将JMS输出绑定通道适配器转换为java 1.7中的等效Spring Integration DSL

时间:2015-09-01 12:01:38

标签: jms spring-integration dsl spring-jms

如何在java 1.7中将<int-jms:outbound-channel-adapter channel="topicChannel" destination="requestQueue"/>转换为等效的Spring Integration DSL

以下是ActiveMQ配置:

<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://localhost:61616"/>
        </bean>
    </property>
    <property name="sessionCacheSize" value="10"/>
</bean>

<bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="queue.demo"/>
</bean>

2 个答案:

答案 0 :(得分:0)

@Bean
public ActiveMQQueue requestQueue() {
    return new ActiveMQQueue("queue.demo");
}

答案 1 :(得分:0)

您可以像这样配置发件人:

    @Configuration
@ComponentScan(basePackages = { "com.sample.dispatcher" })
public class DispatcherConfig {

    public static final String JOB_TOPIC = "jobTopic";

    @Bean
    @ServiceActivator(inputChannel = JOB_TOPIC)
    public MessageHandler outboundJmsAdapter(JmsTemplate template) {
        JmsSendingMessageHandler handler = new JmsSendingMessageHandler(template);
        handler.setDestinationName(JOB_TOPIC);
        return handler;
    }

    @Bean(name = JOB_TOPIC)
    public MessageChannel jobTopic() {
        return new PublishSubscribeChannel();
    }
}

和听众一样

@Configuration
@ComponentScan(basePackages = { "com.sample.processor" })
@IntegrationComponentScan(basePackages = { "com.sample.processor" })
public class ProcessorConfig {

    public static final String ON_POST_JOB = "onPostJob";

    public static final String JOB_TOPIC = "jobTopic";

    @Bean
    public Queue jobTopic() {

        return new ActiveMQQueue(JOB_TOPIC);
    }

    @Bean
    public JmsMessageDrivenEndpoint inboundJmsAdapter(ConnectionFactory connectionFactory) {

        return new JmsMessageEndpointBuilder()
                .setConnectionFactory(connectionFactory)
                .setDestination(JOB_TOPIC)
                .setInputChannel(onPostJob())
                .build();
    }

    @Bean(name = ON_POST_JOB)
    public MessageChannel onPostJob() {

        return new PublishSubscribeChannel();
    }

}

我有一个示例项目,它使用jms和Spring Integration作为在单独的vm / process /上运行的两个应用程序之间的通信形式:

https://github.com/vineey/sample-jobqueue