Your dynamic destination name header expression is fine. Just configure a custom destination resolver to your JmsTemplate instance.
@Bean
public MQDestinationResolver mqDestinationResolver() {
return new MQDestinationResolver();
}
public class MQDestinationResolver extends DynamicDestinationResolver implements CachingDestinationResolver {
private final Map<String, Destination> destinationCache = new ConcurrentHashMap<>(16);
private boolean cache = true;
public void setCache(boolean cache) {
this.cache = cache;
}
@Override
public Destination resolveDestinationName(@Nullable Session session, String destinationName, boolean pubSubDomain)
throws JMSException {
Destination destination = this.destinationCache.get(destinationName);
if (destination == null) {
destination = super.resolveDestinationName(session, destinationName, pubSubDomain);
MQDestination mqDestination = (MQDestination) destination;
// Set IBM MQ specific destination properties
mqDestination.setMQMDReadEnabled(true);
mqDestination.setMQMDWriteEnabled(true);
mqDestination.setMessageBodyStyle(WMQConstants.WMQ_MESSAGE_BODY_UNSPECIFIED);
mqDestination.setTargetClient(WMQConstants.WMQ_CLIENT_JMS_COMPLIANT);
if (this.cache) {
this.destinationCache.put(destinationName, destination);
}
}
return destination;
}
@Override
public void removeFromCache(String destinationName) {
this.destinationCache.remove(destinationName);
}
@Override
public void clearCache() {
this.destinationCache.clear();
}
}