After peeking a while in the sources of ActiveMQ I discovered the trick by myself: actually it's not ActiveMQ the problem, but the java.net.URI class, which in a string like this:
vm://A_NODE_NAME?create=false&waitForStart=10000 considers "A_NODE_NAME" a malformed host name and sets its corresponding attribute to null, so that it will read like: vm://null?create=false&waitForStart=10000 on both sides. When the two brokers enter in contact one of them finds the transport already bound (by the other). To solve the problem it was enough to change the node name so that it is compliant with host names, like this: vm://A-NODE-NAME?create=false&waitForStart=10000 That's it. Best regards, Gianluca G. Bertani wrote: > > I am trying to embed an ActiveMQ broker inside an application that is > exposing services via JMS. The intent is to create a cluster of brokers so > that: > - each instance of the application has its own broker via VM transport; > - each instance exposes a TCP transport to clients; > - each instance is a node of a network of brokers, where each broker > connects to the others using the TCP transport (statically configured). > > So far I have been able to start one node, but when the second node starts > as soon as it tries to get a connection it gets this mind boggling > exception: > > javax.jms.JMSException: Could not create Transport. Reason: > java.io.IOException: VMTransportServer already bound at: vm://null > at > org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35) > at > org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:239) > at > org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:252) > at > org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:224) > at > org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:172) > ... > Caused by: java.io.IOException: VMTransportServer already bound at: > vm://null > at > org.apache.activemq.transport.vm.VMTransportFactory.bind(VMTransportFactory.java:201) > at > org.apache.activemq.transport.vm.VMTransportFactory.doCompositeConnect(VMTransportFactory.java:133) > at > org.apache.activemq.transport.vm.VMTransportFactory.doConnect(VMTransportFactory.java:53) > at > org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.java:51) > at > org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:80) > at > org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:237) > ... 6 more > > The code that starts the embedded broker is like this: > > ------------------------------- > ActiveMQConnectionFactory conFactory= new ActiveMQConnectionFactory( > "vm://" + nodeName + "?create=false&waitForStart=10000"); > > BrokerService activeMQ= new BrokerService(); > activeMQ.setBrokerName(nodeName); > > if (otherNodes.length > 0) { > String nodesConnectorString= "static:("; > for (String node : otherNodes) > nodesConnectorString += "tcp://" + node.trim() + ","; > nodesConnectorString= nodesConnectorString.substring( > 0, nodesConnectorString.length() -1) + ")"; > > URI nodesConnectorUri= new URI(nodesConnectorString); > NetworkConnector nodeConnector= activeMQ.addNetworkConnector( > nodesConnectorUri); > nodeConnector.setDuplex(true); > } > > URI localConnectorUri= new URI("tcp://localhost:" + externalPort); > activeMQ.addConnector(localConnectorUri); > > activeMQ.start(); > > ActiveMQConnection connection= > (ActiveMQConnection) conFactory.createConnection(); // EXCEPTION! > connection.start(); > ------------------------------- > > I don't understand to what that "vm://null" is referring, since I created > the connection factory specifying a name for the broker (the "nodeName" is > not null). And more, I don't understand how the exception can be raised > about the VM transport, since the two nodes are on separate JVMs... > > Any help would be greatly appreciated. > Thanks in advance. > > Gianluca > -- View this message in context: http://www.nabble.com/VMTransportServer-already-bound-tp23296126p23296815.html Sent from the ActiveMQ - User mailing list archive at Nabble.com.