You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Eugeny N Dzhurinsky <bo...@redwerk.com> on 2008/08/20 14:00:55 UTC

Embedded broker, adding connections after broker was configured with xbean:

Hello all!

I have the activemq.xml file, listed below:

<beans>
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
    <broker brokerName="broker0" xmlns="http://activemq.org/config/1.0">
        <managementContext>
            <managementContext connectorPort="1599"
                jmxDomainName="org.apache.activemq"/>
        </managementContext>
        <!--
        <transportConnectors>
            <transportConnector name="openwire" uri="tcp://localhost:1235" />
        </transportConnectors>
        -->
    </broker>
    <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
        <connectors>
            <nioConnector port="8161" />
        </connectors>
        <handlers>
            <webAppContext contextPath="/fileserver"
                resourceBase="webapps/" logUrlOnStart="true" />
        </handlers>
    </jetty>
</beans>

When transportConnectors section was uncommented, everything is working fine -
the broker is listening for connections at port 1235.

Due to flexibility requests we need to allow the application to be configured
by passing the broker connection url through the command line, so we decided
to comment out the transportConnectors section and use addConnection() method
in the broker as listed below:

    final BrokerService broker = BrokerFactory.createBroker(new URI(
                        "xbean:activemq.xml"));
    System.out.format("Using transport connector '%1$s'\n", connectorUrl);
    broker.addConnector(connectorUrl);
    broker.start();

However this doesn't work well - while there is something listening on port
1235, the remote clients of the brokers are getting such exception during
connection:

Exception in thread "main" javax.jms.JMSException: Wire format negotiation timeout: peer did not send his wire format.
        at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:62)
        at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1206)
        at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1289)
        at org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:456)

With replacing the code line 
    final BrokerService broker = BrokerFactory.createBroker(new URI(
                        "xbean:activemq.xml"));
with

final BrokerService broker = new BrokerService();

everything works fine and connections are negitiated and accepted by broker.

the question is - what is the correct way to add the connection listeners to the
BrokerService, configured with bean definition like I pasted above?

Thank you in advance!

-- 
Eugene N Dzhurinsky

Re: Embedded broker, adding connections after broker was configured with xbean:

Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Thu, Aug 21, 2008 at 12:33:52PM +0300, Eugeny N Dzhurinsky wrote:
> the method createBroker doesn't start the broker.
> 
> Or I didn't understand what you meant with 
> 
> > What should help is to add a start="false" attribute to the broker xbean.
> 
> Could you please advice?

sorry, I've tried to rewrite the <broker> tag like this

<broker brokerName="broker0" xmlns="http://activemq.org/config/1.0"
start="false">

and everything works fine!

So looks like the fact the broker is being started when created using XBean
definition and the fact the broker doesn't respect the connections being added
to it after the broker is started are needing to be noticed somewhere in faq
or something like this :)

Thank you for help!

-- 
Eugene N Dzhurinsky

Re: Embedded broker, adding connections after broker was configured with xbean:

Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Wed, Aug 20, 2008 at 01:35:58PM +0100, Gary Tully wrote:
> I think the issue is that the broker configured via
> "xbean:activemq.xml" is started eagerly. That is, it is started before
> your connector is added. What should help is to add a start="false"
> attribute to the broker xbean.
> 
> not sure what is deemed the correct way, there are a bunch of ways to
> configure and start a broker. A way that works for you is the correct
> way!
> 
> hope this helps.

This seems not working, as I found in sources for BrokerFactory:

==============================================================================================
    /**
     * Creates a broker from a URI configuration
     * 
     * @param brokerURI the URI scheme to configure the broker
     * @throws Exception
     */
    public static BrokerService createBroker(URI brokerURI) throws Exception {
        return createBroker(brokerURI, false);
    }

    /**
     * Creates a broker from a URI configuration
     * 
     * @param brokerURI the URI scheme to configure the broker
     * @param startBroker whether or not the broker should have its
     *                {@link BrokerService#start()} method called after
     *                construction
     * @throws Exception
     */
    public static BrokerService createBroker(URI brokerURI, boolean startBroker) throws Exception {
        if (brokerURI.getScheme() == null) {
            throw new IllegalArgumentException("Invalid broker URI, no scheme specified: " + brokerURI);
        }
        BrokerFactoryHandler handler = createBrokerFactoryHandler(brokerURI.getScheme());
        BrokerService broker = handler.createBroker(brokerURI);
        if (startBroker) {
            broker.start();
        }
        return broker;
    }
==============================================================================================

the method createBroker doesn't start the broker.

Or I didn't understand what you meant with 

> What should help is to add a start="false" attribute to the broker xbean.

Could you please advice?

-- 
Eugene N Dzhurinsky

Re: Embedded broker, adding connections after broker was configured with xbean:

Posted by Gary Tully <ga...@gmail.com>.
I think the issue is that the broker configured via
"xbean:activemq.xml" is started eagerly. That is, it is started before
your connector is added. What should help is to add a start="false"
attribute to the broker xbean.

not sure what is deemed the correct way, there are a bunch of ways to
configure and start a broker. A way that works for you is the correct
way!

hope this helps.

2008/8/20 Eugeny N Dzhurinsky <bo...@redwerk.com>:
> Hello all!
>
> I have the activemq.xml file, listed below:
>
> <beans>
>    <bean
>        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
>    <broker brokerName="broker0" xmlns="http://activemq.org/config/1.0">
>        <managementContext>
>            <managementContext connectorPort="1599"
>                jmxDomainName="org.apache.activemq"/>
>        </managementContext>
>        <!--
>        <transportConnectors>
>            <transportConnector name="openwire" uri="tcp://localhost:1235" />
>        </transportConnectors>
>        -->
>    </broker>
>    <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
>        <connectors>
>            <nioConnector port="8161" />
>        </connectors>
>        <handlers>
>            <webAppContext contextPath="/fileserver"
>                resourceBase="webapps/" logUrlOnStart="true" />
>        </handlers>
>    </jetty>
> </beans>
>
> When transportConnectors section was uncommented, everything is working fine -
> the broker is listening for connections at port 1235.
>
> Due to flexibility requests we need to allow the application to be configured
> by passing the broker connection url through the command line, so we decided
> to comment out the transportConnectors section and use addConnection() method
> in the broker as listed below:
>
>    final BrokerService broker = BrokerFactory.createBroker(new URI(
>                        "xbean:activemq.xml"));
>    System.out.format("Using transport connector '%1$s'\n", connectorUrl);
>    broker.addConnector(connectorUrl);
>    broker.start();
>
> However this doesn't work well - while there is something listening on port
> 1235, the remote clients of the brokers are getting such exception during
> connection:
>
> Exception in thread "main" javax.jms.JMSException: Wire format negotiation timeout: peer did not send his wire format.
>        at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:62)
>        at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1206)
>        at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1289)
>        at org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:456)
>
> With replacing the code line
>    final BrokerService broker = BrokerFactory.createBroker(new URI(
>                        "xbean:activemq.xml"));
> with
>
> final BrokerService broker = new BrokerService();
>
> everything works fine and connections are negitiated and accepted by broker.
>
> the question is - what is the correct way to add the connection listeners to the
> BrokerService, configured with bean definition like I pasted above?
>
> Thank you in advance!
>
> --
> Eugene N Dzhurinsky
>