Connection Refused from ActiveMQConnectionFactory

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Connection Refused from ActiveMQConnectionFactory

Neduz
Hello,

Since I upgraded from ActiveMQ 5.7.0 to 5.8.0 in Karaf 2.3.0, I had to change the configuration for the setup of the embedded broker and the ConnectionFactory service.
Previously I created the broker and the ConnectionFactory from the same blueprint XML file, using the activemq xbean namespace.
Now the broker is created in a spring XML file (which was installed in the KARAF_HOME/etc folder automatically).

I use this blueprint xml to create a ConnectionFactory service:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
           xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
           xmlns:amq="http://activemq.apache.org/schema/core">

   
    <ext:property-placeholder />

    <bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" >
        <property name="brokerURL" value="tcp://localhost:61616?connectionTimeout=10000" />
                <property name="userName" value="****"/>
                <property name="password" value="****"/>
    </bean>

    <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
        <property name="maxConnections" value="50" />
        <property name="connectionFactory" ref="activemqConnectionFactory" />
    </bean>

    <bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
          <property name="transactionManager" ref="transactionManager" />
          <property name="connectionFactory" ref="activemqConnectionFactory" />
          <property name="resourceName" value="activemq.resourcemanager" />
    </bean>

    <reference id="transactionManager" interface="javax.transaction.TransactionManager" />

    <service ref="pooledConnectionFactory" interface="javax.jms.ConnectionFactory">
        <service-properties>
            <entry key="name" value="amqCF-pool"/>
        </service-properties>
    </service>

</blueprint>


The result is that even though the Spring xml file has a lower start level in Karaf, the connectionFactory service gets a "connection refused" when the first bundle(s) tries to use the ConnectionFactory Service. When I restart the failed bundles, they can connect and the system runs fine.

So the startlevel("default" broker) < startlevel(connection-factory.xml)< startlevel(my bundles using the connection factory).

