Quantcast
Channel: SQL Service Broker forum
Viewing all articles
Browse latest Browse all 461

Message with the timer

$
0
0

I'm calling stored procedure asynch with timer:

DECLARE @DialogHandle UNIQUEIDENTIFIER, @RequestMessage NVARCHAR(255);
BEGIN dialog CONVERSATION @DialogHandle FROM SERVICE [SAStockIncreaseService] TO SERVICE N'SAStockIncreaseService', 'current database' WITH ENCRYPTION = OFF;
BEGIN CONVERSATION TIMER(@DialogHandle) TIMEOUT = 10;

It works. The procedure defined within 'SAStockIncreaseService' is called after 10 seconds.
There is message in SAStockIncrease queue:

RECEIVE TOP (1) @Handle = conversation_handle, @message=message_body FROM dbo.SAStockIncrease;

This message is empty. Now I would like to add something to this message.
As i understand from documentation, this message is always empty when using timer. It is not possible to put something inside?

If i would like to send some message inside call of my procedure, i must add this 2 lines:

SET @RequestMessage = N'<Request><SA>58</SA></Request>';
SEND ON CONVERSATION  @DialogHandle(@RequestMessage);

This way I would have 2 messages inside dbo.SAStockIncrease queue, but they will have the same group and conversation handle, so I can new that they belongs together.

It looks stupid to me, why not put message into timer call and have only one record(message) in my conversation, but that is how it is, if I understand correctly.

So, when I execute this:

RECEIVE TOP (1) @Handle = conversation_handle, @message=message_body FROM dbo.SAStockIncrease;

I will always get the timer message first. Than I should check if there is another message with select statement:

SELECT @message=CAST(message_body) WHERE conversation_handle=@handle

But what if some other user executes RECEIEVE TOP(1).. at the same time and clear my message from the queue?

What is the right procedure to read all messages with the same handle at the same time?

I guess it is obvious what I would like to do - so, what is the right way?

Thanks,
Simon


Viewing all articles
Browse latest Browse all 461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>