0

Hey so i need to listen in on like a dozen queues and more or less put all the incoming messages through the same processing flow. I have message driven channel adapters hooked up to each of these queues :

<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"/>

... and so forth.

Once the message is received, i'm routing them all into the same channel. But i'll still need to know where the message came from, so before i actually route them, i'm kinda using a header enricher to add the queue name to the message.

<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>

Is there any way for me to like iterate over a list of queue names and create these adapters on the fly? Perhaps using the java config? Thanks in advance.

alokraop
  • 853
  • 1
  • 11
  • 29
  • See [these answers](http://stackoverflow.com/questions/33053052/spring-integration-get-rid-of-code-duplication-for-setting-up-beans/33055153#33055153) for techniques to do this. – Gary Russell Nov 03 '15 at 20:41
  • Hey just to double check, i'll have to make like one child context for each queue and pass the name into each environment and the same inbound adapter to each context right? But the thing is, I'm using a control bus to start and stop these adapters, so can i just dynamically assign an id to each child's inbound adapter in the same way i'm assigning the actual queue name (from the environment that is)? Will try it out thanks. – alokraop Nov 04 '15 at 10:56
  • Yes; that's the technique. Note that a control bus in the parent context won't have visibility to the adapters in the child contexts. You would have to put a control bus in each child and route the control message(s) to the right one. – Gary Russell Nov 04 '15 at 13:43
  • Oh but that would mean I'll have to keep references to all these child contexts around right? I'd only be able to access the control bus through them. All I'm doing now is assigning the root config as a context param. – alokraop Nov 04 '15 at 14:13
  • The control buses can all listen to the same control channel (pub/sub); just add a filter to ignore control messages that are not for this instance. `pubsub(parent)->filter(child)->controlbus(child)`. Or, you can simply keep a reference to the child context and `stop()` / `start()` the whole context instead of using a control bus. – Gary Russell Nov 04 '15 at 14:18
  • Oh ya a filter would be perfect. I'll do that. One or the other adapter in each child has to be running (I have to put two in each child), so I can't stop the whole context. Thanks a lot for the help. – alokraop Nov 04 '15 at 14:26

0 Answers0