动态创建MSMQ侦听器的最佳方法是什么?

时间:2022-05-14 20:10:20

I was using Spring.NET to create a message listener at application startup. I now need the ability to create 0-n listeners, some of which could be listening to different queues. I will need to be able to create/destroy them at run-time. What would be the best way to go about doing this? My previous spring configuration was something like:

我在应用程序启动时使用Spring.NET创建了一个消息监听器。我现在需要能够创建0-n个侦听器,其中一些可能正在侦听不同的队列。我需要能够在运行时创建/销毁它们。这样做最好的方法是什么?我以前的弹簧配置是这样的:

<objects xmlns="http://www.springframework.net">

  <object id='inputQueue' type='Spring.Messaging.Support.MessageQueueFactoryObject, Spring.Messaging'>
    <property name='Path' value='.\Private$\inputQueue'/>
  </object>

  <!-- MSMQ Transaction Manager -->
  <object id="messageQueueTransactionManager" type="Spring.Messaging.Core.MessageQueueTransactionManager, Spring.Messaging"/>

  <!-- Message Listener Container that uses MSMQ transactional for receives -->
  <object id="transactionalMessageListenerContainer" type="Spring.Messaging.Listener.TransactionalMessageListenerContainer, Spring.Messaging">
    <property name="MessageQueueObjectName" value="inputQueue"/>
    <property name="PlatformTransactionManager" ref="messageQueueTransactionManager"/>
    <property name="MaxConcurrentListeners" value="10"/>
    <property name="MessageListener" ref="messageListenerAdapter"/>
  </object>

  <!-- Adapter to call a PONO as a messaging callback -->
  <object id="messageListenerAdapter" type="Spring.Messaging.Listener.MessageListenerAdapter, Spring.Messaging">
    <property name="HandlerObject" ref="messageListener"/>
  </object>

  <!-- The PONO class that you write -->
  <object id="messageListener" type="Com.MyCompany.Listener, Com.MyCompany">
    <property name="Container" ref="transactionalMessageListenerContainer"/>
  </object>   

</objects>

Should I just programmatically do what this file is doing each time I need a new listener? Should I not use Spring.NET's messaging framework for this?

我是否应该以编程方式执行每次需要新侦听器时此文件正在执行的操作?我不应该使用Spring.NET的消息传递框架吗?

1 个解决方案

#1


1  

If I'm using Spring.NET judiciously (i.e. messaging, ADO.NET helpers, etc.) as you already stated, I would do it programmatically. And then add the new graph to my existing container. This way Spring.NET still manages lifecycle for me.

如果我正如你已经说过的那样明智地使用Spring.NET(即消息传递,ADO.NET助手等),我会以编程方式进行。然后将新图表添加到现有容器中。这样Spring.NET仍然为我管理生命周期。

#1


1  

If I'm using Spring.NET judiciously (i.e. messaging, ADO.NET helpers, etc.) as you already stated, I would do it programmatically. And then add the new graph to my existing container. This way Spring.NET still manages lifecycle for me.

如果我正如你已经说过的那样明智地使用Spring.NET(即消息传递,ADO.NET助手等),我会以编程方式进行。然后将新图表添加到现有容器中。这样Spring.NET仍然为我管理生命周期。