Quantcast

Using ActiveMQ via karaf bundle

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using ActiveMQ via karaf bundle

smunro
Hello,

I am a small issue (possible down to my lack of knowledge of Karaf) around accessing a BrokerService (activemq component).

Following the activemq cookbook, I had installed the jms , activemq-broker & activemq-components, and I noticed a configuration (spring) file was created after doing this.

I was hoping to be able to have an osgi bundle which a blueprint.xml file that could reference connection settings defined in the config file.

This is obviously pretty trivial, but I have not found any simple examples on how to do this, more often than not, camel is thrown into the mixture which I do not wish to make use of at  the moment.

So, to be clear, I want to use the embedded activemq feature, be able to reference the broker service within my own osgi bundle and via code, manage subscriptions.

Can anyone point me at some good samples and/or offer any suggestions to achieve what I want.  It's possible blueprint is now the way to go, but I would like to have some declarative control and we are not using spring at the moment either.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using ActiveMQ via karaf bundle

cschneider
Spring is just used inside activemq to setup the broker.

You can use the activemq-cf feature to create a ConnectionFactory from
config.
This is how it works:
https://github.com/apache/activemq/blob/master/activemq-cf/src/main/java/org/apache/activemq/osgi/cf/ConnectionFactoryProvider.java

and this is an example config:
https://github.com/apache/activemq/blob/master/activemq-cf/org.apache.activemq.cfg

You can then reference the ConnectionFactory in your blueprint context
as an OSGi service and inject it into any bean.
Camel-jms is the simplest way to get started with jms but you can also
use plain java.

See this example for using jms with camel and injecting the
ConnectionFactory:
https://github.com/Talend/tesb-rt-se/blob/master/examples/tesb/ebook/ebook-importer/src/main/resources/OSGI-INF/blueprint/blueprint.xml

The example uses jta. In your case you can remove the TransactionManager
parts.

So the context would look like this:
<reference id="connectionFactory" interface="javax.jms.ConnectionFactory" />

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
         <property name="connectionFactory" ref="connectionFactory"/>
</bean>

<camelContext id="ebook-importer"
xmlns="http://camel.apache.org/schema/blueprint">
         <routeBuilder ref="importRoutes" />
</camelContext>

And this is the camel route
https://github.com/Talend/tesb-rt-se/blob/master/examples/tesb/ebook/ebook-importer/src/main/java/org/talend/esb/examples/ebook/importer/ImportRoutes.java 


For accessing jms with plain java you can use any plain java example and
just create a bean for it and inject the ConnectionFactory. Do not
underestimate the complexity of doing jms
by hand though.

Christian

On 11.04.2017 18:23, smunro wrote:

> Hello,
>
> I am a small issue (possible down to my lack of knowledge of Karaf) around
> accessing a BrokerService (activemq component).
>
> Following the activemq cookbook, I had installed the jms , activemq-broker &
> activemq-components, and I noticed a configuration (spring) file was created
> after doing this.
>
> I was hoping to be able to have an osgi bundle which a blueprint.xml file
> that could reference connection settings defined in the config file.
>
> This is obviously pretty trivial, but I have not found any simple examples
> on how to do this, more often than not, camel is thrown into the mixture
> which I do not wish to make use of at  the moment.
>
> So, to be clear, I want to use the embedded activemq feature, be able to
> reference the broker service within my own osgi bundle and via code, manage
> subscriptions.
>
> Can anyone point me at some good samples and/or offer any suggestions to
> achieve what I want.  It's possible blueprint is now the way to go, but I
> would like to have some declarative control and we are not using spring at
> the moment either.
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Using-ActiveMQ-via-karaf-bundle-tp4050100.html
> Sent from the Karaf - User mailing list archive at Nabble.com.


--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using ActiveMQ via karaf bundle

smunro
Thanks for the rapid response and information.

I don't underestimate the complexity of leaving camel out, I have used JMS & Camel, but that was for a complex EIS with multiple disparate systems, this is much simpler.

I've never used MQTT in activemq nor have I had to use activemq via karaf, and that's mostly where my knowledge is lacking. I just needed a simple service way to create MQTT topics, publish and subscribe to the topic and do so in a declarative fashion using blueprint.xml. Unfortunately the majority of examples are a little more complex that what I need. You've given me material to move forward with and I'll give that a spin.

Thanks again!  
Loading...