gpt4 book ai didi

sql - 将数据插入 sql server service broker 中的队列

转载 作者:行者123 更新时间:2023-12-02 05:31:49 24 4
gpt4 key购买 nike

我正在尝试将数据插入队列。存储过程 fire_event 将用于此目的。每当调用此存储过程时,它应该将该数据插入队列中。下面是将从存储过程传递的查询和变量。有人能告诉我如何使用这个存储过程在 SQL Server 的队列中插入数据吗?我想通过将其直接插入队列来替换插入表 event_type 的操作。谢谢

BEGIN

INSERT event_type
VALUES (@p_message_id,@p_event_type,@p_classifier,
@p_event_time,@p_correlation_id,@p_person_id,@p_channel_id,
@p_source_address_id,@p_agent_user,
@p_agent_channel_id,@p_device_os,@p_device_os_version,
@p_device_manufacturer,@p_device_model,@p_product_id,
@p_event_source,@p_event_version,
@p_node_id,@p_user_agent_string,@p_event_data)

END

最佳答案

如果您真的是指 Service Broker,那么您应该使用 SEND命令。

例如,Service Broker 对象:

Create Queue MyTableQueue;
Create Service MyTableService On Queue MyTableQueue([DEFAULT])
Create Queue ProcessQueue;
Create Service ProcessService On Queue ProcessQueue([DEFAULT])

发送消息:

Declare @h UniqueIdentifier;
Declare @doc xml;

Set @doc =
(
Select 'Hello' Msg
For XML Raw, Elements, Type, Root('Data')
);
Begin Dialog Conversation @h
From Service MyTableService
To Service 'ProcessService'
With Encryption = OFF;

Send On Conversation @h(@doc)

或者在您的情况下(+ 列别名):

Declare @h UniqueIdentifier;
Declare @doc xml;

Set @doc =
(
Select @p_message_id,@p_event_type,@p_classifier,@p_event_time,@p_correlation_id,@p_person_id,@p_channel_id,@p_source_address_id,@p_agent_user,
@p_agent_channel_id,@p_device_os,@p_device_os_version,@p_device_manufacturer,@p_device_model,@p_product_id,@p_event_source,@p_event_version,
@p_node_id,@p_user_agent_string,@p_event_data
For XML Raw, Elements, Type, Root('Data')
);

Begin Dialog Conversation @h
From Service MyTableService
To Service 'ProcessService'
With Encryption = OFF;

Send On Conversation @h(@doc)

关于sql - 将数据插入 sql server service broker 中的队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12267915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com