1

If want to create a qpid destination for a message publisher on spring integration jms. As an example I can create a queue like this:

<bean id="theTestQueue" class="org.apache.qpid.client.AMQQueue">
    <constructor-arg name="address" value="testQueue" />
    <property name="create" value="ALWAYS"/>
    <property name="node">
        <bean class="org.apache.qpid.client.messaging.address.Node">
            <constructor-arg name="name" value="testQueue"/>
            <property name="durable" value="true"/>
        </bean>
    </property>
</bean>

After that, I set this queue to the channel adapter:

<int:channel id="testChannel"/>
<int-jms:outbound-channel-adapter channel="testChannel" destination="theTestQueue" session-transacted="true"/>

If the publisher sends the first message, the queue will be created on the message broker.

But what can I do, if I want to set queues dynamically?

<int:channel id="testChannel"/>   
<int-jms:outbound-channel-adapter destination-expression="headers.destination" channel="testChannel"/>

The publisher looks like:

@Publisher(channel = "testChannel")
public Message<?> sendMessage (Message<?> message, @Header("destination") String name) {
  return message;

}

The second param of the publisher-method is the name of the destination. That works if I create the queue on brokerside before I will send a message. My current solution is the creation by a jmx mbean before the publisher sends the first message. But I want to use jmx connections as few as possible. Is there a chance to create a queue automatically? Or maybe with an factory without jmx...

Thank you for help. :)

Smoothi
  • 283
  • 1
  • 3
  • 15

1 Answers1

1

As you may notice the destination attribute requires a Destination bean reference (id). From other side destination-expression can be evaluated to the Destination object as well.

If you have org.apache.qpid.client.AMQQueue bean definition for all those your "dynamic destinations", you just need to improve you expression to get appropriate bean from the application context

destination-expression="@beanFactoryAccessor.get(headers.destination)"

where beanFactoryAccessor is some simple bean which is injected with BeanFactory to invoke its getBean() by the provided name.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • That is the problem, I have no definitions. My application executes different tasks. The tasks will be initiated over a GUI. The queues should be created depending on the id of the task. For example, if the taskID is `XYZ` the queue should be created and named as `testQueue.XYZ`. So I don't know, what for destinations are needed. – Smoothi Mar 27 '15 at 10:23
  • But maybe, I can create my own QueueFactory and put it to the destination-expression... i will try :) – Smoothi Mar 27 '15 at 10:35