The JMSSample application

The JMSSample application demonstrates how to send messages to and receive messages from Eclipse Amlen topics and queues.

It is implemented in three classes:
  • com.ibm.ima.samples.jms.JMSSample
  • com.ibm.ima.samples.jms.JMSSampleSend
  • com.ibm.ima.samples.jms.JMSSampleReceive

The JMSSample application can read administered objects from a JNDI repository or can configure them at run time.

You can run the JMSSample application in one of two ways. You can either run the application by specifying the Eclipse Amlen server URI or by using a JNDI repository.

  • To run the JMSSample application by specifying the Eclipse Amlen server URI, use the following command:

    java com.ibm.ima.samples.jms.JMSSample -s URI -a action -t topic | -q queue 

    where:

    -s URI
    The URI address of the Eclipse Amlen server. This address is in the format of tcp://<ipaddress>:<port>
    -a action
    For this option, action can be either publish or subscribe. The option of publish enables messages to be sent to a JMS topic or queue. The option of subscribe enables messages to be received from a JMS topic or queue.
    -t topic
    This option sets topic to be the name of the topic destination.
    -q queue
    This option sets queue to be the name of the queue destination.
  • To run the JMSSample application by using a JNDI repository, use the following command.

    java com.ibm.ima.samples.jms.JMSSample -jcf connection factory -jx JNDI context factory -jc JNDI provider -a action -t topic | -q queue

    where:

    -jcf connection factory
    This option sets connection factory to be the name of a JNDI object that represents a connection factory administered object.
    -jx JNDI context factory
    This option sets JNDI context factory to be the JNDI initial context factory. For example, com.sun.jndi.ldap.LdapCtxFactory or com.sun.jndi.fscontext.RefFSContextFactory.
    -jc JNDI provider [-jp provider password]
    This option sets JNDI provider to be the JNDI provider URL. For example, ldap://127.0.0.1/o=jndiTest or file:///c:/test/MyJndi and sets provider password to be the JNDI provider password.
    -a action
    For this option, action can be either publish or subscribe. The option of publish enables messages to be sent to a JMS topic or queue. The option of subscribe enables messages to be received from a JMS topic or queue.
    -t topic
    This option sets topic to be the name of the JNDI object that represents the destination.
    -q queue
    This option sets queue to be the name of the JNDI object that represents the destination.

The following command-line options are also available with either of these commands:

-ks keystore [-kspw keystore password]
where keystore is the keystore repository of security certificates and keystore password is the keystore password. This option is used for SSL encryption.
-ts truststore [-tspw truststore password]
where truststore is the truststore repository and truststore password is the truststore password. This option is used to establish trust relationships for SSL connections.
-jn name prefix
where name prefix is a name prefix. This option can be used for creating and looking up JNDI objects.
-i clientId
where clientId is the client identity. This option specifies the client ID that is associated with the connection to the Eclipse Amlen server. If a client ID is not specified, then one is automatically generated by the JMS client API.
-m message
where message is a string that represents the message to be sent. The default is Sample Message.
-n count
where count is the number of times the specified message is to be sent or received. The default number of messages that are sent or received is 1.
-o logfile name
The log defaults to stdout.
-u userId -p password
where userId is the user name and password is the user password. These options are used for authentication with Eclipse Amlen
If userId is specified without password then the user is prompted for the password.
-w rate
where rate is the rate at which messages are sent in units of messages/second.
-x timeout
where timeout is the timeout in seconds for each synchronous call to receive a message.
-b
This option enables a topic subscription to be made durable. Topic subscriptions are non-durable by default.
-d
This option enables DisableAck to be set in a connection factory.
-e
This option enables the deletion of a durable subscription at client disconnect. By default, durable subscriptions are preserved after disconnect.
-h
This option enables output of the usage statement.
-r
This option enables persistent delivery mode. The default delivery mode is non-persistent.
-v
This option enables the provision of verbose output.

Examples

The following example uses the JMSSample application with the Eclipse Amlen URI to send messages to a queue.

java com.ibm.ima.samples.jms.JMSSample -s tcp://10.10.1.2:16102 -a publish -q myQueue

The following example uses the JMSSample application with a JNDI repository to send messages to a topic.

java com.ibm.ima.samples.jms.JMSSample -jcf myConnFactory -a pubish -t myTopic 
-jx com.sun.jndi.fscontext.RefFSContextFactory -jc file:///c:/test/MyJndi