【问题标题】:Spring Integration outbound-channel-adapter destination-expression MQMDMessageContextSpring 集成出站通道适配器目标表达式 MQMDMessageContext
【发布时间】:2014-09-19 13:34:30
【问题描述】:

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

  1. connection-factory="MQConnectionFactory" channel="OUT_MSG"
  2. destination-expression="headers.DestinationQueueName">

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

【问题讨论】:

  • 对于 Artem Bilan,我认为您需要队列名称 - 不能有动态名称。据我了解-这就是您的建议,对吗?

标签: java spring spring-integration


【解决方案1】:

不只是DestinationQueueName String 将com.ibm.mq.jms.MQQueue 对象和这些选项放在标题中怎么样?

【讨论】:

    【解决方案2】:

    您的动态目的地名称标题表达式很好。只需为您的 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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 2014-12-07
      • 2023-03-21
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多