I have two spring-boot applications. in receiver-application's Application.java I have:
@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
configurer.configure(factory, connectionFactory);
return factory;
}
and in Receiver.java ...
@JmsListener(destination = "myQueue", containerFactory = "myFactory")
public void receiveMessage(String tradeString) throws JSONException, IOException {
tradeImpl = new ObjectMapper().readValue(tradeString, TradeImpl.class);
}
In sender-application I simply use:
public void send(trade) {
String queueName = "myQueue";
String tradeString = new ObjectMapper().writeValueAsString(trade);
jmsTemplate.convertAndSend(queueName, tradeString);
}
So I'm just sending the message to the queue name specified in receiver-application. I get the following in the logs
Failed to start JMX connector Cannot bind to URL [rmi://localhost:1099>/jmxrmi]: javax.naming.NameAlreadyBoundException: jmxrmi [Root exception is java.rmi.AlreadyBoundException:
I have read the following post and didn't find it very encouraging:
Spring boot - sharing embedded JMS broker with separate service
It concludes with:
But As I mentioned I didn't make this working before and not sure if it is possible. Didn't find in Spring Boot docs explicit message it doesn't work in this combination.
I suspect the idea behind embedded Spring Boot JMS broker is to allow local in memory integration testing only, not to expose embedded JMS brokers to the outside world.
Does anybody know if what I want to do is indeed possible? And if not, are there any suggestions on how I can achieve messaging between to spring-boot apps using embedded brokers?
If your 2 spring boot apps are on the same jvm you simply have to add in application.properties of only one of the two :
If your 2 spring boot apps are on 2 differents jvm: In one spring boot app you need to have :
In pom.xml
In the second one :
In application.properties
In pom.xml
For the case that you have 2 jvm, 1 for each app, By default spring boot will configure AMQ with only vm connector, in the first app you need to add tcp connector like this :
Try to specify
spring.activemq.brokerUrl=tcp://localhost:61616
for theproducer
application.This way an embedded ActiveMQ Broker will be disabled and a connection to another started on the
61616
port will be performed.