What is the correct usage of convertAndSend method?

I want to know what are the correct ways of using the method - "convertAndSend".I went through the method signatures in AmqpTemplate class. But the codes in GitHub or the codes I found are not meeting the method signature prototype. For eg -

These were the ones found in codes -

template.convertAndSend("Hello, world!");

But the method signature is -

void convertAndSend(Object message) throws AmqpException

The argument is Object message, but the use case found is String message.

Another use case found -

amqpTemplate.convertAndSend("tp.routingkey.1", "Message # " + messagCount++);

Here both arguments are String. But the method signature close to this - void convertAndSend(String routingKey, Object message) throws AmqpException;

So even here, in the use case, String message is used instead of Object Message.

How will this work?? Are those use cases correct?? Please help.

1 answer

  • answered 2018-03-11 12:56 Gary Russell

    The object can be any type, including String. The conversion is performed by a MessageConverter. The default SimpleMessageConverter can handle byte[], String or java Serializable. There is also a json converter.

    Read the documentation.