I have the below mq config class by which I can receive message in the receive queue, but when using the JmsTemplate bean my messages are not sending to queue.
I do not get any JmsException
or any exceptions and send()
seems successful. It is piece of XML as string which I send as payload as follows:
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;
}
}
My question is have I misconfigured something? Do I need multiple connectionfactories or container factories as I have receive and send queues?
My listener:
@JmsListener(destination = "${receive}", concurrency = "1-1", containerFactory = "test-container")
public Model<Message> getMessage(@Payload final String message) {...}