This page is out of date and should not be used. Please refer to the Qpid JMS client books for up to date documentation.

Overview

Some example client code is provided to help you get started, using JNDI and JMS.

Downloading the source

The source code for the example client classes being provided is contained in the example package which can be found in:

https://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/example/

Building the Example source

You can build the example source using Maven by simply typing 'mvn' in the example directory.

Notes on the source package

Note that if you wish to build the example client code from within your IDE you will need to add the following jars contained in the Qpid binary release into your classpath:

qpid-client-<MILESTONE>.jar
qpid-common-<MILESTONE>.jar
geronimo-jms_1.1_spec-1.0.jar

At the time of writing MILESTONE is 'M4'.

NB: At runtime, you'll need to put all the jars in the client/lib dir into your classpath along with these jars.

The example packages classes currently use log4j for logging. You may instead wish to amend the logging and exception handling in line with your project standards.

Class Overview

Essentially we have provided example client classes to act as a publisher and a subscriber for handling messages using AMQ, as far as possible via JMS.

Contributions to the example classes are most welcome. Please send your classes to dev@qpid.apache.org.

Basic Classes

This section outlines the classes that you're likely to find most useful.

Publisher

This class contains the methods for publishing messages to a queue, using the example.properties file to populate the initial context and provide an example queue and topic.

FileMessageDispatcher

This class provides a simple wrapper around the publisher for dispathcing messages from file input, providing a really easy way to get started publishing messages. So, first create some files you'd like to use as payload for your test messages.

Then, you simply pass one argument to the FileMessageDispatcher class which is the path to your test message files. The dispatcher will then create a message from each file in the directory. You can opt to use the path to a single file as an alternative, in the same way.

Subscriber

This class acts as a consumer of messages sent to a queue.

Helper Classes/Exceptions

This section gives some additional information about helper classes in the example packages.

MessageFactory

This class constructs a message with payload from an input file provided and sets a property on the message using the filename.

MessageFactoryException

Exception thrown if a message cannot be created in the factory class.

Examples Using AMQP Immediate Delivery Feature

MonitorMessageDispatcher

This is an additional wrapper class to be run independently as the monitor which allows you to provide a heartbeat (set to 20 seconds intervals but can be changed at will) being consumed by the example subscriber. When we detect that the subscriber has stopped, you can opt to make a call to an application specific 'recovery process' by amending the exception handling in the main method when a UndeliveredMessageException is caught (marked by a TODO), or simply exit gracefully if appropriate.

UndeliveredMessageException

Thrown when the subscriber is not there to read the monitor traffic which has been marked as for immediate delivery.

MonitoredSubscriber

Subclass of the Subscriber which also reads messages from the monitor queue to let us know that it's consuming ok.

The shared package contains utility classes for file manipulation etc and constants for general use (to reduce the maintenance overhead) which could perhaps be replaced with config properties as appropriate.

  • No labels