Oracle8i Application Developer's Guide - XML
Release 3 (8.1.7)

Part Number A86030-01

Library

Solution Area

Contents

Index

Go to previous page Go to beginning of chapter Go to next page

Using Oracle Advanced Queuing (AQ) in XML Data Exchange, 5 of 6


AQ Example 2 (Java): Processing an XML Message Using JMS (Publish - Subscribe)

XML messages can be enqueued and dequeued from an AQ queue using JMS (Java Messaging Standard). Example 2 shows you how to publish and subscribe an XML message as a JMS TextMessage. Refer to Oracle8i Application Developer's Guide - Advanced Queuing for more examples.

AQ Example 2: Processing an XML Message Using JMS --Tasks Performed

Setting Up the AQ JMS Environment

See Oracle8i Application Developer's Guide - Advanced Queuing Chapter 13, "JMS Administrative Interface- Basic Operations" for information on setting up the AQ JMS environment.

Publish (Enqueue) an XML Message using JMS

The following lists the tasks performed by Example 2 using JMS to publish an XML message:

  1. Gets the name and location of Topic on a certain subject

  2. Gets ConnectionFactory for JMS provider that hosts desired topic

  3. Opens a Connection to the JMS provider using ConnectionFactory

  4. Creates a JMS Session

  5. Gets a Topic object using the JMS Session

  6. Creates the Message to be published

  7. Creates a TopicPublisher to send messages

  8. Publishes the Message to the Topic

Receive (Dequeue) an XML Message using JMS

The following lists the tasks performed by Example 2 using JMS to receive (subscribe) an XML message:

  1. Gets the name and location of Topic on certain subject

  2. Gets a ConnectionFactory of JMS provider that hosts desired Topic

  3. Opens a Connection to the JMS provider using ConnectionFactory

  4. Creates a JMS Session

  5. Gets a Topic object using the JMS Session

  6. Creates a TopicSubscriber to receive desired message

  7. Waits for messages - using blocking receive call or by registering MessageListener

AQ Example 2: Processing an XML Message Using JMS -- Java Code

Here is the Java code listing using JMS to process an XML message.

public void publishXMLMessage (String host, String ora_sid, int port, String 
driver) throws JMS Exception
{
TopicConnectionFactory tc_fact;
TopicConnection        t_conn;
TopicSession           jms_sess;
Topic                  mlmsg_topic;
TextMessage            xmlmsg;
TopicPublisher         xmlmsg_publisher;

// create a ConnectionFactory
tc_fact = AQjmsFactory.createTopicConnectionFactory(
                     host, ora_sid, port, driver);
//create a Topic Connection
t_conn = tc_fact.createTopicConnection ("scott", "tiger");
//create a JMS Session
jms_sess = t_conn.createTopicSession(true, 0); 

// Get a Topic object
xmlmsg_topic = ((AQjmsSession)jms_sess).getTopic("scott", "xmlmsg_topic");
//create Topic publisher
xmlmsg_publisher = jms_sess.createPublisher(null);
// create XML text message
xmlmsg =		jms_sess.createTextMessage();
//Publish message
xmlmsg_publisher.publish(xmlmsg_topic, xmlmsg);
jms_sess.commit();
}

public void receiveXMLMessage (String host, String ora_sid, int port, String 
driver) throws JMS Exception
{
TopicConnectionFactory	tc_fact;
TopicConnection		t_conn;
TopicSession			jms_sess;
Topic				xmlmsg_topic;
TextMessage			xmlmsg;
TopicSubscriber		xmlmsg_subscriber;

// create a ConnectionFactory
tc_fact = AQjmsFactory.createTopicConnectionFactory(
                     host, ora_sid, port, driver);
//create a Topic Connection
t_conn = tc_fact.createTopicConnection ("scott", "tiger");
//create a JMS Session
jms_sess = t_conn.createTopicSession(true, 0); 

// Get a Topic object
xmlmsg_topic = ((AQjmsSession)jms_sess).getTopic("scott", "xmlmsg_topic");
//create Topic subscriber
xmlmsg_subscriber = jms_sess.createDurableSubscriber(xmlmsg_topic, "XmlMsg_
Subscriber");
// create XML text message
xmlmsg =		(TextMessage)xmlmsg_subscriber.receive();
//Process Text Message

jms_sess.commit();
}



Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.

Library

Solution Area

Contents

Index