Java Spring集成出站通道适配器目标表达式MQMDMessageContext
我正在使用Java Spring集成出站通道适配器目标表达式MQMDMessageContext,java,spring,spring-integration,Java,Spring,Spring Integration,我正在使用Spring集成jms出站通道适配器,它将消息发送到动态队列。我使用属性destination expression=“headers.DestinationQueueName”。在将出站消息写入OUT\u MSG频道之前,在代码中设置DestinationQueueName 如何在队列上设置这些属性:MQMDMessageContext、MQMDReadEnabled和MQMDWriteEnabled?不如将com.ibm.mq.jms.MQQueue对象和这些选项放在头上,而不
Spring集成jms出站通道适配器,它将消息发送到动态队列。我使用属性destination expression=“headers.DestinationQueueName”
。在将出站消息写入OUT\u MSG
频道之前,在代码中设置DestinationQueueName
如何在队列上设置这些属性:MQMDMessageContext
、MQMDReadEnabled
和MQMDWriteEnabled
?不如将com.ibm.mq.jms.MQQueue
对象和这些选项放在头上,而不仅仅是DestinationQueueName
字符串,当然可以?您的动态目标名称标题表达式很好。只需为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();
}
}
@Bean
公共MQDestinationResolver MQDestinationResolver(){
返回新的MQDestinationResolver();
}
公共类MQDestinationResolver扩展了DynamicDestinationResolver实现了CachingDestinationResolver{
private final Map destinationCache=新的ConcurrentHashMap(16);
私有布尔缓存=true;
公共void setCache(布尔缓存){
this.cache=cache;
}
@凌驾
公共目标resolveDestinationName(@Nullable会话,字符串destinationName,布尔pubSubDomain)
性感觉异常{
Destination Destination=this.destinationCache.get(destinationName);
如果(目标==null){
destination=super.resolveDestinationName(会话、destinationName、pubSubDomain);
MQDestination MQDestination=(MQDestination)目的地;
//设置IBM MQ特定的目标属性
mqDestination.setMQMDReadEnabled(true);
mqDestination.setMQMDWriteEnabled(true);
mqDestination.setMessageBodyStyle(WMQConstants.WMQ_MESSAGE_BODY_未指定);
mqDestination.setTargetClient(WMQConstants.WMQ_CLIENT_JMS_兼容);
if(this.cache){
this.destinationCache.put(destinationName,destination);
}
}
返回目的地;
}
@凌驾
public void removeFromCache(字符串destinationName){
this.destinationCache.remove(destinationName);
}
@凌驾
公共void clearCache(){
this.destinationCache.clear();
}
}
对于Artem Bilan,我认为您需要队列名称-不能有动态名称。据我所知,这就是你的建议,对吗?