Skip to content
QiTASC.com / intaQt Built-ins /
JMS Built-ins
/ .. /
JMS Built-ins





JMS Built-ins

JMS Built-ins provide functionality to the Java Message Service (JMS) API, which is a Java Message Oriented Middleware (MOM) API for sending messages between two or more clients. The Built-ins are used to handle the Producer-consumer problem.

Configuration

Syntax

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Jms {
  <name Identifier> {
    jarUrl                  = <String>
    initialContextFactory   = <String>
    providerUrl             = <String>
    username                = <String>
    password                = <String>
    sessionAcknowledgeMode  = <Number>
    isSessionTransacted     = <Boolean>
  }
  ...
}

Parameters

  • jarUrl - Points to the JMS implementation library (a .jar file)

  • initialContextFactory - The class path to the implementation of ContextFactory

  • providerUrl - The url to the active JMS provider

  • username and password (optional) - Used to access a protected database

  • sessionAcknowledgeMode (optional) - The acknowledge mode of the sessions

    • 0 - session is transacted
    • 1 - (default) - auto-acknowledge
    • 2 - client acknowledge
    • 3 - dups ok acknowledge
  • isSessionTransacted (optional) -

    • true if session is transacted
    • false (default) otherwise

Example

1
2
3
4
5
6
7
Jms = {
    "local" {
        jarUrl : "file:/Users/QiTASC/Downloads/activemq-all-5.8.0.jar"
        initialContextFactory : "org.apache.activemq.jndi.ActiveMQInitialContextFactory"
        providerUrl : "tcp://localhost:61616"
    }
}

The above example uses an absolute path, but the path can also be relative to intaQt working directory. The working directory is the folder where intaQt's executable is located (<User-defined Path>/intaqt/bin/).

Creating Sessions

The createSession function must be called to establish a connection and provide a session using that connection. The session provides the ability to create consumers, producers and messages.

The cleanUp function can be used to clean all resources before test execution is finished. It will also be called automatically at the end of each test execution.

Syntax

1
2
3
4
5
6
7
<session Session> := Jms.createSession(<configurationName String>)

...
//JMS commands
...

Jms.cleanUp()

Parameter

  • configurationName - The JMS name, as defined in the configuration

Example

1
2
3
4
5
session := Jms.createSession("local")
...
//JMS commands
...
Jms.cleanUp()

Session Commands

A session object is a single-threaded context for producing and consuming messages.

A session serves several purposes:

  • It is a factory for its message producers and consumers.

  • It supplies provider-optimized message factories.

  • It is a factory for TemporaryTopics and TemporaryQueues.

  • It provides a way to create Queue or Topic objects for those clients that need to dynamically manipulate provider-specific destination names.

  • It supports a single series of transactions that combine work spanning its producers and consumers into atomic units.

  • It defines a serial order for the messages it consumes and the messages it produces.

  • It retains messages it consumes until they have been acknowledged.

  • It is a factory for QueueBrowsers.

A session can create and service multiple message producers and consumers. All functions described in Session JavaEE7 are accessible from JMS Built-ins.

Producers and Consumers

Message Producer Objects

A client uses a MessageProducer object to send messages to a destination. A MessageProducer object is created by passing a Destination object to a message-producer creation method supplied by a session. All functions described in MessageProducer JavaEE7 are accessible from JMS Built-ins.

Message Consumer Objects

A client uses a MessageConsumer object to receive messages from a destination. A MessageConsumer object is created by passing a Destination object to a message-consumer creation method supplied by a session. All functions described in MessageConsumer JavaEE7 except getMessageListener() and setMessageListener() are accessible from JMS Built-ins.

Messages

The Message interface is the root interface of all JMS messages. It defines the message header and the acknowledge method used for all messages, which can be found under Message JavaEE7.

Additional Messages Methods

Syntax

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  <isTextMessage Boolean> := message.isTextMessage()
  <textMessage TextMessage> :=  message.asTextMessage()

  <isObjectMessage Boolean> := message.isObjectMessage()
  <objectMessage ObjectMessage> := message.asObjectMessage()

  <isMapMessage Boolean> := message.isMapMessage()
  <mapMessage MapMessage> := message.asMapMessage()

  <isBytesMessage Boolean> := message.isBytesMessage()
  <bytesMessage BytesMessage> := message.asBytesMessage()

  <isStreamMessage Boolean> := message.isStreamMessage()
  <streamMessage StreamMessage> := message.asStreamMessage()

Parameters

  • isTextMessage -

  • textMessage - The text message

  • isObjectMessage -

  • objectMessage - The object message

  • isMapMessage -

  • mapMessage - The map message

  • isBytesMessage -

  • bytesMessage - The bytes message

  • isStreamMessage -

  • streamMessage - The stream message

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
stepdef "produce a message {}" / text /
    session := Jms.createSession("local")
    queue := session.createQueue("SOME.Q")
    producer := session.createProducer(queue)
    message := session.createTextMessage(text)
    producer.send(message)
end

stepdef "receive a message"
    session := Jms.createSession("local")
    queue := session.createQueue("SOME.Q")
    consumer := session.createConsumer(queue)
    message := consumer.receive()
    if message.isTextMessage() then
      textMessage := message.asTextMessage()
      println(textMessage.getText())
    end
end

Callback Reactor Functions

Reactor functions enable the execution of code blocks in response to specific types of JMS messages received by a JMS consumer. The function setMessageReactor applies a Reactor function to an existing consumer. clearMessageReactor removes the attached Reactor function from a message consumer.

Description

Syntax

1
2
3
<messageConsumer MessageConsumer>.setMessageReactor(<reactorFuncRef ReactorFunction(Message)>)

<messageConsumer MessageConsumer>.clearMessageReactor()

Parameters

  • messageConsumer - Consumer target of the Reactor function

  • reactorFuncRef - A defined Reactor function which it refers to

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
stepdef "assign reactor to JMS"
    session := Jms.createSession("local")
    queue := session.createQueue("SOME.Q")
    consumer := session.createConsumer(queue)
    consumer.setMessageReactor(REACTOR::consumeMessage)
end

reactor REACTOR
    func consumeMessage(message)
        if message.isTextMessage() then
            textMessage := message.asTextMessage()
            session := Jms.createSession("local")
            queue := session.createQueue("ANOTHER.Q")
            producer := session.createProducer(queue)
            message := session.createTextMessage("Reply to: " + textMessage.getText())
            producer.send(message)
        end
    end
end

In this example a reactor function named REACTOR is used to automatically generate a response message sent by the defined producer and received by the consumer.