Class JmsClient


  • public class JmsClient
    extends Object
    A JMS client class
    • Method Detail

      • setDefaultStaticInitialContext

        public static void setDefaultStaticInitialContext​(InitialContext context)
      • setDefaultStaticConnectionFactoryName

        public static void setDefaultStaticConnectionFactoryName​(String factoryName)
      • setBasicAuthentication

        public void setBasicAuthentication​(String username,
                                           String password)
        Use basic authentication
        Parameters:
        username - the user name
        password - the user password
      • setKeepAlive

        public void setKeepAlive​(boolean isKeepAlive)
        This option must be used in cases where we must not close the session after executing some of the available public methods. For example, if you subscribe to listen for topic messages and then send a message, the last step will close the session which kills the listening process. In such case the session must not be closed.
        Parameters:
        isKeepAlive -
      • shutdown

        public void shutdown()
        Shutdown the JMS client. This closes all connections and sessions.
      • sendTextMessage

        public void sendTextMessage​(String jndiName,
                                    String textMessage,
                                    Map<String,​?> properties)
        Send a text message
        Parameters:
        jndiName -
        textMessage - message content
        properties - message properties or null if none
      • sendTextMessage

        public void sendTextMessage​(javax.jms.Destination destination,
                                    String textMessage,
                                    Map<String,​?> properties)
        Send a text message
        Parameters:
        destination - message destination
        textMessage - message content
        properties - message properties or null if none
      • sendTextMessageToQueue

        public void sendTextMessageToQueue​(String queueName,
                                           String textMessage,
                                           Map<String,​?> properties)
        Send a text message to a queue
        Parameters:
        queueName - queue name
        textMessage - message content
        properties - message properties or null if none
      • sendTextMessageToTopic

        public void sendTextMessageToTopic​(String topicName,
                                           String textMessage,
                                           Map<String,​?> properties)
        Send a text message to a topic
        Parameters:
        topicName - topic name
        textMessage - message content
        properties - message properties or null if none
      • sendBinaryMessageToQueue

        public void sendBinaryMessageToQueue​(String queueName,
                                             byte[] bytes,
                                             Map<String,​?> properties)
        Send a binary message to a queue
        Parameters:
        queueName - queue name
        bytes - message content
        properties - message properties or null if none
      • receiveMessage

        public javax.jms.Message receiveMessage​(String jndiName)
        Receive a message
        Parameters:
        jndiName -
        Returns:
        the received message
      • receiveMessage

        public javax.jms.Message receiveMessage​(String jndiName,
                                                long timeout)
        Receive a message
        Parameters:
        jndiName -
        timeout - timeout period in milliseconds
        Returns:
        the received message
      • receiveMessage

        public javax.jms.Message receiveMessage​(javax.jms.Destination destination)
        Receive a message
        Parameters:
        destination - remote destination
        Returns:
        the received message
      • receiveMessage

        public javax.jms.Message receiveMessage​(javax.jms.Destination destination,
                                                long timeout)
        Receive a message
        Parameters:
        destination - remote destination
        timeout - timeout period in milliseconds
        Returns:
        the received message
      • receiveMessageFromQueue

        public javax.jms.Message receiveMessageFromQueue​(String queueName)
        Receive a message from queue. Waits indefinitely.
        Parameters:
        queueName - queue name
        Returns:
        the received message
      • receiveMessageFromQueue

        public javax.jms.Message receiveMessageFromQueue​(String queueName,
                                                         long timeout)
        Receive a message from queue for a period of time
        Parameters:
        queueName - queue name
        timeout - timeout period in milliseconds
        Returns:
        the received message
      • receiveMessageFromTopic

        public javax.jms.Message receiveMessageFromTopic​(String topicName)
        Receive a message from a topic. Waits indefinitely.
        Parameters:
        topicName - topic name
        Returns:
        the received message
      • receiveMessageFromTopic

        public javax.jms.Message receiveMessageFromTopic​(String topicName,
                                                         long timeout)
        Receive a message from topic for a period of time
        Parameters:
        topicName - topic name
        timeout - timeout period in milliseconds
        Returns:
        the received message
      • cleanupMessagesQueue

        public void cleanupMessagesQueue​(String queueName)
                                  throws javax.jms.JMSException
        Read all messages from a queue
        Parameters:
        queueName - queue name
        Throws:
        javax.jms.JMSException
      • createTopic

        public void createTopic​(String topicName)
        Create a topic
        Parameters:
        topicName - the topic name
      • startListeningToTopic

        public void startListeningToTopic​(String topicName)
        Start listening for messages on topic
        Parameters:
        topicName - the topic name
      • stopListeningToTopic

        public void stopListeningToTopic​(String topicName)
        Stop listening for messages on topic
        Parameters:
        topicName - the topic name
      • getCollectedTopicMessages

        public javax.jms.Message[] getCollectedTopicMessages​(String topicName)
        Get the current list of collected messages on this topic.
        Parameters:
        topicName - the topic name
        Returns:
        the messages.