3
votes

I have an embedded broker in tomcat that my webapp clients are connecting to fine using vm://localhost. I would like some remote clients in another jvm be able to connect to the embedded broker. How do I set up the embedded broker to listen on a port#? This works for embedded clients:

server.xml fragment:

<Resource auth="Container" 
name="jms/ConnectionFactory" 
type="org.apache.activemq.ActiveMQConnectionFactory" 
description="JMS Connection Factory" 
factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
brokerURL="vm://localhost" 
brokerName="MyActiveMQBroker" 
useEmbeddedBroker="true"/>  

This isn't working for remote clients, but my embedded clients still connect using vm://localhost:

<Resource auth="Container" 
name="jms/ConnectionFactory" 
type="org.apache.activemq.ActiveMQConnectionFactory" 
description="JMS Connection Factory" 
factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
brokerURL="vm:(broker:(tcp://localhost:61616))" 
brokerName="MyActiveMQBroker" 
useEmbeddedBroker="true"/>  

My remote clients give this error:

Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused

I also have been trying this:

brokerURL="vm://localbroker?brokerConfig=xbean:file:C:/temp/activemq.xml"

and in the activemq.xml, setting this:

<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
</transportConnectors>

<networkConnectors>
<networkConnector uri="static:(tcp://0.0.0.0:61616)"/>
</networkConnectors>

I don't believe the xml file is getting read, because my symptoms never change when editing it. On tomcat startup, when the first client webapp deploys, the broker starts and reports that:

Connector vm://localhost Started

I never see another connector started, like tcp://0.0.0.0:61616. Is this possible?

1

1 Answers

2
votes

vm://localhost will not open tcp port for remote broker to connect. vm protocol can be used within JVM.

Configuration on your local tomcat (e.g. consider local server with hostname as "tomcathostone")

<Resource auth="Container" 
name="jms/ConnectionFactory" 
type="org.apache.activemq.ActiveMQConnectionFactory" 
description="JMS Connection Factory" 
factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
brokerURL="broker:(tcp://0.0.0.0:61616)" 
brokerName="MyActiveMQBroker" 
useEmbeddedBroker="true"/> 

Configuration on your remote tomcat (e.g. consider remote server with hostname as "tomcathosttwo")

<Resource auth="Container" 
name="jms/ConnectionFactory" 
type="org.apache.activemq.ActiveMQConnectionFactory" 
description="JMS Connection Factory" 
factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
brokerURL="broker:(tcp://tomcathosttwo:61616,network:static:tcp://tomcathostone:61616)" 
brokerName="MyActiveMQBroker" 
useEmbeddedBroker="true"/>