簡體   English   中英

Spring Integration outbound-channel-adapter destination-expression MQMDMessageContext

[英]Spring Integration outbound-channel-adapter destination-expression MQMDMessageContext

我正在使用Spring-Integration jms outbound-channel-adapter將消息發送到動態隊列。 我使用屬性destination-expression="headers.DestinationQueueName" DestinationQueueName 在出站消息寫入OUT_MSG通道之前在代碼中設置。

  1. <int-jms:outbound-channel-adapter id="msgWrtr"
  2. 連接工廠=“MQConnectionFactory”通道=“OUT_MSG”
  3. 目的地表達式="headers.DestinationQueueName">
  4. </int-jms:outbound-channel-adapter>

如何在隊列上設置這些屬性: MQMDMessageContextMQMDReadEnabledMQMDWriteEnabled

當然,除了將DestinationQueueName String 放在com.ibm.mq.jms.MQQueue對象和這些選項的標頭之外如何?

您的動態目標名稱標頭表達式很好。 只需為您的 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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM