Skip Headers

Oracle® Streams Advanced Queuing User's Guide and Reference
Release 10.1

Part Number B10785-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

13 Oracle Streams AQ JMS Operational Interface: Point-to-Point

This chapter describes the Oracle Streams Advanced Queuing (AQ) Java Message Service (JMS) operational interface for basic point-to-point operations.

This chapter contains these topics:

Creating a Connection

A JMS Connection supports both point-to-point and publish/subscribe operations. The methods in this section are new and support JMS version 1.1 specifications.

This section contains these topics:

Creating a Connection with Username/Password


Purpose

Creates a connection with username and password.


Syntax
public javax.jms.Connection createConnection(
             java.lang.String username,
             java.lang.String password)
      throws JMSException

Parameters
username

Name of the user connecting to the database for queuing.

password

Password for creating the connection to the server.


Usage Notes

This connection supports both point-to-point and publish/subscribe operations.

Creating a Connection with Default Connection Factory Parameters


Purpose

Creates a connection with default connection factory parameters.


Syntax
public javax.jms.Connection createConnection()
      throws JMSException

Usage Notes

The ConnectionFactory properties must contain a default username and password; otherwise, this method throws a JMSException. This connection supports both point-to-point and publish/subscribe operations.

Creating a Queue Connection

This section contains these topics:

Creating a Queue Connection with Username/Password


Purpose

Creates a queue connection with username and password.


Syntax
public javax.jms.QueueConnection createQueueConnection(
             java.lang.String username,
             java.lang.String password)
      throws JMSException

Parameters
username

Name of the user connecting to the database for queuing.

password

Password for creating the connection to the server.


Example
QueueConnectionFactory qc_fact = AQjmsFactory.getQueueConnectionFactory("sun123", "oratest", 5521, "thin");
/* Create a queue connection using a username/password */
QueueConnection qc_conn = qc_fact.createQueueConnection("jmsuser", "jmsuser");

Creating a Queue Connection with an Open JDBC Connection


Purpose

Creates a queue connection with an open JDBC connection.


Syntax
public static javax.jms.QueueConnection createQueueConnection(java.sql.Connection jdbc_connection)
               throws JMSException

Parameters
jdbc_connection

Valid open connection to the database.


Usage Notes

This is a static method.


Example 1

This method can be used if the user wants to use an existing JDBC connection (say from a connection pool) for JMS operations. In this case JMS does not open a new connection, but instead use the supplied JDBC connection to create the JMS QueueConnection object.

Connection db_conn;     /* previously opened JDBC connection */
QueueConnection qc_conn = AQjmsQueueConnectionFactory.createQueueConnection(
           db_conn);

Example 2

This method is the only way to create a JMS QueueConnection when using JMS from java stored procedures inside the database (JDBC Server driver)

OracleDriver ora = new OracleDriver();
QueueConnection qc_conn = AQjmsQueueConnectionFactory.createQueueConnection(ora.defaultConnection());

Creating a Queue Connection with Default Connection Factory Parameters


Purpose

Creates a queue connection with default connection factory parameters.


Syntax
public javax.jms.QueueConnection createQueueConnection()
      throws JMSException

Usage Notes

The QueueConnectionFactory properties must contain a default username and password: otherwise, this method throws a JMSException.

Creating a Queue Connection with an Open OracleOCIConnection Pool


Purpose

Creates a queue connection with an open OracleOCIConnectionPool.


Syntax
public static javax.jms.QueueConnection createQueueConnection(
          oracle.jdbc.pool.OracleOCIConnectionPool cpool)
   throws JMSException

Parameters
cpool

Valid open connection OCI connection pool to the database.


Usage notes

This is a static method.


Example

This method can be used if the user wants to use an existing OracleOCIConnectionPool instance for JMS operations. In this case JMS does not open an new OracleOCIConnectionPool instance, but instead uses the supplied OracleOCIConnectionPool instance to create the JMS QueueConnection object.

OracleOCIConnectionPool cpool; /* previously created OracleOCIConnectionPool */
QueueConnection qc_conn = AQjmsQueueConnectionFactory.createQueueConnection(cpool);

Creating a Session


Purpose

Creates a Session, which supports both point-to-point and publish/subscribe operations.


