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. After a message is put on the queue, the java/spring app needs to consume that message. 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. 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? In my yml, do I set up the connection in the spring/datasource section?

1 answer

  • answered 2021-10-21 21:36 David Browne - Microsoft

    The API for Service Broker is TSQL which you would call through JDBC. I don't know of any good wrappers for Java, but you would just be calling SEND and RECEIVE.

    RECEIVE supports a WAITFOR clause that allows you do to a blocking read loop on a queue. So your code would run in a loop, that does a WAITFOR ... RECIEVE with a 10sec timeout or somesuch.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum