1
votes

I am using Spring-Integration jms outbound-channel-adapter that sends message to dynamic queue. I use property destination-expression="headers.DestinationQueueName". DestinationQueueName is set in code before outbound message written to OUT_MSG channel.

  1. <int-jms:outbound-channel-adapter id="msgWrtr"
  2. connection-factory="MQConnectionFactory" channel="OUT_MSG"
  3. destination-expression="headers.DestinationQueueName">
  4. </int-jms:outbound-channel-adapter>

How can I set these properties on queue: MQMDMessageContext, MQMDReadEnabled and MQMDWriteEnabled?

2
To Artem Bilan, I think you need queue name - can't have dynamic name. For my understanding - this is what you are suggesting, right? <bean id="outQueue" class="com.ibm.mq.jms.MQQueue"><constructor-arg name="queueName" value="headers.DestinationQueueName" />Raju

2 Answers

0
votes

How about instead of just DestinationQueueName String place to the headers the com.ibm.mq.jms.MQQueue Object and with those options, of course?

0
votes

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