Syntax
public javax.jms.Session createSession(boolean transacted,
                                                 int ack_mode)
                                          throws JMSException

Parameters
transacted

If set to true, then the session is transactional.

ack_mode

Indicates whether the consumer or the client will acknowledge any messages it receives. It is ignored if the session is transactional. Legal values are Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, and Session.DUPS_OK_ACKNOWLEDGE.


Usage Notes

This method is new and supports JMS version 1.1 specifications. Transactional and nontransactional sessions are supported.

Creating a QueueSession


Purpose

Creates a QueueSession.


Syntax
public javax.jms.QueueSession createQueueSession(boolean transacted,
                                                 int ack_mode)
                                          throws JMSException

Parameters
transacted

If set to true, then the session is transactional.

ack_mode

Indicates whether the consumer or the client will acknowledge any messages it receives. It is ignored if the session is transactional. Legal values are Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, and Session.DUPS_OK_ACKNOWLEDGE.


Usage Notes

Transactional and nontransactional sessions are supported.


Example

For a transactional session:

QueueConnection qc_conn;
QueueSession  q_sess = qc_conn.createQueueSession(true, 0);

Creating a QueueSender


Purpose

Creates a QueueSender.


Syntax
public javax.jms.QueueSender createSender(javax.jms.Queue queue)
                                   throws JMSException

Usage Notes

If a sender is created without a default queue, then the destination queue must be specified on every send operation.

Sending Messages

This section contains these topics:

Sending Messages Using a QueueSender with Default Send Options


Purpose

Sends a message using a QueueSender with default send options.


Syntax
public void send(javax.jms.Queue queue,
                 javax.jms.Message message)
          throws JMSException

Parameters
queue

Queue to send this message to.

message

Message to send.


Usage Notes

If the QueueSender has been created with a default queue, then the queue parameter may not necessarily be supplied in the send call. If a queue is specified in the send operation, then this value overrides the default queue of the QueueSender.

If the QueueSender has been created without a default queue, then the queue parameter must be specified in every send call.

This send operation uses default values for message priority (1) and timeToLive (infinite).


Example 1
/* Create a sender to send messages to any queue */
QueueSession  jms_sess;
QueueSender  sender1;
TextMessage  message;
sender1 = jms_sess.createSender(null); 
sender1.send(queue, message);

Example 2
/* Create a sender to send messages to a specific queue */
QueueSession jms_sess;
QueueSender sender2;
Queue   billed_orders_que;
TextMessage  message;
sender2 = jms_sess.createSender(billed_orders_que);
sender2.send(queue, message);

Sending Messages Using a QueueSender by Specifying Send Options


Purpose

Sends messages using a QueueSender by specifying send options.


Syntax
public void send(javax.jms.Queue queue,
                 javax.jms.Message message,
                 int deliveryMode,
                 int priority,
                 long timeToLive)
          throws JMSException

Parameters
queue

Queue to send this message to.

message

Message to send.

deliveryMode

Delivery mode to use.

priority

Priority for this message.

timeToLive

Message lifetime (in milliseconds).


Usage Notes

If the QueueSender has been created with a default queue, then the queue parameter may not necessarily be supplied in the send call. If a queue is specified in the send operation, then this value overrides the default queue of the QueueSender.

If the QueueSender has been created without a default queue, then the queue parameter must be specified in every send call.


Example 1
/* Create a sender to send messages to any queue */ 
/* Send a message to new_orders_que with priority 2 and timetoLive 100000 
   milliseconds */
QueueSession  jms_sess;
QueueSender  sender1;
TextMessage mesg;
Queue   new_orders_que
sender1 = jms_sess.createSender(null); 
sender1.send(new_orders_que, mesg, DeliveryMode.PERSISTENT, 2, 100000);

Example 2
/* Create a sender to send messages to a specific queue */ 
/* Send a message with priority 1 and timetoLive 400000 milliseconds */
QueueSession jms_sess;
QueueSender sender2;
Queue   billed_orders_que;
TextMessage mesg;
sender2 = jms_sess.createSender(billed_orders_que);
sender2.send(mesg, DeliveryMode.PERSISTENT, 1, 400000);

Creating a QueueBrowser

You can create a QueueBrowser for:

Queues with Text, Stream, Objects, Bytes or Map Messages


Purpose

