1
votes

I need to throttle the movement of messages between some JMS (activeMQ) queues to ensure I dont overrun an external service used during message processing.

I have done this in the past with Camel but given that this project is otherwise entirely Spring based, I figured I'd give spring-integration a whirl.

I am happy to see that in 5.0.7 the Java DSL is in core and would really like to use it instead of xml.

But...I cant seem to find good/current docs for using the DSL to do even simple things like create the input and output messageChannels for JMS.

Could anyone point me to any current example of using the java DSL to create channels that I can use to consume and produce messages with...and then later use in a bridge with some throttling applied?

1

1 Answers

0
votes

Well, looks like our JMS chapter in the Reference Manual leaks of the Java DSL samples, similar to what we have so far with AMQP, for example:

https://docs.spring.io/spring-integration/docs/5.0.7.RELEASE/reference/html/amqp.html#_configuring_with_the_java_dsl_2

https://docs.spring.io/spring-integration/docs/5.0.7.RELEASE/reference/html/amqp.html#_configuring_with_the_java_dsl_4

I believe we can add similar paragraphs into the JMS chapter as well. Please, raise a JIRA on the matter and we will address it soon. Meanwhile I suggest you to open a org.springframework.integration.jms.dsl.Jms factory for appropriate builder to use.

On the other hand I can suggest you to take a look into the existing test-case of some possible configurations: https://github.com/spring-projects/spring-integration/blob/master/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java

For example to read from the queue you need a configuration like this:

    @Bean
    public IntegrationFlow jmsMessageDrivenFlow() {
        return IntegrationFlows
                .from(Jms.messageDrivenChannelAdapter(jmsConnectionFactory(), DefaultMessageListenerContainer.class)
                        .outputChannel(jmsMessageDrivenInputChannel())
                        .destination("jmsMessageDriven")
                .configureListenerContainer(c -> c.clientId("foo")))
                .<String, String>transform(String::toLowerCase)
                .channel(jmsOutboundInboundReplyChannel())
                .get();
    }

To send to the JMS you need something like this:

    @Bean
    public IntegrationFlow jmsOutboundFlow() {
        return f -> f
                .handle(Jms.outboundAdapter(jmsConnectionFactory())
                        .destinationExpression("headers." + SimpMessageHeaderAccessor.DESTINATION_HEADER)
                        .configureJmsTemplate(t -> t.id("jmsOutboundFlowTemplate")));
    }