我正在学习 SQL Server Service Broker 作为协调异步任务的工具。假设我有一个MasterService
结合来自EmployeeInfoService
和的数据PayrollInfoService
。我得到一个列表,EmployeeIDs
然后将每个作为对话发送到两个服务。在这两个服务的末尾是激活存储过程,它将EmployeeIDs
一次处理两个。
几个问题
- 如何将每个员工的响应存储到我的临时表中
MasterService
? - 我怎么知道这两个服务已经完成了所有处理
EmployeeIDs
,所以我可以从我在步骤 #1 中构建的两个临时表中生成数据?
到目前为止,这是我的代码:
-- Get a whole bunch of EmployeeIDs
DECLARE @EmployeeConversation uniqueidentifier
DECLARE @PayrollConversation uniqueidentifier
BEGIN DIALOG @EmployeeConversation
FROM SERVICE MasterService
TO SERVICE 'EmployeeInfoService';
SEND ON CONVERSATION @EmployeeConversation MESSAGE (EmployeeID1)
SEND ON CONVERSATION @EmployeeConversation MESSAGE (EmployeeID2)
SEND ON CONVERSATION @EmployeeConversation MESSAGE (Employee...);
BEGIN DIALOG @PayrollConversation
FROM SERVICE MasterService
TO SERVICE 'PayrollInfoService'
WITH RELATED_CONVERSATION_GROUP = @EmployeeConversation;
SEND ON CONVERSATION @PayrollConversation MESSAGE (EmployeeID1)
SEND ON CONVERSATION @PayrollConversation MESSAGE (EmployeeID2)
SEND ON CONVERSATION @PayrollConversation MESSAGE (Employee...);
-- Now I need to wait till both conversations are done.
-- How do I handle that?