Creates a QueueBrowser for queues with text, stream, objects, bytes or map messages.


Syntax
public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue,
                                            java.lang.String messageSelector)
                                     throws JMSException

Parameters
queue

Queue to access.

messageSelector

Only messages with properties matching the message selector expression are delivered.


Usage Notes

To retrieve messages that match certain criteria, the selector for the QueueBrowser can be any expression that has a combination of one or more of the following:

  • JMSMessageID = 'ID:23452345' to retrieve messages that have a specified message ID

  • JMS message header fields or properties:

    JMSPriority < 3 AND JMSCorrelationID = 'Fiction'
    
    
  • User-defined message properties:

    color IN ('RED', BLUE', 'GREEN') AND price < 30000 
    
    

All message IDs must be prefixed with "ID:"

Use methods in java.util.Enumeration to go through list of messages.


Example 1
/* Create a browser without a selector */
QueueSession    jms_session;
QueueBrowser    browser;
Queue           queue;
browser = jms_session.createBrowser(queue);

Example 2
/* Create a browser for queues with a specified selector */
QueueSession    jms_session;
QueueBrowser    browser;
Queue           queue;
/* create a Browser to look at messages with correlationID = RUSH  */
browser = jms_session.createBrowser(queue, "JMSCorrelationID = 'RUSH'");

Queues with Text, Stream, Objects, Bytes, Map Messages, Locking Messages


Purpose

Creates a QueueBrowser for queues with text, stream, objects, bytes or map messages, locking messages while browsing.


Syntax
public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue,
                                            java.lang.String messageSelector,
                                            boolean locked)
                                     throws JMSException

Parameters
queue

Queue to access.

messageSelector

Only messages with properties matching the message selector expression are delivered.

locked

If set to true, then messages are locked as they are browsed (similar to a SELECT for UPDATE).


Usage Notes

Locked messages cannot be removed by other consumers until the browsing session ends the transaction.


Example 1
/* Create a browser without a selector */
QueueSession    jms_session;
QueueBrowser    browser;
Queue           queue;
browser = jms_session.createBrowser(queue, null, true);

Example 2
/* Create a browser for queues with a specified selector */
QueueSession    jms_session;
QueueBrowser    browser;
Queue           queue;
/* create a Browser to look at messages with 
correlationID = RUSH in lock mode */
browser = jms_session.createBrowser(queue, "JMSCorrelationID = 'RUSH'", true);

Queues of Oracle Object Type Messages


Purpose

Creates a QueueBrowser for queues of Oracle object type messages.


Syntax
public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue, 
                                            java.lang.String messageSelector,
                                            java.lang.Object payload_factory)
                                     throws JMSException

Parameters
queue

Queue to access.

messageSelector

Only messages with properties matching the message selector expression are delivered.

payload_factory

CustomDatumFactory or ORADataFactory for the java class that maps to the Oracle ADT.


Note:

CustomDatum support will be deprecated in a future release. Use ORADataFactory payload factories instead.


Usage Notes

For queues containing AdtMessages the selector for the QueueBrowser can be a SQL expression on the message payload contents or messageID or priority or correlationID.

  • Selector on message ID - to retrieve messages that have a specific messageID

    msgid = '23434556566767676' 
    
    

    Note: in this case message IDs must NOT be prefixed with ID:

  • Selector on priority or correlation is specified as follows

    priority < 3 AND corrid = 'Fiction'
    
    
  • Selector on message payload is specified as follows

    tab.user_data.color = 'GREEN' AND tab.user_data.price < 30000
    

Example

The CustomDatum factory for a particular java class that maps to the SQL object payload can be obtained using the getFactory static method.

Assume the queue test_queue has payload of type SCOTT.EMPLOYEE and the java class that is generated by Jpublisher for this Oracle object type is called Employee. The Employee class implements the CustomDatum interface. The CustomDatumFactory for this class can be obtained by using the Employee.getFactory() method.

/* Create a browser for a Queue with Adt messages of type EMPLOYEE*/
QueueSession jms_session
QueueBrowser browser;
Queue        test_queue;
browser = ((AQjmsSession)jms_session).createBrowser(test_queue,
                                                   "corrid='EXPRESS'",
                                                    Employee.getFactory());

Queues of Oracle Object Type Messages, Locking Messages


Purpose

