Reputation: 33
I am using activeMQ tcp//localhost URL for quiet some time now and i don't have a problem with it. Currently, I am trying to use a "vm//localhost" connector, but i am having a problem with receiving a message from the producer. I am using spring boot, producer and consumer are in different jars. My consumer is receiving a null message. Am I missing something? Below is my code (taken form apache website). Thanks in advance
Producer.jar
ActiveMQConnectionFactory connectionFactory =
new ActiveMQConnectionFactory("vm://localhost");
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("TEST.FOO");
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
String text = "Hello world! From: " + Thread.currentThread().getName() + " : " + this.hashCode();
TextMessage message = session.createTextMessage(text);
System.out.println("Sent message: " + message.hashCode() + " : " + Thread.currentThread().getName());
producer.send(message);
session.close();
connection.close();
Consumer.jar
ActiveMQConnectionFactory connectionFactory =
new ActiveMQConnectionFactory("vm://localhost");
Connection connection = connectionFactory.createConnection();
connection.start();
connection.setExceptionListener(this);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("TEST.FOO");
MessageConsumer consumer = session.createConsumer(destination);
// Wait for a message
Message message = consumer.receive(10000);
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
System.out.println("Received 1: " + text);
} else {
System.out.println("Received 2: " + message);
}
consumer.close();
session.close();
connection.close();
Upvotes: 0
Views: 776
Reputation: 3913
i was sure, vm is the transport inside the VM! and not accessible outside it, so the solution is that one of the 2 clients need to use vm transport and the other one tcp and ActiveMQ started in the one using vm transport or to embedd your 2 components in the same VM .
see my another answer for the same use case How to send Jms message from one spring-boot application to another when both apps use embedded activemq
Upvotes: 1