org.fcrepo.client.messaging
Class JmsMessagingClient

java.lang.Object
  extended by org.fcrepo.client.messaging.JmsMessagingClient
All Implemented Interfaces:
javax.jms.MessageListener, MessagingClient

public class JmsMessagingClient
extends Object
implements MessagingClient, javax.jms.MessageListener

A messaging client which listens for messages via JMS.

Author:
Bill Branan

Constructor Summary
JmsMessagingClient(String clientId, MessagingListener listener, Properties connectionProperties)
          Creates a messaging client
JmsMessagingClient(String clientId, MessagingListener listener, Properties connectionProperties, boolean durable)
          Creates a messaging client
JmsMessagingClient(String clientId, MessagingListener listener, Properties connectionProperties, String messageSelector, boolean durable)
          Creates a messaging client
 
Method Summary
 boolean isConnected()
           
 void onMessage(javax.jms.Message message)
          Receives messages and passes them to the MessagingListener along with the client id.
 void start()
          Starts the MessagingClient.
 void start(boolean wait)
          Starts the MessagingClient.
 void stop(boolean unsubscribe)
          Stops the MessagingClient, shuts down connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JmsMessagingClient

public JmsMessagingClient(String clientId,
                          MessagingListener listener,
                          Properties connectionProperties)
                   throws MessagingException
Creates a messaging client

Throws:
MessagingException
See Also:
JmsMessagingClient(String, MessagingListener, Properties, String, boolean)

JmsMessagingClient

public JmsMessagingClient(String clientId,
                          MessagingListener listener,
                          Properties connectionProperties,
                          boolean durable)
                   throws MessagingException
Creates a messaging client

Throws:
MessagingException
See Also:
JmsMessagingClient(String, MessagingListener, Properties, String, boolean)

JmsMessagingClient

public JmsMessagingClient(String clientId,
                          MessagingListener listener,
                          Properties connectionProperties,
                          String messageSelector,
                          boolean durable)
                   throws MessagingException
Creates a messaging client

Client ID

The clientId provides applications with the opportunity to create multiple messaging clients and track them based on this identifier. The clientId is used within the MessagingClient when creating a connection for durable subscriptions.

Message Listener

A listener, the onMessage() method of which will be called when a message arrives from the messaging provider. See the documentation for javax.jms.MessageListener for more information.

Connection Properties

All of the following properties must be included:

Property Description Example Value
java.naming.factory.initial (javax.naming.Context.INITIAL_CONTEXT_FACTORY) The JNDI initial context factory which will allow lookup of the other attributes org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url (javax.naming.Context.PROVIDER_URL) The JNDI provider URL tcp://localhost:61616
connection.factory.name (org.fcrepo.server.messaging.JMSManager.CONNECTION_FACTORY) The JNDI name of the connection factory needed to create a JMS Connection ConnectionFactory

One or more of the following properties must be specified:

Property Name Description Example Value
topic.X (where X = name of subscription topic, example - topic.fedoraManagement) A topic over which notification messages will be provided fedora.apim.*
queue.X (where X = name of subscription queue, example - queue.fedoraManagement) A queue through which notification messages will be provided fedora.apim.update

Durable

Specifies whether the topics included in the connection properties should have durable consumers. If set to true, all topics listeners will be constructed as durable subscribers. If set to false, all topic listeners will be constructed as non-durable subscribers. This does not affect queue listeners.

If there is a need for multiple topics, some of which are durable and some of which are not, then two MessagingClients should be created. One client would include topics needing durable subscribers and the other client would include topics not needing durable subscribers. A single MessageListener can be registered as the listener for both clients.

Message Selector

A JMS message selector allows a client to specify, by header field references and property references, the messages it is interested in. Only messages whose header and property values match the selector are delivered. See the javadoc for javax.jms.Message for more information about message selectors.

Parameters:
clientId - identification value for this messaging client
listener - the listener which will be called when messages arrive
connectionProperties - set of properties necessary to connect to JMS provider
messageSelector - a selection which determines the messages to deliver
durable - determines if the underlying JMS subscribers are durable
Throws:
MessagingException - if listener is null or required properties are not set
Method Detail

start

public void start()
           throws MessagingException
Starts the MessagingClient. This method must be called in order to receive messages. Waits for completed connection.

Specified by:
start in interface MessagingClient
Throws:
MessagingException

start

public void start(boolean wait)
           throws MessagingException
Starts the MessagingClient. This method must be called in order to receive messages.

Parameters:
wait - Set to true to wait until the startup process is complete before returning. Set to false to allow for asynchronous startup.
Throws:
MessagingException

isConnected

public boolean isConnected()

stop

public void stop(boolean unsubscribe)
          throws MessagingException
Stops the MessagingClient, shuts down connections. If the unsubscribe parameter is set to true, all durable subscriptions will be removed.

Specified by:
stop in interface MessagingClient
Parameters:
unsubscribe -
Throws:
MessagingException

onMessage

public void onMessage(javax.jms.Message message)
Receives messages and passes them to the MessagingListener along with the client id.

Specified by:
onMessage in interface javax.jms.MessageListener


Copyright © 2012 DuraSpace. All Rights Reserved.