如何连接消息驱动的适配器列表而不实际写出每个适配器?

时间:2015-11-03 19:23:23

标签: java spring jms spring-integration

嘿,所以我需要像十几个队列一样收听,或多或少地通过相同的处理流程将所有传入的消息放入。我有消息驱动的通道适配器连接到每个队列:

<jms:message-driven-channel-adapter id="101InstructionQueue1In" 
                                  channel="xmedInitiation1PrimaryChannel"                                    
                                  auto-startup="true"
                                  connection-factory="${XMED.1.PRIMARY}Factory"
                                  destination-name="${XMED.1.INITIATION}"/>

<jms:message-driven-channel-adapter id="101InstructionQueue2In" 
                                  channel="xmedInitiation2PrimaryChannel"                                    
                                  auto-startup="true"
                                  connection-factory="${XMED.2.PRIMARY}Factory"
                                  destination-name="${XMED.2.INITIATION}"/>


<jms:message-driven-channel-adapter id="201InstructionQueue1In" 
                                  channel="xmedInitiation1SecondaryChannel" 
                                  connection-factory="${XMED.1.SECONDARY}Factory"
                                  destination-name="${XMED.1.INITIATION}" 
                                  auto-startup="true"/>                                   

<jms:message-driven-channel-adapter id="201InstructionQueue2In" 
                                  channel="xmedInitiation2SecondaryChannel" 
                                  connection-factory="${XMED.2.SECONDARY}Factory"
                                  destination-name="${XMED.2.INITIATION}" 
                                  auto-startup="true"/>

......等等。

收到消息后,我将它们全部路由到同一个频道。但是我仍然需要知道消息来自哪里,所以在我实际路由它们之前,我有点使用标头扩充器来为消息添加队列名称。

<channel id="xmedInitiation1PrimaryChannel"  />

<header-enricher input-channel="xmedInitiation1PrimaryChannel" output-channel="initiationPreprocessingChannel" >
    <header name="INITIATOR" value="PRIMARY" />
    <header name="INITIATOR_NAME" value="${XMED.1.INITIATION}" />
</header-enricher>

<channel id="xmedInitiation1SecondaryChannel"  />

<header-enricher input-channel="xmedInitiation1SecondaryChannel" output-channel="initiationPreprocessingChannel" >
    <header name="INITIATOR" value="SECONDARY" />
    <header name="INITIATOR_NAME" value="${XMED.1.INITIATION}" />
</header-enricher>

有没有办法让我喜欢迭代队列名称列表并动态创建这些适配器?也许使用java配置?提前致谢。

0 个答案:

没有答案