我有下面的mq配置类,通过它我可以在接收队列中接收消息,但当使用JmsTemplate bean时,我的消息不会发送到队列。我没有得到任何JmsException
或任何异常,send()
似乎成功了。它是一段XML字符串,我将其作为有效载荷发送如下:
jmsTemplate.send(session -> session.createTextMessage(payload));
@EnableJms
@Configuration
public class MessageQueueConfiguration {
@Bean(name = "test-factory")
public ConnectionFactory getMqConnectionFactory(String host, int port, String queueManager, String channel) throws JMSException {
final MQConnectionFactory connectionFactory = new MQConnectionFactory();
connectionFactory.setQueueManager(queueManager);
connectionFactory.setHostName(host);
connectionFactory.setPort(port);
connectionFactory.setChannel(channel);
connectionFactory.setTransportType(WMQ_CM_CLIENT);
return connectionFactory;
}
@Bean("test-container")
public JmsListenerContainerFactory containerFactory(final ConnectionFactory connectionFactory, final ErrorHandler errorHandler) {
final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setErrorHandler(errorHandler);
return factory;
}
@Bean(name = "receive")
public Destination receive(@Value("${receive-queue}") final String destination) throws JMSException {
return new MQQueue(destination);
}
@Bean(name = "send")
public Destination send(@Value("${send-queue}") final String destination) throws JMSException {
return new MQQueue(destination);
}
@Bean(name = "sender")
public JmsTemplate testTemplate(@Qualifier("test-factory") final ConnectionFactory connectionFactory, @Qualifier("send") final Destination destination) {
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.setDefaultDestination(destination);
return jmsTemplate;
}
}
我的问题是我有没有误解什么?我需要多个连接工厂还是容器工厂,因为我有接收和发送队列?
我的听众:
@JmsListener(destination = "${receive}", concurrency = "1-1", containerFactory = "test-container")
public Model<Message> getMessage(@Payload final String message) {...}
您没有显示侦听器,但为什么有两个队列?
看起来你是在向一个队列发送,而从另一个队列接收。您需要从发送到的同一目的地接收。