Class 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 Detail

      • session

        protected javax.jms.Session session
      • consumer

        protected javax.jms.MessageConsumer consumer
      • topic

        protected javax.jms.Topic topic
      • messageSelector

        protected String messageSelector
    • Constructor Detail

      • JmsReceiver

        public JmsReceiver()
    • Method Detail

      • getName

        public String getName()
        Returns the name for this Receiver. (JMS)
        Specified by:
        getName in interface Receiver
        Returns:
        the name of this Receiver. (JMS)
      • 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 class AbstractReceiver
      • 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 of messageSelector.
        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 interface Receiver
        Overrides:
        setNjams in class AbstractReceiver
        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.
        Specified by:
        stop in interface Receiver
      • onMessage

        public void onMessage​(javax.jms.Message msg)
        This method is the MessageListener implementation. It receives JMS Messages automatically.
        Specified by:
        onMessage in interface javax.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 interface javax.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 interface ClasspathValidator
        Returns:
        an array of Strings of fully qualified class names.