Class JmsReceiver
- java.lang.Object
-
- com.im.njams.sdk.communication.AbstractReceiver
-
- com.im.njams.sdk.communication.jms.JmsReceiver
-
- All Implemented Interfaces:
Receiver
,ClasspathValidator
,javax.jms.ExceptionListener
,javax.jms.MessageListener
- Direct Known Subclasses:
SharedJmsReceiver
public class JmsReceiver extends AbstractReceiver implements javax.jms.MessageListener, javax.jms.ExceptionListener, ClasspathValidator
JMS implementation for a Receiver.- Version:
- 4.0.5
- Author:
- pnientiedt, krautenberg@integrationmatters.ocm
-
-
Field Summary
Fields Modifier and Type Field Description protected javax.jms.MessageConsumer
consumer
protected String
messageSelector
protected javax.jms.Session
session
protected javax.jms.Topic
topic
-
Fields inherited from class com.im.njams.sdk.communication.AbstractReceiver
connectionStatus, njams, RECONNECT_INTERVAL
-
-
Constructor Summary
Constructors Constructor Description JmsReceiver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connect()
This method is called when the receiver has to connect.protected javax.jms.MessageConsumer
createConsumer(javax.jms.Session sess, javax.jms.Topic topic)
This method creates a MessageConsumer out of the provided session for the Topic topic, and listens only to the messages ofmessageSelector
.protected String
createMessageSelector()
This method creates a String that is used as a message selector.protected com.faizsiegeln.njams.messageformat.v4.command.Instruction
getInstruction(javax.jms.Message message)
This method tries to extract the Instruction out of the provided message.String
getName()
Returns the name for this Receiver.void
init(Properties props)
Initializes this Receiver via the given Properties.String[]
librariesToCheck()
This method gets all libraries that need to be checked.void
onException(javax.jms.JMSException exception)
This method logs all JMS Exceptions and tries to reconnect the connection.void
onMessage(javax.jms.Message msg)
This method is the MessageListener implementation.protected void
reply(javax.jms.Message message, com.faizsiegeln.njams.messageformat.v4.command.Instruction instruction, String clientId)
This method tries to reply the instructions response back to the sender.void
setNjams(Njams njams)
This constructor sets the njams instance for getting the instruction listeners.void
stop()
This method stops the Jms Receiver by closing all its resources, if its status is CONNECTED.-
Methods inherited from class com.im.njams.sdk.communication.AbstractReceiver
extendRequest, isConnected, isConnecting, isDisconnected, onException, onInstruction, reconnect, start, suppressGetRequestHandlerInstruction
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.im.njams.sdk.utils.ClasspathValidator
validate
-
-
-
-
Field Detail
-
session
protected javax.jms.Session session
-
consumer
protected javax.jms.MessageConsumer consumer
-
topic
protected javax.jms.Topic topic
-
messageSelector
protected String messageSelector
-
-
Method Detail
-
getName
public String getName()
Returns the name for this Receiver. (JMS)
-
init
public void init(Properties props)
Initializes this Receiver via the given Properties.Valid properties are:
For more look in the github FAQ of this project.
-
createMessageSelector
protected String createMessageSelector()
This method creates a String that is used as a message selector.- Returns:
- the message selector String.
-
connect
public void connect()
This method is called when the receiver has to connect. It can't be started if init(..) hasn't been called beforehand.- Specified by:
connect
in classAbstractReceiver
-
createConsumer
protected javax.jms.MessageConsumer createConsumer(javax.jms.Session sess, javax.jms.Topic topic) throws javax.jms.JMSException
This method creates a MessageConsumer out of the provided session for the Topic topic, and listens only to the messages ofmessageSelector
.- Parameters:
sess
- the session that creates the MessageConsumer to the given topic, that listens to the messages that match the messageSelector.topic
- the topic to listen to- Returns:
- the MessageConsumer if it can be created. It listens on the given
topic for messages that match the
messageSelector
. If a message is found, this.onMessage(Message msg) is invoked. - Throws:
javax.jms.JMSException
- is thrown if the MessageConsumer can' be created.
-
setNjams
public void setNjams(Njams njams)
Description copied from class:AbstractReceiver
This constructor sets the njams instance for getting the instruction listeners.- Specified by:
setNjams
in interfaceReceiver
- Overrides:
setNjams
in classAbstractReceiver
- Parameters:
njams
- the instance that holds the instructionListeners.
-
stop
public void stop()
This method stops the Jms Receiver by closing all its resources, if its status is CONNECTED.
-
onMessage
public void onMessage(javax.jms.Message msg)
This method is the MessageListener implementation. It receives JMS Messages automatically.- Specified by:
onMessage
in interfacejavax.jms.MessageListener
- Parameters:
msg
- the newly arrived JMS message.
-
getInstruction
protected com.faizsiegeln.njams.messageformat.v4.command.Instruction getInstruction(javax.jms.Message message)
This method tries to extract the Instruction out of the provided message. It maps the Json string to an Instruction object.- Parameters:
message
- the Json Message- Returns:
- the Instruction object that was extracted or null, if no valid instruction was found or it could be parsed to an instruction object.
-
reply
protected void reply(javax.jms.Message message, com.faizsiegeln.njams.messageformat.v4.command.Instruction instruction, String clientId)
This method tries to reply the instructions response back to the sender. Send a message to the sender that is mentioned in the message. If a JmsCorrelationId is set in the message, it will be forwarded as well.- Parameters:
message
- the destination where the response will be sent to and the jmsCorrelationId are safed in here.instruction
- the instruction that holds the response.clientId
-
-
onException
public void onException(javax.jms.JMSException exception)
This method logs all JMS Exceptions and tries to reconnect the connection.- Specified by:
onException
in interfacejavax.jms.ExceptionListener
- Parameters:
exception
- The jmsException to be logged.
-
librariesToCheck
public String[] librariesToCheck()
This method gets all libraries that need to be checked.- Specified by:
librariesToCheck
in interfaceClasspathValidator
- Returns:
- an array of Strings of fully qualified class names.
-
-