2

How can I convert <int-jms:outbound-channel-adapter channel="topicChannel" destination="requestQueue"/> to equivalent Spring Integration DSL in java 1.7

Below is the ActiveMQ configuration:

<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>
Meiko Rachimow
  • 4,664
  • 2
  • 25
  • 43
Digital
  • 549
  • 1
  • 7
  • 26

2 Answers2

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

etc.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Gary thanks for the reply....Can you please tell me what is the DSL configuration for **** – Digital Sep 01 '15 at 13:24
  • See the [DSL documentation](https://github.com/spring-projects/spring-integration-java-dsl/wiki/Spring-Integration-Java-DSL-Reference#adapters) and [test cases](https://github.com/spring-projects/spring-integration-java-dsl/blob/master/src/test/java/org/springframework/integration/dsl/test/jms/JmsTests.java#L195) for configuration examples. – Gary Russell Sep 01 '15 at 13:31
  • Basically my main aim is to convert the below snipplet to spring DSL >destination="requestQueue"/> > >ref="messageListener" method="processMessage" /> – Digital Sep 01 '15 at 13:41
  • I have asked you before not to post XML in comments; it's unreadable. Try reading the documentation and test cases as I've suggested; if you still can't figure it out, ask a specific question; do not ask us to do all your work for you. – Gary Russell Sep 01 '15 at 13:50
0

You can configure the sender like this:

    @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();
    }
}

and the listener like this

@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();
    }

}

I have a sample project that uses jms and Spring Integration as form of communication between two applications running on separate vm/process/:

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

vine
  • 846
  • 6
  • 10