Service Broker外部激活器...在2个队列上激活?

时间:2011-02-19 18:25:18

标签: sql-server-2008 service-broker

我有两个队列,还有更多...我希望使用外部激活器在外部激活这些队列。

当我编辑EAService.config以激活队列#1时,它可以正常工作 当我编辑EAService.config以激活队列#2时,它工作得很好。

如果我把两者都放在配置中,那么首先列出的那个就会被激活。

这两个队列实际上都是由同一个exe进行处理的...这个例子不起作用就是这个......

<NotificationServiceList>
    <NotificationService name="my_notif_svc1" id="100" enabled="true">
      <Description>my notification service 1</Description>
      <ConnectionString>
        <Unencrypted>server=my_pc01;database=my_db;Application Name=External Activator;Integrated Security=true;</Unencrypted>
      </ConnectionString>
    </NotificationService>
    <NotificationService name="my_notif_svc2" id="100" enabled="true">
      <Description>my notification service 2</Description>
      <ConnectionString>
        <Unencrypted>server=my_pc01;database=my_db;Application Name=External Activator;Integrated Security=true;</Unencrypted>
      </ConnectionString>
    </NotificationService>
  </NotificationServiceList>
  <ApplicationServiceList>
    <ApplicationService name="myMessageApp1" enabled="true">
      <OnNotification>
        <ServerName>my_pc01</ServerName>
        <DatabaseName>my_db</DatabaseName>
        <SchemaName>dbo</SchemaName>
        <QueueName>my_user_queue1</QueueName>
      </OnNotification>
      <LaunchInfo>
        <ImagePath>c:\test\myMessageReceiver.exe</ImagePath>
        <CmdLineArgs>whatever cmd-line arguments you need to pass to your receiver application</CmdLineArgs>
        <WorkDir>c:\test</WorkDir>
      </LaunchInfo>
      <Concurrency min="1" max="4" />
    </ApplicationService>
    <ApplicationService name="myMessageApp2" enabled="true">
      <OnNotification>
        <ServerName>my_pc01</ServerName>
        <DatabaseName>my_db</DatabaseName>
        <SchemaName>dbo</SchemaName>
        <QueueName>my_user_queue2</QueueName>
      </OnNotification>
      <LaunchInfo>
        <ImagePath>c:\test\myMessageReceiver.exe</ImagePath>
        <CmdLineArgs>whatever cmd-line arguments you need to pass to your receiver application</CmdLineArgs>
        <WorkDir>c:\test</WorkDir>
      </LaunchInfo>
      <Concurrency min="1" max="4" />
    </ApplicationService>
  </ApplicationServiceList>

另外我不明白id =“100”正在做什么...我尝试过相同的#和不同的#...即100&amp; 101但它并没有什么区别。激活器服务仅适用于“ApplicationServiceList”

中列出的第一个

帮助!

2 个答案:

答案 0 :(得分:1)

我想出了我的问题......

来自文档

  

系统可以使用外部激活   对于多个Service Broker   应用程序队列。有一个   多对一的关系   应用程序队列和激活   通知服务。有一个   一对一的关系   激活通知服务和   外部激活服务。

我是上面列出的两个通知服务(my_notif_svc1&amp; my_notif_svc2)。我切换了我的事件通知(创建事件通知......)以使用相同的“TO SERVICE”,现在它可以工作。

因此,您必须为外部激活器使用一个“服务”,但您可以为指向该服务的多个队列创建多个事件通知。

我仍然认为我设置它的方式应该可行,但这绝对有效......

答案 1 :(得分:0)

我也遇到了同样的问题,如果他们为什么以及他们是否会尊重SSBEA中列出的多个通知服务而不仅仅是列表中的第一个通知服务,那么很高兴得到微软的正式回复。最后,我们使用相同的解决方案,这是一个有用的代码片段,用于动态获取Guid并将队列激活事件设置为SINGLE服务(ServiceBrokerNotification.NotificationService)。

DECLARE @sbn nvarchar(100) = 'servicebrokernotification'
DECLARE @sbnid nvarchar(60)

SELECT @sbnid = ''''+CAST(service_broker_guid AS nvarchar(60))+'''' FROM sys.databases WHERE name = @sbn SELECT @sbnid

DECLARE @Str nvarchar(max) DECLARE @createEventSql nvarchar(max)

Set @Str = 'CREATE EVENT NOTIFICATION NotificationEvent ON QUEUE [TargetQueue] FOR QUEUE_ACTIVATION TO SERVICE ''NotificationService'' ,' + @sbnid;

Select @Str EXECUTE (@Str)

相关问题