2 Replies Latest reply on Jul 8, 2014 10:43 AM by Clebert Suconic

    BytesMessage is received when MapMessage is sent using Qpid-AMQP JMS client

    Shuaib Yunus Newbie

      Hi team,

       

      Does anyone know what's going on in my use case below?

       

      I have 2 clients, a producer and a consumer.

       

      Producer sends a MapMessage:

       

      import javax.jms.Connection;
      import javax.jms.ConnectionFactory;
      import javax.jms.JMSException;
      import javax.jms.MessageProducer;
      import javax.jms.Session;
      import javax.jms.MapMessage;
      
      // SNIP!!!
      
      ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("localhost");
      Connection connection = connectionFactory.createConnection();
      
      Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer producer = sendSession.createProducer(sendSession.createTopic("jms.topic.exampleTopic"));
           
      MapMessage message = sendSession.createMapMessage();
      message.setBoolean("TEST", true);
      producer.send(message);
      

       

      Consumer receives the MapMessage:

       

      MessageConsumer consumer = receiveSession.createConsumer(session.createTopic("subscription1"));
      
      consumer.setMessageListener(new MessageListener() {
      
          public void onMessage(Message message) {
              try {
                  System.out.println("Subscriber1 received message: " + ((MapMessage) message).getBoolean("TEST"));
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
      
      connection.start();
      

       

      When the consumer is run, this occurs:

       

      java.lang.ClassCastException: org.apache.qpid.amqp_1_0.jms.impl.BytesMessageImpl cannot be cast to org.apache.qpid.amqp_1_0.jms.MapMessage
          at com.kaazing.jms.client.demo.Subscriber$1.onMessage(Subscriber.java:82)
          at org.apache.qpid.amqp_1_0.jms.impl.SessionImpl$Dispatcher.run(SessionImpl.java:941)
          at java.lang.Thread.run(Thread.java:744)