benji benji - 4 months ago 12
Java Question

Could not start network bridge due to: java.net.ConnectException: Connection refused: connect

I am trying to define a network bridge between a broker in a non-primary site and a broker in a primary site with the expected behavior that messages produced in a non-primary-site get forwarded to the primary site and processed there.

After doing some research online I added a

<networkConnectors/>
element to the xml file for my non-primary broker pointing to the primary broker.

This is the XML file for the primary broker:

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="Broker" dataDirectory="SOME_PATH" destroyApplicationContextOnStop="true" advisorySupport="false" schedulerSupport="true">

<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" producerFlowControl="true" memoryLimit="20mb">
<pendingSubscriberPolicy>
<vmCursor />
</pendingSubscriberPolicy>
</policyEntry>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="20mb">
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>

<managementContext>
<managementContext createConnector="false"/>
</managementContext>

<persistenceAdapter>
<kahaDB directory="SOME_PATH"/>
</persistenceAdapter>

<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="50 mb"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="1 gb"/>
</storeUsage>
<tempUsage>
<tempUsage limit="100 mb"/>
</tempUsage>
</systemUsage>
</systemUsage>

<transportConnectors>
<transportConnector name="primary_broker" uri="tcp://localhost:2384"/>
</transportConnectors>

</broker>
</beans>


This is the XML file for the non-primary broker:

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="Broker" dataDirectory="SOME_PATH" destroyApplicationContextOnStop="true" advisorySupport="false" schedulerSupport="true">

<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" producerFlowControl="true" memoryLimit="20mb">
<pendingSubscriberPolicy>
<vmCursor />
</pendingSubscriberPolicy>
</policyEntry>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="20mb">
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>

<managementContext>
<managementContext createConnector="false"/>
</managementContext>

<networkConnectors>
<networkConnector name="bridge" uri="static:(tcp://PRIMARY_SERVER_NAME:2384)"/>
</networkConnectors>

<persistenceAdapter>
<kahaDB directory="SOME_PATH"/>
</persistenceAdapter>

<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="50 mb"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="1 gb"/>
</storeUsage>
<tempUsage>
<tempUsage limit="100 mb"/>
</tempUsage>
</systemUsage>
</systemUsage>

<transportConnectors>
<transportConnector name="secondary_broker" uri="tcp://localhost:2386"/>
</transportConnectors>

</broker>
</beans>


The error I am seeing when I am trying to start up the non-primary broker is:

Could not start network bridge between: vm://Broker?async=false&network=true and: tcp://PRIMARY_SERVER_NAME:2384 due to: java.net.ConnectException: Connection refused: connect


I did some investigation and got the IT team involved and confirmed that it is not a firewall issue.

I tried to set up a network between 2 brokers on the same non-primary host. I used the same configuration (i.e. just by updating the
uri
value in
networkConnector
) and this time the network was established successfully.

I am not sure what is going on and why using the same configuration, and assuming there's no network issue, I am able to bridge 2 brokers on the same host, but not on different hosts.

I am using ActiveMQ v5.5.

Answer

The issue was that the <transportConnector/> element in the primary broker was configured with localhost
After changing it to use the actual server name instead it worked

<transportConnectors>
    <transportConnector name="primary_broker" uri="tcp://SERVER_NAME:2384"/>
</transportConnectors>
Comments