Issue
I'm developing a producer-consumer application. The two are connected through an ActiveMQ queue. When I try to send a message, the following string is prepended before the content:
Sr�)�x-opt-jms-destQ�x-opt-jms-msg-typeQSs�d
�/ID:72a1faef-ff5a-40dd-aecc-61e94c0a432a:1:1:1-1@�queue://name_of_my_queue@@@@@@�~
�Sw�
actual message
The message is detected by the consumer as an ActiveMQBytesMessage and there's no way for it to get its content correctly. Here are the code snippets for the producer and consumer:
Consumer
String receiveMessage() {
MessageConsumer consumer = session.createConsumer(session.createQueue(receiverQueue));
String content = "";
try {
Message message = consumer.receive();
if(message instanceof TextMessage) {
content = ((TextMessage) message).getText();
}
else {
BytesMessage byteMessage = (BytesMessage) message;
byte[] byteData = null;
byteData = new byte[(int) byteMessage.getBodyLength()];
byteMessage.readBytes(byteData);
byteMessage.reset();
content = new String(byteData);
}
}
catch (JMSException | JsonProcessingException e) {
log.error(e.getMessage());
}
return content;
}
Producer
void sendMessage() {
JMSContext context;
try {
context = connectionFactory.createContext(Session.AUTO_ACKNOWLEDGE);
JMSProducer producer = context.createProducer();
TextMessage tm = context.createTextMessage("TestMessage");
producer.send(context.createQueue(myQueue), tm);
}
}
catch (JMSException | JsonProcessingException e) {
System.out.println(e.getMessage());
}
}
The producer is in a quarkus application. How can I solve this problem? Thank you!
Solution
For those of you who might run into the same issue: I figured out the problem was the broker. I was using a rmohr/activemq container and I solved it by switching to vromero/activemq-artemis
Answered By - Giulia Fois