0

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) {...}
M06H
  • 1,675
  • 3
  • 36
  • 76

1 Answers1

0

You don't show your listener but why do you have two queues?

It looks like you are sending to one queue and receiving from another. You need to receive from the same destination you are sending to.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • they are two seperate queues, one for receive and one for sending but they are on the same channel/queuemanager. So I think it is a misconfiguration and I need to create a different connectionfactory for the receiver and sender? is my understanding correct? – M06H Nov 07 '19 at 14:05
  • That makes no sense; if you send to destination `foo` and receive from destination `bar` you will get nothing and messages will accumulate in queue `foo`. – Gary Russell Nov 07 '19 at 14:12
  • I receive from `foo` (local mq) and send to `bar` (remote queue). they're both on queue manager X. I receive message from `foo` fine as with current setup above. updated question with listener. – M06H Nov 07 '19 at 14:32