I tried the old blueprint-broker xml, but the namespace handler seems to be lacking (can't find it in the Services tab on the karaf web console). I cannot see an activemq-blueprint feature anymore (it's not listed in http://activemq.apache.org/osgi-integration.html either).

I tried the "depends-on" attribute; but it seems blueprint can't see the spring-id's in other bundles/xml files.

I also tried to play with the brokerUrl option "connectionTimeout", but the Connection Refused keeps coming at startup.

The only work around I can think of (but haven't tried yet) is to create a "dummy bundle" with a start level between the broker and the connection factory service and perform a thread.sleep in the startUp method, hoping that the broker's threads have enough time to start before the ActiveMQConnectionFactory is started.

I could also try to use spring-beans/spring-dm xml format to create the connectionfactory bean and register the service, but as I was only using blueprint so far, I'd like to stick to one standard for the whole application.

Does anyone have any suggestions how to get the ConnectionFactory service running after the broker started?


Kind regards,

Tom Mercelis
Reply | Threaded
Open this post in threaded view
|

Re: Connection Refused from ActiveMQConnectionFactory

gtully
I guess the service factory that creates the broker should register a vm
connection factory service in osgi once it has successfully started a
broker,
 that could then be used to depend on. I think that is a sensible
enhancement.

One thing that may help today is adding a dependency on the service factory
from activemq-osgi in your blueprint.
 <service ref="activeMQServiceFactory"
interface="org.osgi.service.cm.ManagedServiceFactory">

Once that is available, bound, you know at least that the broker has
started.


On 27 February 2013 12:16, Neduz <[hidden email]> wrote:

> Hello,
>
> Since I upgraded from ActiveMQ 5.7.0 to 5.8.0 in Karaf 2.3.0, I had to
> change the configuration for the setup of the embedded broker and the
> ConnectionFactory service.
> Previously I created the broker and the ConnectionFactory from the same
> blueprint XML file, using the activemq xbean namespace.
> Now the broker is created in a spring XML file (which was installed in the
> KARAF_HOME/etc folder automatically).
>
> I use this blueprint xml to create a ConnectionFactory service:
>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>
> xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
>
> xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
>            xmlns:amq="http://activemq.apache.org/schema/core">
>
>
>     <ext:property-placeholder />
>
>     <bean id="activemqConnectionFactory"
> class="org.apache.activemq.ActiveMQConnectionFactory" >
>         <property name="brokerURL"
> value="tcp://localhost:61616?connectionTimeout=10000" />
>                 <property name="userName" value="****"/>
>                 <property name="password" value="****"/>
>     </bean>
>
>     <bean id="pooledConnectionFactory"
> class="org.apache.activemq.pool.PooledConnectionFactory">
>         <property name="maxConnections" value="50" />
>         <property name="connectionFactory" ref="activemqConnectionFactory"
> />
>     </bean>
>
>     <bean id="resourceManager"
> class="org.apache.activemq.pool.ActiveMQResourceManager"
> init-method="recoverResource">
>           <property name="transactionManager" ref="transactionManager" />
>           <property name="connectionFactory"
> ref="activemqConnectionFactory"
> />
>           <property name="resourceName" value="activemq.resourcemanager" />
>     </bean>
>
>     <reference id="transactionManager"
> interface="javax.transaction.TransactionManager" />
>
>     <service ref="pooledConnectionFactory"
> interface="javax.jms.ConnectionFactory">
>         <service-properties>
>             <entry key="name" value="amqCF-pool"/>
>         </service-properties>
>     </service>
>
> </blueprint>
>
>
> The result is that even though the Spring xml file has a lower start level
> in Karaf, the connectionFactory service gets a "connection refused" when
> the
> first bundle(s) tries to use the ConnectionFactory Service. When I restart
> the failed bundles, they can connect and the system runs fine.
>
> So the startlevel("default" broker) < startlevel(connection-factory.xml)<
> startlevel(my bundles using the connection factory).
>
> I tried the old blueprint-broker xml, but the namespace handler seems to be
> lacking (can't find it in the Services tab on the karaf web console). I
> cannot see an activemq-blueprint feature anymore (it's not listed in
> http://activemq.apache.org/osgi-integration.html either).
>
> I tried the "depends-on" attribute; but it seems blueprint can't see the
> spring-id's in other bundles/xml files.
>
> I also tried to play with the brokerUrl option "connectionTimeout", but the
> Connection Refused keeps coming at startup.
>
> The only work around I can think of (but haven't tried yet) is to create a
> "dummy bundle" with a start level between the broker and the connection
> factory service and perform a thread.sleep in the startUp method, hoping
> that the broker's threads have enough time to start before the
> ActiveMQConnectionFactory is started.
>
> I could also try to use spring-beans/spring-dm xml format to create the
> connectionfactory bean and register the service, but as I was only using
> blueprint so far, I'd like to stick to one standard for the whole
> application.
>
> Does anyone have any suggestions how to get the ConnectionFactory service
> running after the broker started?
>
>
> Kind regards,
>
> Tom Mercelis
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Connection-Refused-from-ActiveMQConnectionFactory-tp4664195.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



--
http://redhat.com
http://blog.garytully.com
Reply | Threaded
Open this post in threaded view
|

Re: Connection Refused from ActiveMQConnectionFactory

Neduz
Hello,

I've tried adding

	<reference id="activeMQServiceFactory" interface="org.osgi.service.cm.ManagedServiceFactory" filter="(osgi.service.blueprint.compname=activeMQServiceFactory)" availability="mandatory" activation="eager"/>

As first blueprint item in the blueprint xml file as this services provided by the bundle from mvn:org.apache.activemq/activemq-osgi/5.8.0

But that doesn't resolve the problem apparently.


2013-03-04 13:16:26,371 | ERROR | rint Extender: 2 | BlueprintContainerImpl           | container.BlueprintContainerImpl  375 | 7 - org.apache.aries.blueprint.core - 1.0.1 | Unable to start blueprint container for bundle myproject-myblueprintconfig.xml
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to convert value BeanRecipe[name='#recipe-2'] to type class java.lang.Object
[snip some stacktrace]
Caused by: org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to intialize bean mybean
[snip some more stacktrace]
Caused by: java.lang.RuntimeException: javax.jms.JMSException: Error while attempting to add new Connection to the pool
[snip stacktrace]
Caused by: javax.jms.JMSException: Error while attempting to add new Connection to the pool
	at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
[snip]
Caused by: javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616?connectionTimeout=10000. Reason: java.net.ConnectException: Connection refused: connect
[snip]
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)[:1.7.0_11]
[snip]

And the Broker is only ready about 1.1s later:
2013-03-04 13:16:27,449 | INFO  | ... | 62 - org.apache.activemq.activemq-osgi - 5.8.0 | Connector openwire Started
2013-03-04 13:16:27,464 | INFO  | ... | 62 - org.apache.activemq.activemq-osgi - 5.8.0 | Apache ActiveMQ 5.8.0 (amq-broker, ID:******62399384059-2:1) started

Did I correctly implement your suggestion? I've added the filter option because file-installer also provides an ManagedServiceFactory. And the availability and activation options I added assuming they would prevent blueprint from just making proxies before the service is actually available.

At every Karaf start another bundle or bundles fail to start due to the connection refused message. Sometimes (about 1 in 4 or 1 in 5 times) all bundles start perfectly.

PS: I agree that using the "waiting" for an OSGI service to be available is the best approach for a mixed blueprint/spring-beans environment; but was the Blueprint method for creating a broker deliberately dropped? If yes for what reason(s)?

Kind regards,

Tom Mercelis
Reply | Threaded
Open this post in threaded view
|

Re: Connection Refused from ActiveMQConnectionFactory

gtully
The service factory that auto creates the broker based on
etc/org.apache.activemq.server-default.cfg only supports spring xml at the
moment, the injection of properties into a blueprint context that
is explicitly created by the ManagedServiceFactory needs to be in
investigated some more to have is support blueprint in the same way.
Please create an enhancement to track this, because it is something we
should do for the next release.

But the old way of deploying a blueprint xml that contains a broker is
still possible, just drop the blueprint xml into the deploy directory or
add it to your bundle and it will be get initialised.
What has been dropped are the karaf commands that do the copy into the
deploy directory for you.
Using a managed service factory and external properties that can be visible
via config admin provides a more consistent karaf experience.


On 4 March 2013 13:11, Neduz <[hidden email]> wrote:

> Hello,
>
> I've tried adding
>
>
>
> As first blueprint item in the blueprint xml file as this services provided
> by the bundle from mvn:org.apache.activemq/activemq-osgi/5.8.0
>
> But that doesn't resolve the problem apparently.
>
>
>
>
> And the Broker is only ready about 1.1s later:
>
>
> Did I correctly implement your suggestion? I've added the filter option
> because file-installer also provides an ManagedServiceFactory. And the
> availability and activation options I added assuming they would prevent
> blueprint from just making proxies before the service is actually
> available.
>
> At every Karaf start another bundle or bundles fail to start due to the
> connection refused message. Sometimes (about 1 in 4 or 1 in 5 times) all
> bundles start perfectly.
>
> PS: I agree that using the "waiting" for an OSGI service to be available is
> the best approach for a mixed blueprint/spring-beans environment; but was
> the Blueprint method for creating a broker deliberately dropped? If yes for
> what reason(s)?
>
> Kind regards,
>
> Tom Mercelis
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Connection-Refused-from-ActiveMQConnectionFactory-tp4664195p4664342.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



--
http://redhat.com
http://blog.garytully.com
Reply | Threaded
Open this post in threaded view
|

Re: Connection Refused from ActiveMQConnectionFactory

Neduz
Hello,

Maybe the user forum is not the recommended place for this discussion: but besides the blueprint xml discussion; there's another "design" question that I'm not sure of how it is seen by the AMQ devs at this moment:

I'll be making a few assumptions since I'm not very experienced with ActiveMQ or Karaf or Blueprint:
1) The default contract of ConnectionFactory is that it can throw exceptions if the JMS broker is not immediately available for some reason (that's at least the behavior I'm seeing).
2) The creation of the instances of ActiveMQConnectionFactory & PooledConnectionFactory is in my example done with Blueprint, but it could as well be written POJO classes, in any OSGi or JEE container. So the design is very all-purpose.

The solutions we were currently discussing are all based on the Broker and the Client being in the same OSGI/Spring/Blueprint context, but that may not always be true. Wouldn't it be useful to have an option in the (Pooled)ActiveMQConnectionFactory that there's a blocking start-method that blocks until the connection with the broker(url) is established. This would allow the "default" behavior of OSGI to be used:
The (pooled)connectionfactory is offered as a Service, and giving it a blocking start/init-method that retries until success or some configurable limit is reached (time/attempts/...) would delay the start of all bundles consuming the javax.jms.ConnectionFactory Service until the broker is really available (whether this in in the same runtime or anywhere else on the network).

I can implement this try/retry strategy in the init-method of all my blueprint bundles; but I think it would be a good addition to have this functionality in AMQ.

Kind regards,

Tom Mercelis
Reply | Threaded
Open this post in threaded view
|

Re: Connection Refused from ActiveMQConnectionFactory

Tom_Z
In reply to this post by Neduz
Hi there,

<reference id="amqFactory" interface="javax.jms.ConnectionFactory" />

worked for me in 5.9.1...

Tom