activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Fernandez" <joe.fernan...@ttmsolutions.com>
Subject RE: Help with embedded brokers
Date Thu, 01 May 2008 17:56:36 GMT
What's happening is that you have two brokers with the same name trying to
connect with one another.  The exception throws people off because they
always perceive it mean that it has something to do with their client, which
is not always the case. Whenever you see the "NC_" prefix associated with
this exception it reflects a local or remote bridge between two brokers.  

This is how the clientID is constructed if the broker was trying to set up a
local bridge.  

localClientId = "NC_" + remoteBrokerName + "_inbound" +
configuration.getBrokerName();

And this one if the broker was trying to set up a remote bridge. 

remoteConnectionInfo.setClientId("NC_" + configuration.getBrokerName() +
"_outbound");

In your case, it is a local bridge, but the local and remote broker names
are the same (i.e., localhost). 

Joe
Goto www.ttmsolutions.com for a free ActiveMQ user guide


-----Original Message-----
From: matt hoffman [mailto:matt@mhoffman.org] 
Sent: Thursday, May 01, 2008 11:30 AM
To: users@activemq.apache.org
Subject: Help with embedded brokers

I'm having a lot of trouble getting embedded brokers to work as they
should.  I'm using them in my case mainly to ease configuration -- I want to
be able to run several instances of the same code and have them discover
each other and communicate, without needing a single server already running.


The current problem is, the first server starts up great, and works as
expected.  Subsequent servers, though, throw this error:

javax.jms.InvalidClientIDException: Broker: localhost - Client:
NC_localhost_inboundlocalhost already connected from vm://localhost#0

Which seems strange, seeing as how I'm not explicitly setting clientID
anywhere.  I thought these were auto-generated?

Below is the configuration I'm currently using.  I'm not referencing the
broker in code at all; I'm interacting with it only through the Spring
JmsTemplate, which in turn gets a connection from the
ActiveMQConnectionFactory connecting to vm://localhost.  Based on the
documentation, that seems to be the way to do it... what have I
misunderstood?


In my Spring config:

    <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
        <property name="config" value="classpath:activemq.xml" />
        <property name="start" value="true" />
    </bean>

    <bean id="workQueueDestination"
class="org.apache.activemq.command.ActiveMQQueue">
        <constructor-arg index="0" value="Test.WorkQueue"/>
    </bean>

    <bean id="eventTopicDestination"
class="org.apache.activemq.command.ActiveMQTopic">
        <constructor-arg index="0" value="Test.EventTopic"/>
    </bean>

    <bean id="jmsFactory"
class="org.apache.activemq.ActiveMQConnectionFactory" depends-on="broker">
        <property name="brokerURL" value="vm://localhost"/>
    </bean>

    <bean id="workQueueJmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory">
            <!-- wrapping in a pool to avoid creating a connection per send
-->
            <bean
class="org.springframework.jms.connection.CachingConnectionFactory">
                <property name="targetConnectionFactory">
                    <ref local="jmsFactory"/>
                </property>
            </bean>
        </property>

        <property name="defaultDestination" ref="workQueueDestination"/>
    </bean>

I previously tried including the broker config directly in the Spring file,
but broke it out as a problem-solving exercise and haven't moved it back
yet.
Here's the referenced activemq.xml:


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:jms="http://activemq.org/config/1.0"
       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.org/config/1.0
http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd"
       default-lazy-init="false">

    <jms:broker id="broker" persistent="false" useJmx="true">
        <jms:networkConnectors>
            <jms:networkConnector uri="multicast://default" duplex="true"/>
            <!-- by default just auto discover the other brokers -->
        </jms:networkConnectors>

        <jms:persistenceAdapter>
            <jms:memoryPersistenceAdapter/>
        </jms:persistenceAdapter>

        <jms:transportConnectors>
            <jms:transportConnector name="openwire" uri="tcp://localhost:0"
discoveryUri="multicast://default"/>
        </jms:transportConnectors>

    </jms:broker>

</beans>


Mime
View raw message