I have a JMS outbound gateway which i use to send messages to multiple queues in a queue manager. The destination is determined on the fly using the destinationExpression method:
@Bean
public IntegrationFlow sendTo101() {
return flow -> flow
.handle(Jms
.outboundAdapter(context.getBean("connection101", ConnectionFactory.class))
.destinationExpression("headers.destinationName")
.configureJmsTemplate(spec -> spec
.explicitQosEnabled(true)
.get().setDeliveryDelay(180000)
)
.get(),
endpointSpec -> endpointSpec.advice(context.getBean(RequestHandlerRetryAdvice.class))
);
}
Now there's a need to set a delivery delay to a certain subset of messages that come in. Is there any way to use the contents of the message to determine if i should add a delay or not?
I could have a filter further up which checks for this property and redirects the flow to another outbound gateway, but that would be quite a bit of redundant code so i wanted to make sure that there wasn't a better way.
Also, different messages require different delays. Is it possible to set a different delay per message? I do realize that the delay property is on the Message Producer and not something you set on the message according to the JMS spec, but i'm fine with making a new JMS producer per message even though it hinders performance.
Thanks for the help!
Well, what I can suggest in this case is like to have top level JmsTemplate bean and set its deliveryDelay in advance of the Jms.outboundAdapter(). But in this case all your messages must be processed in this flow in the same Thread to avoid concurrent modification.
We have DynamicJmsTemplate which is based on the DynamicJmsTemplateProperties. And the last one uses ThreadLocal to change priority and receiveTimeout per request.
I'm pretty sure that your request for the deliveryDelay can be considered as a part of that feature.
Only the problem here that target JmsTemplate doesn't use getter but gets access to the property directly. So, first of all we have to ask Spring Framework team (https://jira.spring.io/browse/SPR) to refactor JmsTemplate internal for better inheritance.