Package examples.jms.queue

 

Establish a connection to a JMS queue, and send, browse, and receive messages from that queue.

 

Class Summary

QueueBrowse * Establish a connection to a JMS queue and browse, but not dequeue, the queued messages.
QueueReceive * Establish a connection to and receive messages from a JMS queue.
QueueReceiveInTx * Establish a connection to and receive messages from a JMS queue in a client-demarcated transaction.
QueueSend * Establish a connection and send messages to the JMS queue.

 

 

Package examples.jms.queue Description

Establish a connection to a JMS queue, and send, browse, and receive messages from that queue. The classes in this package operate on the same JMS queue. Run the classes together to observe messages being sent and received, and to browse the queue for messages.

 

Build the Example

  1. Set up your environment.

  2. To compile the example...

    cd $SAMPLES_HOME/server/examples/src/examples/jms/queue
    ...and execute...

    javac -d $CLIENT_CLASSES *.java

    ...and then...

    cp -r * $SAMPLES_HOME/server/examples/build/clientclasses/examples/jms/queue

    Or, you can execute the build script provided for this example.

    ant

    Here is the build.xml

  3. Start the examples WebLogic Server.

  4. Bring up the Administration Console in your browser.

  5. Click through:

    Services | JMS node | Connection Factories node

    The preconfigured connection factory instances associated with the examplesServer are listed.

  6. Select the exampleQueue connection factory instance. A dialog displays in the right pane showing the tabs associated with this instance.

  7. Click the Transactions tab to display the transaction options.

  8. Select the XA Connection Factory Enabled check box.

  9. Click Apply to save the change.

  10. Choose the server target for the exampleQueue connection factory as follows:

    1. Click the Target and Deploy tab.

    2. The WebLogic Server instances in the examples domain are listed in the Independent Servers box. If necessary, select the examplesServer check box.

    3. Click Apply to save the change.

    Note that normally, you would also have to choose one or more target servers for the JMS server associated with the queue. For your convenience, the examplesJMSServer server has been preconfigured to include the examplesServer as a chosen target.

  11. With the examples WebLogic Server running, set up a new development shell and run the QueueSend client...

    $ java examples.jms.queue.QueueSend t3://localhost:7001
    Enter message ("quit" to quit): This is a test
    Enter message ("quit" to quit): quit
    

  12. To browse messages in the queue, set up a new development shell and run the QueueBrowse client...

    $ java examples.jms.queue.QueueBrowse t3://localhost:7001
    Queued JMS Messages:
    Message ID ID:P<514047.1112281702411.0> delivered Thu Mar 31 09:08:22 CST 2005 to exampleQueue
            Expires        never
            Priority       4
            Mode           PERSISTENT
            Correlation ID null
            Reply to       null
            Message type   null
            TextMessage    "This is a test"
    

  13. To receive messages from the queue, set up a new development shell and run the QueueReceive client...

    $ java examples.jms.queue.QueueReceive t3://hostname:port

  14. To receive messages from the queue in a client-demarcated transaction, set up a new development shell and run the QueueReceiveInTx client with the following command:

    $ java examples.jms.queue.QueueReceiveInTx t3://hostname:port

    The program displays messages as they are received from the queue.

    Note that the queue receive transaction will timeout with a rollback exception if the amount of time required to send and receive the messages and quit the session somehow exceeds the default 30-minute timeout period.

  15. To end the program, send a quit message from the shell running the QueueSend client.