Creates a QueueBrowser for queues of Oracle object type messages, locking messages while browsing.


Syntax
public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue,
                                            java.lang.String messageSelector,
                                            java.lang.Object payload_factory,
                                            boolean locked)
                                     throws JMSException

Parameters
queue

Queue to access.

messageSelector

Only messages with properties matching the message selector expression are delivered.

payload_factory

CustomDatumFactory or ORADataFactory for the java class that maps to the Oracle ADT.


Note:

CustomDatum support will be deprecated in a future release. Use ORADataFactory payload factories instead.

locked

If set to true, then messages are locked as they are browsed (similar to a SELECT for UPDATE).


Example
/* Create a browser for a Queue with Adt messages of type EMPLOYEE* in lock mode/
QueueSession jms_session
QueueBrowser browser;
Queue        test_queue;
browser = ((AQjmsSession)jms_session).createBrowser(test_queue, 
                                                    null, 
                                                    Employee.getFactory(),
                                                    true);

Creating a QueueReceiver

You can create a QueueReceiver for:

Queues of Standard JMS Type Messages


Purpose

Creates a QueueReceiver for queues of standard JMS type messages.


Syntax
public javax.jms.QueueReceiver createReceiver(javax.jms.Queue queue,
                                              java.lang.String messageSelector)
                                       throws JMSException

Parameters
queue

Queue to access.

messageSelector

Only messages with properties matching the message selector expression are delivered.


Usage Notes

The selector for the QueueReceiver can be any expression that has a combination of one or more of the following:

  • JMSMessageID = 'ID:23452345' to retrieve messages that have a specified message ID. All message IDs must be prefixed with "ID:"

  • JMS message header fields or properties:

    JMSPriority < 3 AND JMSCorrelationID = 'Fiction'
    
    
  • User-defined message properties:

    color IN ('RED', BLUE', 'GREEN') AND price < 30000 
    

Example 1
/* Create a receiver without a selector */
QueueSession    jms_session
QueueReceiver   receiver;
Queue           queue;
receiver = jms_session.createReceiver(queue);

Example 2
/* Create a receiver for queues with a specified selector */
QueueSession    jms_session;
QueueReceiver   receiver;
Queue           queue;
/* create Receiver to receive messages with correlationID starting with EXP  */
browser = jms_session.createReceiver(queue, "JMSCorrelationID LIKE 'EXP%'");

Queues of Oracle Object Type Messages


Purpose

Creates a QueueReceiver for queues of Oracle object type messages.


Syntax
public javax.jms.QueueReceiver createReceiver(javax.jms.Queue queue,
                                              java.lang.String messageSelector,
                                              java.lang.Object payload_factory)
                                       throws JMSException

Parameters
queue

Queue to access.

messageSelector

Only messages with properties matching the message selector expression are delivered.

payload_factory

CustomDatumFactory or ORADataFactory for the java class that maps to the Oracle ADT.


Note:

CustomDatum support will be deprecated in a future release. Use ORADataFactory payload factories instead.


Usage Notes

The CustomDatum factory for a particular java class that maps to the SQL object type payload can be obtained using the getFactory static method.

For queues containing AdtMessages the selector for the QueueReceiver can be a SQL expression on the message payload contents or messageID or priority or correlationID.

  • Selector on message ID - to retrieve messages that have a specific messageID. In this case message IDs must NOT be prefixed with ID:

    msgid = '23434556566767676'
    
    
  • Selector on priority or correlation is specified as follows

    priority < 3 AND corrid = 'Fiction'
    
    
  • Selector on message payload is specified as follows

    tab.user_data.color = 'GREEN' AND tab.user_data.price < 30000
    

Example

Assume the queue test_queue has payload of type SCOTT.EMPLOYEE and the java class that is generated by Jpublisher for this Oracle object type is called Employee. The Employee class implements the CustomDatum interface. The CustomDatumFactory for this class can be obtained by using the Employee.getFactory() method.

/* Create a receiver for a Queue with Adt messages of type EMPLOYEE*/
QueueSession jms_session
QueueReceiver receiver;
Queue        test_queue;
browser = ((AQjmsSession)jms_session).createReceiver(
                 test_queue,
                "JMSCorrelationID = 'MANAGER', 
                 Employee.getFactory());