Service Broker 一次仅接收一条消息
即使我指定 Receive Top(25) 等,我一次也只会收到一条消息要出列。不确定我在存储过程中做错了什么?可能是一些微不足道的事情,但我没有看到问题。
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
知道我做错了什么吗?
谢谢,
B
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的猜测是每条消息属于不同的对话(因此默认情况下属于不同的对话组)。如果是这种情况,那么这是预期的行为。
来自联机丛书 - 接收 (Transact-SQL):
如果您想要一次接收多条消息,请在单个对话中发送多条消息或将多个对话分组< /a> 进入接收端的单个会话组。
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):
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.
您知道在运行过程之前该队列中有多少消息吗?
如果您运行以下查询来获取所有队列中的计数
SELECT sq.name,
p.行数
来自 sys.service_queues sq
将 sys.internal_tables 加入 sq.object_id = it.parent_id
并且 it.parent_minor_id = 0
和 it.internal_type = 201
在 i.object_id = it.object_id 和 i.index_id = 1 上加入 sys.indexes as i
将 sys.partitions 作为 p 加入 p.object_id = i.object_id 和 p.index_id = i.index_id
在哪里
sq.object_id = it.parent_id AND
it.parent_minor_id = 0 且
it.internal_type = 201
如果该队列中有超过 1 条消息,您的接收中应该会收到超过 1 条消息。
Do you know how many messages are in that queue, before the proc is run?
If you run the following query to get the count in all your queues
SELECT sq.name,
p.rows
FROM sys.service_queues sq
Join sys.internal_tables it ON sq.object_id = it.parent_id
AND it.parent_minor_id = 0
AND it.internal_type = 201
Join sys.indexes as i on i.object_id = it.object_id and i.index_id = 1
Join sys.partitions as p on p.object_id = i.object_id and p.index_id = i.index_id
WHERE
sq.object_id = it.parent_id AND
it.parent_minor_id = 0 AND
it.internal_type = 201
If there is more than 1 message in that queue, you should get more than 1 in your receive.