首次访问后在代理上创建jms队列

时间:2015-03-27 09:36:48

标签: spring jms spring-integration messaging qpid

如果想在spring integration jms上为消息发布者创建qpid目标。作为一个例子,我可以像这样创建一个队列:

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

之后,我将此队列设置为通道适配器:

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

如果发布者发送第一条消息,则将在消息代理上创建队列。

但是,如果我想动态设置队列,我该怎么办?

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

发布商看起来像:

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

}

publisher-method的第二个参数是目标的名称。如果我在发送消息之前在brokerside上创建队列,那么这是有效的。我目前的解决方案是在发布者发送第一条消息之前由jmx mbean创建。但我想尽可能少地使用jmx连接。有机会自动创建队列吗?或者可能是没有jmx的工厂......

谢谢你的帮助。 :)

1 个答案:

答案 0 :(得分:1)

您可能会注意到destination属性需要Destination bean引用(id)。从另一侧destination-expression也可以评估为Destination对象。

如果您的所有“动态目标”都有org.apache.qpid.client.AMQQueue bean定义,那么您只需要改进表达式以从应用程序上下文中获取适当的bean

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

其中beanFactoryAccessor是一个简单的bean,注入BeanFactory以通过提供的getBean()调用其name