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. :)
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
.