The JMS section of the user guide shows how to create connection factories and manipulate JMS using the Apache Karaf provided jms:*
commands and related.
This example shows how to use the JMS Karaf feature from a developer perspective. It directly uses a JMS ConnectionFactory
service in code that you can implement to interact with JMS.
ConnectionFactory
service.The build uses Apache Maven. Simply use:
mvn clean install
On a running Karaf instance, register the features repository:
karaf@root()> feature:repo-add mvn:org.apache.karaf.examples/karaf-jms-example-features/LATEST/xml
Then, you can install the karaf-jms-example-activemq
feature:
karaf@root()> feature:install karaf-jms-example-activemq
It will install an Apache ActiveMQ in your running Karaf instance, providing a complete embedded ActiveMQ broker, listening on port 61616 by default.
Then, you can install the karaf-jms-example-connectionfactory
feature:
karaf@root()> feature:install karaf-jms-example-connectionfactory
This feature is the “client” part: it uses the Karaf jms
feature and related (like pax-jms
) to create a ConnectionFactory
service to the embedded ActiveMQ instance.
Finally, the karaf-jms-example-command
feature installs a shell commands bundle:
karaf@root()> feature:install karaf-jms-example-command
The karaf-jms-example-command
feature installed a bundle providing example:*
commands.
You can use the example:send
command to send a message to the ActiveMQ broker:
karaf@root()> example:send TEST FOO
where TEST
is the JMS queue name and FOO
the JMS message payload.
Then, you can consume the latest message in a queue using example:consume
:
karaf@root()> example:consume TEST