public class MessagingClient extends Object implements javax.jms.MessageListener
Constructor and Description |
---|
MessagingClient(String clientId,
MessagingListener listener,
Properties connectionProperties)
Creates a messaging client
|
MessagingClient(String clientId,
MessagingListener listener,
Properties connectionProperties,
boolean durable)
Creates a messaging client
|
MessagingClient(String clientId,
MessagingListener listener,
Properties connectionProperties,
String messageSelector,
boolean durable)
Creates a messaging client
|
Modifier and Type | Method and Description |
---|---|
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.
|
public MessagingClient(String clientId, MessagingListener listener, Properties connectionProperties) throws MessagingException
public MessagingClient(String clientId, MessagingListener listener, Properties connectionProperties, boolean durable) throws MessagingException
public MessagingClient(String clientId, MessagingListener listener, Properties connectionProperties, String messageSelector, boolean durable) throws MessagingException
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.
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.
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 |
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.
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.
clientId
- identification value for this messaging clientlistener
- the listener which will be called when messages arriveconnectionProperties
- set of properties necessary to connect to JMS providermessageSelector
- a selection which determines the messages to deliverdurable
- determines if the underlying JMS subscribers are durableMessagingException
- if listener is null or required properties are not setpublic void start() throws MessagingException
MessagingException
public void start(boolean wait) throws MessagingException
wait
- Set to true to wait until the startup process
is complete before returning. Set to false to
allow for asynchronous startup.MessagingException
public boolean isConnected()
public void stop(boolean unsubscribe) throws MessagingException
unsubscribe
- MessagingException
public void onMessage(javax.jms.Message message)
onMessage
in interface javax.jms.MessageListener
Copyright © 2010-2013 MediaShelf. All Rights Reserved.