Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Broker only receiving one message at a time

Even when I specify Receive Top(25), etc I am only getting one message to be dequeued at a time. Not sure what i am doing wrong inside my sproc? Probably something trivial, but I don't see the problem.

Sproc:

CREATE PROCEDURE dbo.SPP_DEQUEUE_MESSAGE

AS

BEGIN

DECLARE @receiveTable TABLE(
message_type        sysname,
message_body        xml,
message_dialog      uniqueidentifier);

    BEGIN TRANSACTION;

    WAITFOR
        ( RECEIVE TOP(25)
            message_type_name,
            message_body,
            conversation_handle  
          FROM TargetQueue1DB
            INTO @receiveTable
        ), TIMEOUT 3000;

    SELECT 
        *
    From @receiveTable;     

    Delete from @receiveTable;

COMMIT TRANSACTION;

END --End Sproc

Any idea what I am doing wrong?

Thanks,

B

like image 561
scarpacci Avatar asked Dec 15 '10 20:12

scarpacci


People also ask

How does a service broker work?

Service Broker provides queuing and reliable messaging for SQL Server. Service Broker is used both for applications that use a single SQL Server instance and applications that distribute work across multiple instances. Within a single SQL Server instance, Service Broker provides a robust asynchronous programming model.

Is an example for service broker?

GitHub Repository service - this is designed to be an easy-to-read example of a service broker, with complete documentation, and comes with a demo app that uses the service. The broker can be deployed as an application to any Cloud Foundry instance or hosted elsewhere.


1 Answers

My guess would be that each message belongs to a different conversation (and therefore by default to a different conversation group). If this is the case, then this is expected behavior.

From Books Online - Receive (Transact-SQL):

All messages that are returned by a RECEIVE statement belong the same conversation group

If you want to receive multiple messages at once, send multiple messages on a single conversation or group multiple conversations into a single conversation group on the receiving end.

like image 138
Pawel Marciniak Avatar answered Sep 25 '22 05:09

Pawel Marciniak