【发布时间】:2020-08-20 10:10:58
【问题描述】:
我正在尝试使用 IBM MQ 主题订阅通过 Spring Boot 应用程序监听消息。
可用信息(由 MQ 管理员提供):
Topic name
Host
Port
QueueManager
BrokerDurableSubscriptionQueue
我正在尝试在 MQConnectionFactory 中设置 BrokerDurableSubscriptionQueue 属性。
我可以找到mqConnectionFactory.setBrokerSubQueue(queueName),我猜它可以用于非持久订阅。
但我找不到类似的 Durable 订阅属性。
但是我可以看到 MQTopic 类具有 setBrokerDurSubQueue 属性,但我不确定如何在我的情况下使用 MQTopic 对象。
我正在使用以下代码:
MQConnectionFactory:
@Bean
public MQTopicConnectionFactory topicConnectionFactory(){
MQTopicConnectionFactory mqTopicConnectionFactory= new MQConnectionFactory();
mqTopicConnectionFactory.setHostName(); //mq host name
mqTopicConnectionFactory.setPort(); // mq port
mqTopicConnectionFactory.setQueueManager(); //mq queue manager
mqTopicConnectionFactory.setChannel(); //mq channel name
mqTopicConnectionFactory.setTransportType(1);
mqTopicConnectionFactory.setSSLCipherSuite(); //tls cipher suite name
return mqTopicConnectionFactory;
}
@Bean
public JmsListenerContainerFactory<?> topicListenerFactory(MQTopicConnectionFactory mqtopicConnectionFactory,
DefaultJmsListenerContainerFactoryConfigurer configurer)
{
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
configurer.configure(factory, mqtopicConnectionFactory);
factory.setPubSubDomain(true);
factory.setSubscriptionDurable(true);
return factory;
}
听众:
@JmsListener(
destination = "someTopic",
subscription = "someTopic",
containerFactory = "topicListenerFactory"
)
public void receiveMessage(String msg) {
repository.save(msg);
}
【问题讨论】:
-
@JoshMc 感谢您的回复。这很有意义。
-
我已经清理了我的 cmets 并将所有详细信息添加到我的答案中。
标签: spring-boot ibm-mq spring-jms