ConvertAndSend cannot be dropped when a listener receives a message

I use RabbitMQ to send messages to the queue and to the recipient, I receive it, but I can not use it.

When I send it, I do it.

rabbitTemplate.convertAndSend("myExchange", "binding", MyObject);

MyObjectis a custom object created in this project. In another project, I created in MyObject.classexactly the same way (but I know that the signature of the object is not the same).

The converted set for my listener is as follows.

Jackson2JsonMessageConverter jsonMessageConverter() {
    Jackson2JsonMessageConverter messageConverter = new Jackson2JsonMessageConverter();
    messageConverter.setClassMapper(classMapper());

    return messageConverter;
}

private ClassMapper classMapper() {
    DefaultClassMapper classMapper = new DefaultClassMapper();
    classMapper.setDefaultType(MyObject.class);
    return classMapper;
}

So, for my listener, the following code does not work. I noticed that the body comes with [B@1232(byte[232].

@Override
public void onMessage(final Message message) {
    final MyObject myObject = (MyObject) messageConverter.fromMessage(message);

How do I achieve this?

+4
source share
2 answers

MyObject . , .


- . json ( ) jsonString convertAndSend.

- :

final String jsonString = (String) messageConverter.fromMessage(message);
+1

, MessageConverter Jackson2JsonMessageConverter, json.

Jackson2JsonMessageConverter messageConverter = ...; // create and configure

rabbitTemplate.setMessageConverter(messageConverter);
rabbitTemplate.convertAndSend("myExchange", "binding", MyObject);

default SimpleMessageConverter.

- SimpleMessageConverter, , .

, , MyObject Serializable, MessageConverter .

, . , [B @1232 ( [232].

+1

Source: https://habr.com/ru/post/1658264/


All Articles