2

I have a Stomp Over WebSocket client using Stomp.js that send a message to a queue:

var destinationProductProd_02 = "jms.queue.shat";
function sendMessageProduct() {

    var product = {
      productId : "111",
      name : "laptop",
      quantity: 2
    }

    var beforeSend = JSON.stringify(product);
    console.log("typeof message: "+ typeof beforeSend);   // <<--- String
    stompClient.send(destinationProductProd_02, {}, beforeSend);

}

And in the server side I have

@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {

    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

    factory.setConnectionFactory(connectionFactory);
    factory.setConcurrency("3-10");

    SimpleMessageConverter s = new SimpleMessageConverter();
    factory.setMessageConverter(s);

    return factory;
}

SimpleMessageConverter is the default converter that use Spring. My listerner is the next:

@JmsListener(containerFactory = "jmsListenerContainerFactory", destination = ORDER_QUEUE)
public void receiveMessage(Session ses, @Payload final Message message, @Headers final Map<String, Object> headers)  {
    System.out.println("MessageReceiver::receiveMessage(product)   payload class:  "+ message.getPayload().getClass());
}

the message.getPayload().getClass() indicates that the payload type is an byte array ([B).

Why I'm receiving binary array if I'm sending text?

Or how can I cast this byte array to Java object. What happens if I send JSON and Serialized Java Object to the same queue... how manage two different type of message in the same queue? I want use some like:

public void receiveMessage(@Payload final Message<Product> message){...}

where product is a POJO class

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
Sergio
  • 441
  • 9
  • 22

0 Answers0