I need to add the SOH unicode in a RabbitMQ payload.
For that I'm using this dependency in java:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.7.0</version>
</dependency>
and I add the message with this code:
rabbitTemplate.convertAndSend(messageQueueName, "test\u0001test");
When I put a breakpoint and evaluate this string, it indeed is composed of "test" + SOH + "test". Unfortunately, when the message is sent, the resulting message stored in the RabbitMQ queue is:
"test\u0001test"
Which is not what I want as the receiving application can't identify the SOH which is used as a separator.
I tried to find information about payload format but I found nothing relevant, I'm starting to guess that it's more about a rabbitMQ configuration but as I'm very new to this, I'm not sure.
I tried to solve this java side by modifying the header or content type like this:
rabbitTemplate.convertAndSend(messageQueueName, "test\u0001test", m -> {
m.getMessageProperties().getHeaders().put(JMS_TYPE_HEADER, "TextMessage");
m.getMessageProperties().setContentType("text/plain");
return m;
});
I tried with bytesMessage and application/octet-stream as well. But the results were the same.
Could you please tell me what kind of configuration I would need in order to have the unicode symbol for SOH in the payload of the message that I sent to RabbitMQ?
Thank you and have a nice day.
Ok I found the solution.
The problem was due to the fact that I called rabbitTemplate.convertAndSend with the string as the message directly.
RabbitTemplate actualy tries to convert the string as a Message if it is not a Message that is given, but the conversion get rid of the special symbols and it add quotes to the text.
So the solution was to create myself the Message object and then send it like that:
Message message = new Message("test\u0001test".getBytes(StandardCharsets.UTF_8));
rabbitTemplate.convertAndSend(queueName, message);