0

I have created a simple consumer for Amazon MQ but looks like i missed something because whenever a message came it should call my recevieMessage method but its not working.
But I tried this with apache active MQ its working perfectly.

PS: I also tried with implementing MessageListener class overrides the onMessage() method but not working. I tried with different arguments in receiveMessage method like Object, Message, ByteMessage....

public class Receiver {
    @JmsListener(destination = "Queue_Name")
    public void receiveMessage(final  Message consumerMessage) throws JMSException {
    --some logic on data 
    }
}

My Configuration:

 @Configuration
    @EnableJms//enable jms
    public class ReceiverConfig {
    @Bean//created a ActiveMQ Connection Factory 
      public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
        ActiveMQConnectionFactory activeMQConnectionFactory =
            new ActiveMQConnectionFactory();
        activeMQConnectionFactory.setBrokerURL(brokerUrl);
        activeMQConnectionFactory.setUserName(userName);
        activeMQConnectionFactory.setPassword(passWord);
        return activeMQConnectionFactory;
      }

      @Bean// Uses default Jms Listener Container Factory
      public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory =
            new DefaultJmsListenerContainerFactory();
        factory
            .setConnectionFactory(receiverActiveMQConnectionFactory());

        return factory;
      }

      @Bean
      public Receiver receiver() {
        return new Receiver();
      }
}

Geeting this every time i start the application: WARN 12740 --- [206:61616@63304] o.a.activemq.ActiveMQSessionExecutor : Received a message on a connection which is not yet started. Have you forgotten to call Connection.start()? Connection: ActiveMQConnection

GauravRatnawat
  • 717
  • 1
  • 11
  • 25

1 Answers1

0

I foget to mention my user defined jms lisner connection factory name to @jmsListner annotation.

@JmsListener(destination = "Queue-name",containerFactory ="jmsListenerContainerFactory" )
    public void receiveMessage(@Payload final  Message consumerMessage) throws JMSException {
        LOGGER.info("Into receiveMessage Method");
}

But I am still unable to find how this is working for any other activeMQ.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
GauravRatnawat
  • 717
  • 1
  • 11
  • 25