3
votes

We have the below working configuration in XML and are trying to convert to DSL. Not sure whether they are equivalent and also tried to do with inboundAdapter. However , am unable to figure out how to set concurrency related values there. Can someone please advise if they used either messageDrivenChannelAdapter or inboundAdapter with these parameters in DSL?

<jms:message-driven-channel-adapter 
id="inputChannelAdapter" 
channel="inputChannel" 
destination-name="inboundQueueName"
connection-factory="cachingConnectionFactory"
acknowledge="transacted" 
header-mapper="defaultJmsHeaderMapper"
error-channel="errorChannel" 
concurrent-consumers="10"  
max-concurrent-consumers="20"/>



@Bean
public IntegrationFlow jmsInboundFlow() {
    return IntegrationFlows
            .from(Jms.messageDrivenChannelAdapter(cachingConnectionFactory)
                    .configureListenerContainer(c -> {
                        DefaultMessageListenerContainer container = c.get();
                        container.setSessionTransacted(true);
                        container.setSessionAcknowledgeModeName("");
                        container.setMaxConcurrentConsumers(30);
                        container.setConcurrentConsumers(20);
                    })
                    .destination(inboundQueueName).headerMapper(defaultJmsHeaderMapper)
                    .errorChannel("errorChannel"))
            .channel(MessageChannels.queue("inputChannel"))
            .get();
}


@Bean
public IntegrationFlow jmsInboundFlow1() {
    return IntegrationFlows
            .from(Jms.inboundAdapter(cachingConnectionFactory)
                    .configureJmsTemplate(t ->
                            t.deliveryPersistent(true).sessionTransacted(true).sessionAcknowledgeModeName(""))
                    .destination(inboundQueueName).headerMapper(defaultJmsHeaderMapper))
                    .channel(MessageChannels.queue("inputChannel"))
            .get();
}
1

1 Answers

4
votes

What you do with the DefaultMessageListenerContainer container = c.get(); is correct way to provide those options.

There is also a variant like use Jms.container() factory:

Jms.messageDrivenChannelAdapter(
                Jms.container(this.jmsConnectionFactory, "containerSpecDestination")
                        .concurrentConsumers(20)
                        .maxConcurrentConsumers(30)
                        .get())

We will see in Spring Integration 5.0 how we can improve configureListenerContainer() to infer generic type for the target container class to let fluent API to deal with the JmsDefaultListenerContainerSpec directly.

See the JIRA ticket on the matter.