JMS Setup

Jms installation

You have to install the jms feature first, so start the console and enter the following commands:

  karaf@root()> feature:install jms
  karaf@root()> feature:install gvvcl-jms

The jms feature doesn’t install a JMS broker: it just installs the OSGi service, commands, and MBean to interact with a JMS broker (not the broker itself).

It means that you have to install a JMS broker.

ActiveMQ installation

We are going to install ActiveMQ outside of Apache Karaf, as a standalone broker. Apache Karaf JMS will remotely connect to the JMS broker.

To install ActiveMQ, you can follow the Apache documentation:

Now you have to install the activemq client on the console:

  karaf@root()> feature:install activemq-client

Configure a new JMS connection

Once JMS and ActiveMQ are installed, you can create a new connection by using the following command:

  karaf@root()> jms:create -t activemq -u gvadmin -p gvadmin --url tcp://localhost:61616 ConnectionName
  • Now you should be able to see the jms connection using the command:

    jndi:names
    

  • You can edit the JMS configuration by edit the file [KARAF_HOME]/deploy/connectionfactory-default.xml

  • Go to ActiveMQ console

if you have troubles, check the configuration file [KARAF_HOME]/etc/org.apache.activemq.webconsole.cfg

  webconsole.jms.url=tcp://localhost:61616
  webconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root
  webconsole.jmx.user=gvadmin
  webconsole.jmx.password=gvadmin
  webconsole.jms.user=gvadmin
  webconsole.jms.password=gvadmin

Example (Tutorial - Step 3 - Event Driven Push Notification -)

  • connectionfactory-test.xml
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
   <bean id="inboundConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
      <property name="brokerURL" value="tcp://localhost:61616" />
      <property name="userName" value="gvadmin" />
      <property name="password" value="gvadmin" />
   </bean>
   <service ref="inboundConnectionFactory" interface="javax.jms.ConnectionFactory">
      <service-properties>
         <entry key="name" value="inboundConnection" />
         <entry key="osgi.jndi.service.name" value="jms/inboundConnection" />
      </service-properties>
   </service>
   <bean id="outboundConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
      <property name="brokerURL" value="tcp://localhost:61616" />
      <property name="userName" value="gvadmin" />
      <property name="password" value="gvadmin" />
   </bean>
   <service ref="outboundConnectionFactory" interface="javax.jms.ConnectionFactory">
      <service-properties>
         <entry key="name" value="outboundConnection" />
         <entry key="osgi.jndi.service.name" value="jms/outboundConnection" />
      </service-properties>
   </service>
</blueprint>