简体   繁体   English

在 java/spring 中使用 SQL Server Service Broker 队列消息

[英]Consume SQL Server Service Broker queue message in java/spring

My app is coded in java/spring and will use SQL Server Service Broker for messaging.我的应用程序是用 java/spring 编码的,将使用 SQL Server Service Broker 进行消息传递。 After a message is put on the queue, the java/spring app needs to consume that message.将消息放入队列后,java/spring 应用程序需要使用该消息。 I have searched all over and can't find any examples.我到处搜索,找不到任何例子。 I am looking for a simple example of how to set up my java/spring app to connect and consume a message from the SQL server service broker queue.我正在寻找一个简单的示例,说明如何设置我的 java/spring 应用程序以连接和使用来自 SQL 服务器服务代理队列的消息。 I keep reading that the app needs to "receive" the message...but how is that done?我一直在读应用程序需要“接收”消息……但这是如何完成的? How does my app poll the queue?我的应用程序如何轮询队列?

Is there a spring boot dependency/library that can be utilized/extended to receive a message on the queue?是否有可用于/扩展以接收队列中消息的 spring boot 依赖项/库? In my yml, do I set up the connection in the spring/datasource section?在我的 yml 中,我是否在 spring/datasource 部分设置了连接?

The API for Service Broker is TSQL which you would call through JDBC . Service Broker 的 API 是 TSQL,您可以通过JDBC调用它。 I don't know of any good wrappers for Java, but you would just be calling SEND and RECEIVE .我不知道有什么好的 Java 包装器,但您只会调用SENDRECEIVE

RECEIVE supports a WAITFOR clause that allows you do to a blocking read loop on a queue. RECEIVE支持WAITFOR子句,该子句允许您对队列上的阻塞读取循环进行操作。 So your code would run in a loop, that does a WAITFOR ... RECIEVE with a 10sec timeout or somesuch.因此,您的代码将在循环中运行,执行 WAITFOR ... RECIEVE 并有 10 秒的超时或类似的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM