我正在使用Spring-Integration jms outbound-channel-adapter
将消息发送到动态队列。我使用了属性destination-expression="headers.DestinationQueueName"
。 DestinationQueueName在写入OUT_MSG
频道的出站邮件之前在代码中设置。
- < int-jms:outbound-channel-adapter id =" msgWrtr"
- 连接工厂=" MQConnectionFactory"信道=" OUT_MSG"
- 目的地表达=" headers.DestinationQueueName">
- < / INT-JMS:出站通道适配器及GT;
醇>
如何在队列中设置这些属性:MQMDMessageContext
,MQMDReadEnabled
和MQMDWriteEnabled
?
答案 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();
}
}