Spring Integration出站通道适配器目标表达式MQMDMessageContext

时间:2014-07-28 11:10:00

标签: java spring spring-integration

我正在使用Spring-Integration jms outbound-channel-adapter将消息发送到动态队列。我使用了属性destination-expression="headers.DestinationQueueName"。 DestinationQueueName在写入OUT_MSG频道的出站邮件之前在代码中设置。

  
      
  1. < int-jms:outbound-channel-adapter id =" msgWrtr"
  2.   
  3. 连接工厂=" MQConnectionFactory"信道=" OUT_MSG"
  4.   
  5. 目的地表达=" headers.DestinationQueueName">
  6.   
  7. < / INT-JMS:出站通道适配器及GT;
  8.   

如何在队列中设置这些属性:MQMDMessageContextMQMDReadEnabledMQMDWriteEnabled

2 个答案:

答案 0 :(得分:0)

如何而不只是DestinationQueueName字符串将com.ibm.mq.jms.MQQueue对象添加到标题中,当然还有这些选项?

答案 1 :(得分:0)

您的动态目标名称标头表达式很好。只需为您的JmsTemplate实例配置自定义目标解析器即可。

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