Service Broker 一次仅接收一条消息

发布于 2024-10-07 15:31:31 字数 706 浏览 1 评论 0原文

即使我指定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

非要怀念 2024-10-14 15:31:31

我的猜测是每条消息属于不同的对话(因此默认情况下属于不同的对话组)。如果是这种情况,那么这是预期的行为。

来自联机丛书 - 接收 (Transact-SQL)

由 a 返回的所有消息
RECEIVE语句属于相同的
对话组

如果您想要一次接收多条消息,请在单个对话中发送多条消息或将多个对话分组< /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):

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.

冷月断魂刀 2024-10-14 15:31:31

您知道在运行过程之前该队列中有多少消息吗?

如果您运行以下查询来获取所有队列中的计数

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文