Я пытаюсь настроить один @JMSListener, который будет прослушивать несколько администраторов очередей в моем приложении Springboot, которое прослушивает IBM MQ. Ниже приведены 2 bean-компонента, которые я создал, и требование состоит в том, чтобы активно прослушивать обе очереди:
@Value("${ibm.mq.queueManager.A}")
String jmsMQConnectionFactoryA;
@Value("${ibm.mq.queueManager.B}")
String jmsMQConnectionFactoryB;
@Bean
@Primary
public MQQueueConnectionFactory jmsMQConnectionFactoryB() {
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
URL url = JMSConfiguration.getURL(this.urlFileLocation);
try {
mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setClientReconnectOptions(WMQConstants.WMQ_CLIENT_RECONNECT_Q_MGR);
mqQueueConnectionFactory.setCCDTURL(url);
mqQueueConnectionFactory.setQueueManager(jmsMQConnectionFactoryB);
} catch (Exception e) {
e.printStackTrace();
}
return mqQueueConnectionFactory;
}
@Bean
public MQQueueConnectionFactory jmsMQConnectionFactoryB() {
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
URL url = JMSConfiguration.getURL(this.urlFileLocation);
try {
mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setClientReconnectOptions(WMQConstants.WMQ_CLIENT_RECONNECT_Q_MGR);
mqQueueConnectionFactory.setCCDTURL(url);
mqQueueConnectionFactory.setQueueManager(jmsMQConnectionFactoryA);
} catch (Exception e) {
e.printStackTrace();
}
return mqQueueConnectionFactory;
}
EDIT 1:
Добавлено 2 containerFactory с использованием указанных выше соединений и 2 JMSTemplate (по мере необходимости в сообщение publi sh) Ниже приведен обновленный рабочий код
@Bean
JmsListenerContainerFactory<?> jmsContainerFactoryA() {
DefaultJmsListenerContainerFactory factory = new
DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(jmsMQConnectionFactoryA());
factory.setRecoveryInterval((long) 60000);
factory.setSessionAcknowledgeMode(2);
factory.setSessionTransacted(true);
// factory.setMaxMessagesPerTask(concurrencyLimit);
return factory;
}
@Bean
JmsListenerContainerFactory<?> jmsContainerFactoryB() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(jmsMQConnectionFactoryB());
factory.setRecoveryInterval((long) 60000);
factory.setSessionAcknowledgeMode(2);
factory.setSessionTransacted(true);
// factory.setMaxMessagesPerTask(concurrencyLimit);
return factory;
}
@Bean
public MQQueue jmsResponseQueue() {
MQQueue queue = null;
try {
queue = new MQQueue("QueueOut");
queue.setBaseQueueName(wmq_out_base_queue);
} catch (JMSException e) {
e.printStackTrace();
}
return queue;
}
@Bean
public JmsTemplate jmsTemplateB() {
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(jmsMQConnectionFactoryB());
template.setDefaultDestination(jmsResponseQueue());
template.setMessageConverter(oxmMessageConverter());
return template;
}
@Bean
public JmsTemplate jmsTemplateA() {
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(jmsMQConnectionFactoryA());
template.setDefaultDestination(jmsResponseQueue());
template.setMessageConverter(oxmMessageConverter());
return template;
}
Class2. java
@Value("${wmq_out_base_queue}")
String wmq_out_base_queue;
@Autowired
JmsTemplate jmsTemplateA;
@Autowired
JmsTemplate jmsTemplateB;
@JmsListener(containerFactory="jmsContainerFactoryA",destination = "${wmq_in_base_queue}")
public void reciveMessageA(Message message) {
LOGGER.info("Received message is: " + message);
this.jmsTemplateA.convertAndSend(wmq_out_base_queue, "Some Message");
}
@JmsListener(containerFactory="jmsContainerFactoryB",destination = "${wmq_in_base_queue}")
public void reciveMessageB(Message message) {
LOGGER.info("Received message is: " + message);
this.jmsTemplateA.convertAndSend(wmq_out_base_queue, "Some Message2");
}