You are on page 1of 85

1

B2B Enhancements in Oracle9i

Advanced Queuing – Notification and Manageability features

B2B / AQ Enhancements 1--1


Objectives

• Describe the enhancements to AQ


notifications.
• Describe the working of AQ with LDAP server
(Oracle Internet Directory).
• Describe how Oracle JMS supports LDAP
clients.
• Understand how to manage AQ with OEM
Console

B2B / AQ Enhancements 1--2


Overview

OID
PL/SQL or
LDAP Java Client
LDAP Client Support

AQ Client

IDAP
Gateway
Message Agent
Requests
Advanced Queue

Rules &
Transfor Rules &
mation XML Messages Transfor
over HTTP mation
MQ Series

Rendezvous

Overview
To enable messaging operations (such as enqueue and dequeue) to be performed over the
Internet, a new XML based Internet Document Access Presentation (IDAP) has been created
by Oracle that allows message operations to be sent via HTTP across firewalls.
In addition, Internet based AQ users are also supported with the LDAP support provided using
the Oracle Internet Directory (OID), Advanced Queuing agents can now also be defined in
Oracle Internet Directory, providing a centralized, easy to manage, secure infrastructure for
global messaging.
AQ information can be externalized in Oracle Internet Directory, providing a single place for
the configuration and management of Advanced Queuing operations that span one or more
systems, such as subscribing to queues across multiple systems.
Oracle Enterprise Manager can be used to administer the AQ resources as well. Also Oracle
Enterprise Security Manager can be used to manage the AQ entries in OID.

B2B / AQ Enhancements 1--3


AQ Notification

OCI Client

ORACLE
E-Mail

Enqueue Advanced Queues


or Post PL/SQL

New in Oracle9i
• AQ Notifications are a result of an enqueue
operation, or explicit post operation when no
queue is involved.
• Now notifications can be delivered through
PL/SQL, email and HTTP post.
• Database events can also be notified to
subscribers

AQ Notification – Overview
Publish – Subscribe notification is the backbone of B2B communications. In Oracle8i, all the
AQ notifications could be received by OCI Clients only. In Oracle9i, AQ notification feature
has been enhanced to support
• Registering e-mail addresses to which notifications can be sent
• Call a stored PL/SQL procedure on notification
The registered clients are notified asynchronously, when events are triggered or an explicit AQ
enqueue operation. The clients need not be connected to the database.

B2B / AQ Enhancements 1--4


Register for AQ Notification of
Database Events
• AQ users can register for notification of
Database events such as startup, shutdown,
creation / dropping of schema, table, etc.
• To enable database event notification,
corresponding triggers should be created in
the database.
• Trigger should contain the command to
enqueue / post to the relevent queue.
• A client can register for "global events" that
apply to multiple databases.
• Such registrations can be stored in OID.

Database Event Registration


In Oracle9i, AQ users can register for notification of Database events such as startup,
shutdown, creation / dropping of schema, table, etc. By registering such events in AQ, the AQ
users can be notified of the users through the AQ.
To enable database event notification, corresponding triggers for the database event should be
written. In the body of the trigger, a message should be enqueued to the appropriate queue. On
the message enqueue, the subscribers to the queue are notified of the event automatically.
If notifications for events from multiple databases are involved, then the trigger mechanism has
to be setup in each of the database that participates in such a notification.

B2B / AQ Enhancements 1--5


Register for Notification with PL/SQL
Package
• DBMS_AQ package has procedures to manage AQ
registrations.
• REGISTER Procedure is used to register
– An email address for message notification
– Invoke a user-defined PL/SQL procedure on
message enqueue
• UNREGISTER Procedure unregisters a subscription and
turns off notifications to the subscriber.
• POST Procedure posts to a list of subscriptions which
allows all clients who are registered for the
subscriptions to get notifications.
• Several subscriptions can be registered on unregistered
at one time with the use of reglist option

DBMS_AQ package has procedures to manage AQ registrations.


REGISTER Procedure procedure registers an email address or user-defined PL/SQL procedure for
message notification. You can specify an email address to which message notifications will be sent
or register a procedure to be invoked on a notification. Interest in several subscriptions can be
registered at one time.
• Example of registering two PL/SQL procedures is shown here:
DECLARE
reginfo sys.aq$_reg_info;
reginfo1 sys.aq$_reg_info;
reginfolist sys.aq$_reg_info_list;
BEGIN
reginfo :=
sys.aq$_reg_info('U1.EVENTS:ADMIN',DBMS_AQ.NAMESPACE_AQ,'plsql
://plsqlregproc1',HEXTORAW('FF'));
reginfo1 :=
sys.aq$_reg_info('U1.EVENTS:ADMIN',DBMS_AQ.NAMESPACE_AQ,'plsql
://plsqlregproc1?PR=1',HEXTORAW('FF'));
reginfolist := sys.aq$_reg_info_list(reginfo);
reginfolist.EXTEND;
reginfolist(2) := reginfo1;
sys.dbms_aq.register(reginfolist, 2);
commit;
END;
UNREGISTER Procedure unregisters a subscription which turns off notifications. Several
subscriptions can be unregistered from at one time.
• Example (Using the above registration)
sys.dbms_aq.unregister(reginfolist, 2);
B2B / AQ Enhancements 1--6
OID Support for AQ

• LDAP client can register for events that apply


to multiple databases. Such a registration is
referred to as Global Registration.
• OID can be used as the repository for event
registration.
• JMS Queue/Topics, Connectionfactories, and
their subscriptions can be looked up in OID.
• OID can be used to look up AQ Aliases,
Agents, and queues.
• OID can be used to modify registered events.

OID Support for AQ


In Oracle 8i, registration was limited to OCI clients. In Oracle9i, the registration via LDAP is
enabled. This will allow registration an LDAP clients so they can receive notifications when the
specified queues are affected.
A client can register for events that apply to multiple databases in an enterprise. For e.g., The
client can register for a "DATABASE OPEN" event (not available in Oracle8i) via LDAP.
When the database of interest comes back up, it will query the LDAP server and pick up the
new registrations.
Also all the users who have registered for the concerned queue would be notified of the
database being started up.

B2B / AQ Enhancements 1--7


Register for AQ Notifications in OID –
Setup
• Prerequisites:
– Client should be an enterprise user.
– Database Parameters
– COMPATIBLE = 9.0 (or higher)
– LDAP_REG_ENABLED = “TRUE”
• Setup Procedure:
– In each enterprise domain create
ENTERPRISE_AQ_USER_ROLE in OID.
– Add GLOBAL_AQ_ROLE to the
ENTERPRISE_AQ_USER_ROLE in the database.
– Add ENTERPRISE_AQ_USER_ROLE to privilege
group cn=OracleDBAQUsers.
– Grant ENTERPRISE_AQ_USER_ROLE to AQ
users.

Registration through OID- Steps


Prerequisites:
• Registering via LDAP (open registration) requires the client to be an enterprise user.
(For more information on enterprise user management please see "Oracle Advanced
Security Guide", “Managing Enterprise User Security“).
• The COMPATIBLE database parameter has to be 9.0 or higher
• The LDAP_REG_ENABLED parameter must be set to true. This can be changed in
operating database instance using the command
ALTER SYSTEM SET ldap_reg_enabled = ‘TRUE’;
• REG_SYNC_INTERVAL parameter must be set to the time interval (in seconds) to
refresh registrations from LDAP. This can be changed in operating database instance
using the command
ALTER SYSTEM SET reg_sync_interval = Number of Seconds

B2B / AQ Enhancements 1--8


Manual setup:
The following steps have to be performed before the open registration feature can be used :
• In each enterprise domain, create enterprise role ENTERPRISE_AQ_USER_ROLE using
Oracle Enterprise Security Manager (OESM). This role will be stored in the OID, and is
applicable to all the databases in the domain.
• For each database in the enterprise domain, add global role
GLOBAL_AQ_USER_ROLE to enterprise role ENTERPRISE_AQ_USER_ROLE using
OESM.
• For each enterprise domain, add enterprise role ENTERPRISE_AQ_USER_ROLE to
privilege group cn=OracleDBAQUsers under cn=oraclecontext in the administrative
context.
• 4. For each enterprise user that should be authorized to register for events in the
database, grant enterprise role ENTERPRISE_AQ_USER_ROLE to it using OESM.

B2B / AQ Enhancements 1--9


Register for Notification in OID Using OCI

• Execute OCIInitialize() with OCI_EVENTS or


OCI_USE_LDAP mode.
• Execute OCIAttrSet() to set the environment handle
attributes for accessing OID.
• Execute OCIHandleAlloc() to allocate a subscription
handle.
• Execute OCIDescriptorAlloc() to allocate a server DN
descriptor.
• Execute OCIAttrSet() to set the server DN descriptor.
• Execute OCIAttrSet() to set the subscription handle.
• Execute OCISubscriptionRegister() to register with
the subscription(s).

Steps to register via LDAP using OCI:


•Execute OCIInitialize() with OCI_EVENTS or OCI_USE_LDAP mode to specify that
the application is interested in registering for notifications via LDAP.
• Execute OCIAttrSet() to set the environment handle attributes for accessing LDAP:
– OCI_ATTR_LDAP_HOST: the host name on which the LDAP server resides
– OCI_ATTR_LDAP_PORT: the port on which the LDAP server is listening
– OCI_ATTR_BIND_DN: the distinguished name to login to the LDAP server;
usually the DN of the enterprise user;
– OCI_ATTR_LDAP_CRED: the credential used to authenticate the client,
– OCI_ATTR_WALL_LOC: for SSL authentication, the location of the client wallet.
– OCI_ATTR_LDAP_AUTH: the authentication method code, (for a complete list of
authentication modes see Appendix A, "Handle and Descriptor Attributes“ in
“Oracle9i Application Developer Guide – Advanced Queuing”)
– OCI_ATTR_LDAP_CTX: the administrative context for oracle in the LDAP
server.

B2B / AQ Enhancements 1--10


Steps to register via LDAP using OCI (Continued)
• Execute OCIAttrSet() to set the server DN descriptor attributes for
• OCI_ATTR_SERVER_DN: the distinguished name of the database in which the
client is interested receiving notifications;
• OCIAttrSet() can be called multiple times for this attribute so that more than one
database server is included in the registration.
• Execute OCIAttrSet() to set the subscription handle attributes for:
– OCI_ATTR_SUBSCR_NAME: subscription name
– OCI_ATTR_SUBSCR_NAMESPACE: subscription namespace
– OCI_ATTR_SUBSCR_CALLBACK: notification callback
– OCI_ATTR_SUBSCR_CTX: callback context
– OCI_ATTR_SUBSCR_PAYLOAD: payload buffer for posting
– OCI_ATTR_SUBSCR_RECPT: recipient name
– OCI_ATTR_SUBSCR_RECPTPROTO: protocol to receive notification
– OCI_ATTR_SUBSCR_RECPTRES: presentation to receive notification with
– OCI_ATTR_SUBSCR_SERVER_DNs: the descriptor handle we populated in step
5.
• Execute OCISubscriptionRegister() to register with the subscription(s). The registration
will take effect when the database comes to LDAP to pick up new registrations, whose
frequency is determined by the value of REG_SYNC_INTERVAL.

B2B / AQ Enhancements 1--11


Registration within an IDAP Message

• Registrations can be performed within IDAP as


well.
• The details of IDAP message are covered in
Lesson 2
• Indicate options associated with events
registration.
– Destination
– Notify_URL

IDAP Message Options - Register


Register options indicate options associated with event notification registration. The following
parameters are provided through the Register Options:
DESTINATION.: To specify the queue or topic on which notifications are registered. The
destination element has an attribute lookup_type which determines how the destination element
value is interpreted.
• DATABASE (default)— destination is interpreted as schema.queue_name
• LDAP— the LDAP server is used to resolve the destination.
NOTIFY_URL— where notification is sent when a message is enqueued. The form can be
http://<url> or mailto://<email address> or plsql://<pl/sql procedure>.

B2B / AQ Enhancements 1--12


Registering for Notification at an Email
Address - Example
<?xml version="1.0"?>
<Envelope xmlns=
"http://www.oracle.com/schemas/IDAP/envelope">
<Body>
<AQXmlRegister xmlns =
"http://www.oracle.com/schemas/AQ/access">
<register_options>
<destination>AQUSER.EMP_TOPIC</destination>
<consumer_name>APP1</consumer_name>
<notify_url>mailto:app1@hotmail.com</notify_url>
</register_options>
<AQXmlCommit/>
</AQXmlRegister>
</Body>
</Envelope>

Register Request Example


Registering for Notification at an Email Address:
To notify an email address of messages enqueued for consumer APP1 in queue
AQUSER.EMP_TOPIC, the register request has the following format:
<?xml version="1.0"?>
<Envelope xmlns= "http://www.oracle.com/schemas/IDAP/envelope">
<Body>
<AQXmlRegister xmlns =
"http://www.oracle.com/schemas/AQ/access">
<register_options>
<destination>AQUSER.EMP_TOPIC</destination>
<consumer_name>APP1</consumer_name>
<notify_url>mailto:app1@hotmail.com</notify_url>
</register_options>
<AQXmlCommit/>
</AQXmlRegister>
</Body>
</Envelope>

B2B / AQ Enhancements 1--13


AQ Aliases in OID

• Aliases provide an easy mechanism for LDAP


clients to look up Queues.
• AQ aliases in OID are managed using the
package DBMS_AQADM
• DBMS_AQADM has two new procedure calls:
– ADD_ALIAS_TO_LDAP creates an alias for
a queue, agent, or a JMS
ConnectionFactory in LDAP.
– DEL_ALIAS_FROM_LDAP drops an alias for
a queue, agent, or JMS ConnectionFactory
in LDAP.

Managing LDAP AQ Information: DBMS_AQADM


ADD_ALIAS_TO_LDAP procedure creates an alias for a queue, agent, or a JMS
ConnectionFactory in LDAP. The alias will be placed directly under the database server’s
distinguished name in LDAP hierarchy.
DBMS_AQADM.ADD_ALIAS_TO_LDAP( alias IN VARCHAR2, obj_location
IN VARCHAR2);
• ALIAS: the name of the alias. Example:’west_shipping’
• OBJ_LOCATION: The distinguished name of the object (queue, agent or connection
factory) to which the above alias refers to.
DEL_ALIAS_FROM_LDAP procedure drops an alias for a queue, agent, or JMS
ConnectionFactory in LDAP.
DBMS_AQ.DEL_ALIAS_FROM_LDAP(
alias IN VARCHAR2);

B2B / AQ Enhancements 1--14


AQ Aliases in OID - Uses

AQ Aliases are used by:


• JMS in JNDI for Look up of
– Connection Factory
– Queue / Topic
• IDAP for
– Sender-ID , Recipient-ID
– Destination Queue / Topics

AQ Aliases in OID
OID can be used as a repository of AQ aliases. Mainly the aliases are looked up by the JMS for
locating ConnectionFactories, Queue/Topic lists. Also the aliases in OID can be used through
IDAP for locating the Sender-ID, Recepient-ID, Destination Queues/Topics.

B2B / AQ Enhancements 1--15


JMS and OID

• Java Message Service (JMS) requires


administered objects to be stored in a
namespace that can be accessed by JNDI.
• AQ can now store relevant information about
connect strings and topic meta-data in the OID.
• New objects have been added to OID to
support this feature:
– ConnectionFactory
– QueueConnectionFactory
– TopicConnectionFactory
– Topic
– Queue

Java Messaging Service and LDAP


The Java Message Service (JMS) provides a common way for Java programs to create, send, receive,
and read an enterprise messaging system’s messages. Applications which interface with Oracle’s
Advanced Queuing feature can be developed in Java using the oracle.jms Java Package. This
implementation of a public standard extends the defined W3C interfaces so that developers operating
in the JMS context have the same means as those working within Native AQ.
The Java Naming and Directory Interface (JNDI) is an application programming interface (API) that
provides naming and directory functionality to applications written using the Java programming
language. It is defined to be independent of any specific directory service implementation. Thus a
variety of directories--new, emerging, and already deployed--can be accessed in a common way.
The JNDI architecture consists of an API and a service provider interface (SPI). Java applications use
the JNDI API to access a variety of naming and directory services. The SPI enables a variety of
naming and directory services to be plugged in transparently, thereby allowing the Java application
using the JNDI API to access their services.
A ConnectionFactory encapsulates a set of connection configuration parameters that has been defined
by an administrator. A client uses it to create a Connection with a JMS provider. In this case Oracle
JMS, Oracle9i is the JMS Provider.
There are two types of ConnectionFactory objects:
• QueueConnectionFactory
• TopicConnectionFactory
ConnectionFactory objects can be obtained in one of the following ways
• Static methods in AQjmsFactory
• Java Naming and Directory Interface (JNDI) Lookup from a LDAP directory server

B2B / AQ Enhancements 1--16


Registration of ConnectionFactories
through LDAP
• There is a Java API for LDAP Registration.
• The Java class is AQRegistrationTool, which
contains the following methods:
– RegisterConnectionFactory()
– UnregisterConnectionFactory()
• Two ways to register Queue / Topic
Connectionfactory through LDAP
– Register using JDBC Connection
Parameters
– Register using JDBC URL

Registration of ConnectionFactories through LDAP


Register using JDBC Connection Parameters or the JDBC URL:
• The registerConnectionFactory() method is a static method used to add a registration entry
for a Connection Factory in LDAP. To successfully register the connection factory, To
successfully register the connection factory, the hashtable passed to
registerConnectionFactory must contain all the information to establish a
valid connection to the LDAP server. Furthermore, the connection must have
write access to the connection factory entries in the LDAP server (which requires
the LDAP user to be either the database itself or be granted
global_aq_user_role).
• After registration, you can look up the connection factory using the JNDI.

B2B / AQ Enhancements 1--17


• Example using JDBC Connection Paremeters:
Hashtable env = new Hashtable(5, 0.75f);
/* the following statements set in hashtable env:
* service provider package, the URL of the ldap server,
the distinguished name of the database server, the
authentication method (simple), the LDAP user name, and
the LDAP user password */
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://sun-456:389");
env.put("searchbase",
"cn=db1,cn=Oraclecontext,cn=acme,cn=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,
"cn=db1aqadmin,cn=acme,cn=com");
env.put(Context.SECURITY_CREDENTIALS, "welcome");
AQjmsFactory.registerConnectionFactory(env, "queue_conn1",
"sun-123", "db1", 1521, "thin", "queue");
• For using the JDBC URL, the url is passed in as a string,
url = "jdbc:oracle:thin:@sun-123:1521:db1";
AQjmsFactory.registerConnectionFactory(env,
"topic_conn1", url, null, "topic");

Method used for unregistering:


• The unregisterConnectionFactory() method should be used to remove a registration entry
for a Connection Factory. unregisterConnectionFactory is a static method.
To successfully unregister the connection factory, the DB connection must be
granted AQ_ADMINISTRATOR_ROLE.

B2B / AQ Enhancements 1--18


Getting ConnectionFactory in LDAP

• To look up Connection Factory in LDAP, use


the lookup method.
• Example:
– qc_fact =
(queueConnectionFactory)ctx.lookup(
"cn=queue_conn1");
– Where the ctx describes the
Oraclecontext as
ctx = (DirContext)ctx.lookup
("cn=OracleDBConnections,cn=db1,c
n=Oraclecontext,cn=acme,cn=com");

Getting ConnectionFactory in LDAP


Example:
Hashtable env = new Hashtable(5, 0.75f);
DirContext ctx;
queueConnectionFactory qc_fact;
/* the following statements set in hashtable env: service provider package, the URL of the
ldap server, the distinguished name of the database server, the authentication method
(simple), the LDAP user name, and the LDAP user password */
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://sun-456:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,
"cn=db1aquser1,cn=acme,cn=com");
env.put(Context.SECURITY_CREDENTIALS, "welcome");
ctx = new InitialDirContext(env);
ctx = (DirContext)ctx.lookup
("cn=OracleDBConnections,cn=db1,cn=Oraclecontext,cn=acme,cn=
com");
qc_fact =
(queueConnectionFactory)ctx.lookup("cn=queue_conn1");

B2B / AQ Enhancements 1--19


Getting Queue / Topic in LDAP

• Use the (topic).lookup method to get the Queue


or Topic from LDAP.
• Example
topic_1=topic)ctx.lookup("cn=topic_1")
;
• The context for ctx is defined as
ctx
=(DirContext)ctx.lookup("cn=OracleDB
Queues,cn=db1,cn=Oraclecontext,cn=ac
me,cn=com");

Getting Queue / Topic in LDAP


Example
Hashtable env = new Hashtable(5, 0.75f);
DirContext ctx;
topic topic_1;
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://sun-456:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,
"cn=db1aquser1,cn=acme,cn=com");
env.put(Context.SECURITY_CREDENTIALS, "welcome");
ctx = new InitialDirContext(env);
ctx
=(DirContext)ctx.lookup("cn=OracleDBQueues,cn=db1,cn=Oraclec
ontext,cn=acme,cn=com");
topic_1 = (topic)ctx.lookup("cn=topic_1");

B2B / AQ Enhancements 1--20


Monitor Internet Users of AQ
AQ$INTERNET_USERS
• AQ$INTERNET_USERS provides information about
agents registered for internet access to AQ.
• The view contains the following columns:
– AGENT_NAME— the name of the AQ Internet agent
– DB_USERNAME— the name of the database user
that this Internet agent maps to
– HTTP_ENABLED— indicates agent is allowed to
access AQ via HTTP. Has a value of YES or NO.
– SMTP_ENABLED— indicates agent is allowed to
access AQ via SMTP. Has a value of YES or NO
– FTP_ENABLED— indicates agent is allowed to
access AQ via FTP. Always has a value of NO in
current release.

Monitor Internet Users of AQ


The view AQ$INTERNET_USERS can be used to monitor and administer AQ agents
registered for internet access.

B2B / AQ Enhancements 1--21


AQ Management with OEM Console

• Management and administration of AQ can


now be performed through Oracle Enterprise
Manager (OEM)
• OEM Console provides two main sections for
managing AQ:
– AQ Administration
– AQ Objects
• The Diagnostics and Tuning Pack supports
alerts and monitoring for AQ queues.

AQ Management with OEM


Oracle Enterprise Manager can be used to manage AQ. AQ administrative functionality has
been provided through Oracle Enterprise Manager. OEM Console can be used to
• create queue tables and queues,
• browse through AQ messages,
• add AQ subscribers, and manage propagation.
Among the Oracle9i functionalities, OEM console supports
• Setting up security for a queue table
• Viewing queue statistics: # of messages in different states
• Rule specification
OEM Console also shows topology for propagation of messages between queues at database
level and queue level.
Oracle Diagnostics and tuning pack supports alerts and monitoring for AQ queues. Alerts can
be sent when the number of messages for a particular subscriber exceeds a threshold. Alerts can
be sent when there is an error in propagation. In addition, queues can be monitored for number
of messages in ready state or number of messages per subscriber, etc.

B2B / AQ Enhancements 1--22


AQ Administration with OEM Console

Administration of AQ through OEM Console:


• Configuring init.ora parameters
– AQ_TM_PROCESSES
– JOB_QUEUE_PROCESSES
– JOB_QUEUE_INTERVAL (for Oracle8 and Oracle8i
databases only)
• Administering Propagation schedules
– Configuration
– Monitoring
– Viewing Topology at Queue and Database levels
• Migration Utilities
– Migrating AQ queues from one database to another

AQ Administration with OEM console


AQ administration functions can be performed with OEM console. The initialization
parameters for AQ can be set and changed.
The OEM console can Also be used to monitor and manage the message propagation schedules

B2B / AQ Enhancements 1--23


AQ Monitoring with
Oracle Diagnostics Pack

AQ Monitoring
In this screen shot, the number of messages in the selected queues are displayed for each status:
Waiting, Ready, or Expired. This example shows that there are about 50 messages ready to be
dequeued from the Orders_Queue table.

B2B / AQ Enhancements 1--24


Summary

In this lesson, you should have learned about:


• AQ integration with Oracle Internet Directory
• Use of different mechanisms to register for AQ
notifications
• Use of JMS and Oracle Internet Directory
• Managing AQ with OEM Console

B2B / AQ Enhancements 1--25


B2B Communication

Advanced Queuing Internet Integration

B2B / AQ Enhancements 2--1


Objectives

• After this lesson, you should be able to:


– Describe how to use iDAP to transmit AQ
messages over the Internet.
– Describe how an internet user is authorized
to access Oracle AQ.
– Setup AQ to use HTTP or HTTPS.
– Setup AQ to use email.
– Describe the structure of XML payloads
under iDAP.
– Describe AQ message propogation between
Oracle Databases using HTTP.
– Describe the use of Messaging gateways.

B2B / AQ Enhancements 2--2


Overview

OID Oracle9i

AQ Agent

IDAP
Message
Requests
PL/SQL
Oracle9i Transformations
AQ Client

XML Messages Gateway for


over HTTP MQSeries, Tibco

Overview
Oracle9i provides a standard infrastructure that makes it easier for customers to integrate
storefronts, exchanges and portals with other backend and external systems. This allows
Oracle9i to support millions of messages per hour in industry standard business messaging
formats.
Advanced Queuing
XML based messaging over HTTP is supported in Advanced Queuing in Oracle9i, allowing
external ‘across firewall’systems to be more easily integrated. In addition, non-database,
Internet based AQ users are also supported, allowing for greater flexibility in heterogeneous
environments. To enable messaging operations (such as enqueue and dequeue) to be performed
across the Internet, a new XML based Internet Document Access Presentation (IDAP) has been
created by Oracle that allows message operations to be sent via HTTP across firewalls.
Oracle9i also provides an built in message transformation architecture, with support for
PL/SQL transformations, which can be executed at enqueue,dequeue and propagation
operations. (Covered in a different lesson).
Advanced Queuing agents can now also be defined in Oracle Internet Directory, providing a
centralized, easy to manage, secure infrastructure for global messaging. In addition, AQ
information can be externalized in Oracle Internet Directory, providing a single place for the
configuration and management of Advanced Queuing operations that span one or more
systems, such as subscribing to queues across multiple systems.
Enterprise application integration may involve legacy applications and/or customer sites where
non-Oracle products are widely used. While solutions to integration problems can be based
around an Oracle AQ or RDBMS, it is not feasible to convert all customer applications to use
Oracle AQ or RDBMS entirely. For this reason, Oracle provides a Messaging Gateway which
allows customer applications to remain unchanged and which seamlessly integrates
connectivity between AQ and other messaging systems.
B2B / AQ Enhancements 2--3
Internet Integration - Requirements
• B2B applications on the internet require
– Messages to work with firewalls and proxies.
– The protocol used should not be proprietary.
• Oracle has evolved an XML based protocol called
Internet Data Access Presentation (iDAP).
• Security mechanisms for the Internet usage have
also been incorporated.

Internet Integration - Requirement


Currently client to server and server to server communication uses the Oracle Net protocol.
Being proprietary, it is faced with difficulty for B2B applications for transporting messages
between organizations. Another limitation is the inability to transmit SQL*Net messages
through a firewall.
A simple and open protocol that demands very little by way of pre-requisites at the client end
is needed. It should also work with firewalls and proxies. Considering this, Oracle has evolved
an XML based standard protocol, IDAP (Internet Data Access Presentation) to make B2B
communications over the internet possible. In addition, authentication and authorization
mechanisms have also been built in to Advanced Queuing to support the Internet based users.

B2B / AQ Enhancements 2--4


Internet Integration - IDAP

• Internet access to AQ is implemented by using the


Internet Data Access Presentation (IDAP)
specification to format AQ messages in XML.
• The IDAP document encapsulates transactions,
security, transformation, and character set id for
the requests.
• Third-party clients will be able to enqueue and
dequeue messages, if they have HTTP(S) support
and the ability to decode XML messages.

Internet Protocol Support


An IDAP document encapsulates AQ operation request and response in XML. To perform AQ
operations - enqueue, dequeue, send notifications, register for notifications, propagation, etc -
over the Internet standard transport (HTTP(s) and Email), IDAP is used. In addition, IDAP
encapsulates transactions, security, transformation, and character set id for the requests.
The XML message that will be propagated will contain the actual payload in XML format
along with meta information present in the header which will also be represented in XML
format.
Currently in AQ messages are stored in queue tables. The payload is stored in either RAW
format or as Oracle objects (ADTs). The meta data for messages is stored in separate columns
in the queue table. In Oracle9i AQ object type payloads can also be rendered, and received in
XML format.
All of these types of queues can still be accessed via the internet. If the queue holds messages
in RAW or Oracle Object (ADT) format, the XML payloads will first be transformed to the
appropriate internal format and then stored. During dequeue, if the messages are obtained from
the queue in RAW or ADT format, they are converted to XML before sending them to the
client.

B2B / AQ Enhancements 2--5


Internet Integration in AQ
Overview

Oracle9i

AQ Servlet
AQ Queue
AQ client
HTTP(S)
Major Components of AQ operations for Internet are:
• The AQ Client Program
• The AQ Servlet running on a Web Server
• The Oracle9i Database Server
Detailed component overview for different protocols
such as HTTP, SMTP are discussed later.

Internet Integration in AQ – Overview


The major components of AQ operations over the internet are:
•The AQ Client program capable of sending XML messages in IDAP format
•AQ Servlet running on a Web server. The AQ servlet would be developed by the
customers based on the example provided in Oracle9i.
•Oracle9i Database server that hosts the Advanced Queue.
The broad steps in this communication are:
•The Client program sends the request for enqueue, dequeue, or register in XML format
complying with the IDAP to the Web Server (or Servlet Runner) which hosts the AQ
Servlet. If SMTP protocol is used, the client request shiuld be transmitted to the Oracle
Email Server, which in turn, after due authentication from Oracle Internet Directory, sends
the request to the AQ Servlet.
•The AQ Servlet interprets the Client Request, connects to the queue on Oracle9i database
server, and performs the relevant queue operations.

B2B / AQ Enhancements 2--6


Setting up Internet Access for AQ
Following are the summarized steps required to set up
Internet Access for AQ queues:
• Set up AQ Servlet: Create a servlet that extends the
class oracle.AQ.xml.AQxmlServlet. Implement init()
method in the servlet to specify database connection
parameters.
• Set up User Authentication: Configure the web server to
authenticate all the users that send POST requests to
the AQ servlet.
• Set up User Authorization: Register AQ agent used to
perform AQ operations using procedure
DBMS_AQADM.CREATE_AQ_AGENT. Map the AQ agent
to the database users using the procedure
DBMS_AQADM.ENABLE_DB_ACCESS.
• Now clients can write IDAP requests and send via HTTP
POST to AQ Servlet.

Set Internet Access for AQ


(For details please look at Chapter 17 in Advanced Queuing documentation).
Following are the summarized steps required to set up Internet Access for AQ queues:
Set up AQ Servlet:
• Create a servlet that extends oracle.AQ.xml.AQxmlServlet class. Implement init() method
in the servlet to specify database connection parameters
Set up User Authentication:
• Configure the web server to authenticate all the users that send POST requests to the AQ
servlet. Only authenticated users are allowed to access the AQ servlet.
Set up User Authorization:
• Register AQ agent name which will be used to perform AQ operations using
DBMS_AQADM.CREATE_AQ_AGENT. Map the AQ agent to the database users using
DBMS_AQADM.ENABLE_DB_ACCESS.
Now clients can write IDAP requests and send via HTTP POST to AQ Servlet.

B2B / AQ Enhancements 2--7


IDAP Message Structure
• The Internet Data Access Presentation (IDAP) uses the
Content-Type of text/xml to specify the body of the
request
• XML provides the presentation for IDAP request and
response messages as follows:
– All protocol tags are scoped to the IDAP namespace.
– The sender includes namespaces in IDAP elements
and attributes.
– The receiver processes IDAP messages that have
correct namespaces.
– The receiver processes IDAP messages without
namespaces as though they had the correct
namespaces, if the context is valid.
– The IDAP namespace has the value
http://www.oracle.com/schemas/IDAP/envelope
– An XML document forming the request of an IDAP
invocation does not require the use of an XML DTD
or a schema.

IDAP Message Structure


IDAP messages are structured into IDAP Envelope, IDAP header, and IDAP body.
The IDAP Envelope
• The tag of this root element is IDAP:Envelope. IDAP defines a global attribute
IDAP:encodingStyle that indicates serialization rules used instead of those described by
the IDAP specification. This attribute may appear on any element and is scoped to that element
and all child elements not themselves containing such an attribute.
• The IDAP envelope also contains namespace declarations and additional attributes, provided
they are namespace-qualified. Additional namespace-qualified sub-elements can follow the
body.
The IDAP Headers
• The tag of this first element under the root is IDAP:Header. An IDAP header passes
necessary information, such as the transaction ID, with the request. The header is encoded as a
child of the IDAP:Envelope XML element. Headers are identified by the name element and
are namespace-qualified. A header entry is encoded as an embedded element.
The IDAP Body
• The IDAP body, tagged IDAP:Body, contains a first sub-element whose name is the method
name. This method request element contains elements for each input and output parameter. The
element names are the parameter names. The body also contains IDAP:Fault, indicating
information about an error.
• For performing AQ operations, the IDAP body must contain an AQ XML document. The AQ
XML document has the namespace http://www.oracle.com/schemas/AQ/access

B2B / AQ Enhancements 2--8


IDAP Message
• The body of an IDAP message is an AQ XML
document, and represents:
– Client requests for enqueue, dequeue, and
registrations
– Notifications from the AQ Server to the client.
• A message set consists of one or more messages.
• Each message consists of a message_header and
message_payload
• An AQ message is provided as an argument to the
send/publish call.
• A message consists of the following:
– Message_number
– Message_header
– Message_payload

AQ Message
MESSAGE_Set: A Message_Set consists of one or more messages.
MESSAGE: A Message consists of the following:
• MESSAGE_NUMBER: The sequence number of the message in the Message_Set. This
information is useful for the client for logging in.
• MESSAGE_HEADER: The Message_Header comprises of the following:
MESSAGE_ID: The identifier of the message.
CORRELATION: The correlation identifier of the message
EXPIRATION: The duration in seconds that a message is available for dequeuing.
DELAY: Duration in seconds after which a message is available for processing.
PRIORITY: The priority of the message. A smaller number indicates higher priority.
SENDER_ID: The application-specified identifier, agent_name, address, protocol
agent_alias— if specified, resolves to a name, address, protocol using LDAP
RECIPIENT_LIST: Overrides the default subscriber list; lookup_type defines if the
recipients are specified or looked up in LDAP
MESSAGE_STATE: The state of the message is filled in automatically during dequeue
EXCEPTION_QUEUE: In case of exceptions the name of the queue to which the message
is moved if it cannot be processed successfully.
MESSAGE_PAYLOAD The payload of the message is of type ANY and will be interpreted
at run time.

B2B / AQ Enhancements 2--9


IDAP Message Handling

• IDAP defines the conversion of XML payload


into Oracle objects
– Scalar attributes
– An XML attribute

Example of IDAP conversion


IDAP can convert an XML payload into an Oracle object with some scalar attributes and an
XMLType attribute
Let us assume a queue table created as follows:
create type xtype as object (
n number;
x XMLType;
);
The AQ XML payload representation of this object would look like:
<message_payload>
<n> 123 </n>
<x>
<more xml data>
</x>
</message_payload>

In the above example, when converted to an object, the attribute n will have value 123 and
attribute x would contain XML data between tags <x> and </x>

B2B / AQ Enhancements 2--10


IDAP Methods

• There are two types of AQ methods in IDAP:


– AQ Access Methods
SEND, PUBLISH, RECEIVE, REGISTER,
COMMIT, ROLLBACK
– AQ Status Response
Response from the AQ
• For each method attributes can be specified
• Three classes of options:
– Producer (for SEND/PUBLISH operations)
– Consumer (for RECEIVE operations)
– Register (for notification registration

AQ Message Methods
AQ methods can be classified into two areas, namely:
AQ Access Methods
• SEND: Enqueue a message from a client to a single consumer queue
• PUBLISH: Enqueue a message from a client to a multi consumer queue
• RECEIVE: Dequeue a message from a client to a single consumer queue
• REGISTER: Register for notifications on a queue or topic
• COMMIT: Commits the transaction
• ROLLBACK: Rolls back the transaction
Status Response
• Status Response following an Publish request
• Status Response following a Receive request
• Status Response following an error

B2B / AQ Enhancements 2--11


IDAP Message Options - Producer

Indicate options associated with send/publish


method calls.
• Destination - Queue
• Visibility – When the message is visible.
• Transformation – The transformation function
(PL/SQL) to be invoked before enqueue.

AQL Message Options - Producer


Producer options indicate options associated with enqueue operations. The following
parameters are provided through the Producer Options:
DESTINATION
• The queue to which messages are to be sent (enqueued). It includes a lookup_type
attribute defines whether the queue is specified directly or needs to be looked up through
LDAP.
VISIBILITY
• Specifies the transactional behavior of the Send (enqueue) request. Visibility can be either
ON_COMMIT or IMMEDIATE.
TRANSFORMATION
• The PL/SQL transformation to be invoked before the message is enqueued.

B2B / AQ Enhancements 2--12


IDAP Message Options - Consumer

Indicate options associated with receive


method calls.
• Destination – Source Queue
• Consumer_name
• Selector
– Message_ID, Correlation or <expression>
• Visibility
• Dequeue_mode
• Navigation
• Transformation

AQL Message Options - Consumer


Consumer options indicate options associated with dequeue operations. The following parameters
are provided through the Consumer Options:
DESTINATION
• The queue from which messages are to be received (dequeued). It includes a lookup_type
attribute defines whether the queue needs to be specified directly or looked up through LDAP.
CONSUMER_NAME
• The name of the consumer.
SELECTOR
• Indicates the selection criterion to be used for dequeuing a message. This can be one of the
following:
• MESSAGE_ID: Specify the message identifier of the message to be dequeued.
• CORRELATION: Specify the correlation identifier of the message to be dequeued.
• <expression>: A condition is specified as a Boolean expression using syntax similar to the
WHERE clause of a SQL query. This Boolean expression can include conditions on message
properties, user data properties (object payloads only), and PL/SQL or SQL functions (as
specified in the where clause of a SQL query). Message properties include priority, corrid and
other columns in the queue table
VISIBILITY
• Specifies whether the message is dequeued as part of the current transaction. Visibility can be
either ON_COMMIT or IMMEDIATE.

B2B / AQ Enhancements 2--13


AQL Message Options – Consumer (Continued)
DEQUEUE_MODE
• Specifies the mode in which the dequeue is performed (The locking behavior associated
with the dequeue). The possible values of dequeue_mode are BROWSE, LOCKED,
REMOVE.
NAVIGATION
• Specifies the position of the method that will be retrieved. The possible values are
NEXT_MESSAGE, NEXT_TRANSACTION, and FIRST_MESSAGE.
TRANSFORMATION
• The PL/SQL transformation to be invoked after the message is dequeued.

B2B / AQ Enhancements 2--14


IDAP Message Options - Register

Indicate options associated with events


registration.
• Destination
• Notify_URL

AQL Message Options - Register


Register options indicate options associated with event notification registration. The following
parameters are provided through the Register Options:
DESTINATION
• The queue to which the consumer is registering for notification. Includes a lookup_type
attribute defines whether the queue needs to be specified directly or looked up through
LDAP.
NOTIFY_URL
• Where notification is sent when a message is enqueued. The form can be http://<url> or
mailto://<email address> or plsql://<pl/sql procedure>.

B2B / AQ Enhancements 2--15


IDAP Messages - Response

• AQ uses Response Messages to return the


result of an AQ method
• Each Response consists of a Status Response
and possibly also one of the following:
– Send_result
– Publish_result
– Receive_result

AQ Response Messages
The response to an enqueue request to a single-consumer queue uses the AQXmlSendResponse
method. The components of the response may include:
Status Response
• status_code— indicates success (0) or failure (-1)
• error_code— Oracle code for the error
• error_message— description of the error
Send_result (for an Enqueue to a Single-Consumer Queue)
• destination— where the message was sent
• message_id— identifier for every message sent
Publish_result (for an Enqueue to a Multiconsumer Queue or Topic)
• destination— where the message was sent
• message_id— identifier for every message sent
Receive_result (for a Dequeue from a Queue or Topic)
• destination— where the message was sent
• message_set— the set of messages dequeued

B2B / AQ Enhancements 2--16


AQ Response Messages (Cintinued)
The response to a Register request uses the AQXmlRegisterResponse method, which consists
of status_response.
The response to a Commit request uses the AQXmlCommitResponse method, which consists
of status_response.
The response to a Rollback request uses the AQXmlRollbackResponse method, which consists
of status_response.
In case of an error in any of the above requests, a FAULT is generated. The FAULT element
consists of:
faultcode - error code for fault
faultstring - indicates a client error or a server error. A client error means that the request is not
valid. Server error indicates that the AQ servlet has not been set up correctly
detail, which consists of status_response

B2B / AQ Enhancements 2--17


AQ Communication using HTTP
An Example
• This example shows an Order Entry message
in its IDAP format.

AQ Communication Using HTTP(S)


An enqueue request has the following format:
<?xml version="1.0"?>
<Envelope xmlns="http://www.oracle.com/schemas/IDAP/envelope">
<Body>
<AQXmlSend xmlns = "http://www.oracle.com/schemas/AQ/access">
<producer_options>
<destination>OE.OE_NEW_ORDERS_QUE</destination>
</producer_options>
<message_set>
<message_count>1</message_count>
<message>
<message_number>1</message_number>
<message_header>
<correlation>XML_ADT_SINGLE_ENQ</correlation>
<sender_id>
<agent_name>john</agent_name>
</sender_id>
</message_header>
<message_payload>

B2B / AQ Enhancements 2--18


AQ Communication Using HTTP(S) (Continued)

<ORDER_TYP>
<ORDERNO>100</ORDERNO>
<STATUS>NEW</STATUS>
<ORDERTYPE>NORMAL</ORDERTYPE>
<ORDERREGION>EAST</ORDERREGION>
<CUSTOMER>
<CUSTNO>1001233</CUSTNO>
<CUSTID>JOHN</CUSTID>
<NAME>AMERICAN EXPRESS</NAME>
<STREET>EXPRESS STREET</STREET>
<CITY>REDWOOD CITY</CITY>
<STATE>CA</STATE>
<ZIP>94065</ZIP>
<COUNTRY>USA</COUNTRY>
</CUSTOMER>
<PAYMENTMETHOD>CREDIT</PAYMENTMETHOD>
<ITEMS>
<ITEMS_ITEM>
<QUANTITY>10</QUANTITY>
<ITEM>
<TITLE>Perl</TITLE>
<AUTHORS>Randal</AUTHORS>
<ISBN>ISBN20200</ISBN>
<PRICE>19</PRICE>
</ITEM>
<SUBTOTAL>190</SUBTOTAL>
</ITEMS_ITEM>
</ITEMS>
<CCNUMBER>NUMBER01</CCNUMBER>
<ORDER_DATE>2000-08-23 0:0:0</ORDER_DATE>
</ORDER_TYP>
</message_payload>
</message>
</message_set>
</AQXmlSend>
</Body>
</Envelope>

B2B / AQ Enhancements 2--19


AQ Communication Using HTTP or
HTTP(S)

Oracle9i
6
4
AQ Servlet
1 AQ Queue
2

AQ client HTTP(S)

AQ Client-Server Communication Using HTTP and HTTP(S)


The algorithm for processing requests is as follows:
• Client connects and establishes an HTTP(S) session with the HTTP(S) server.
• The request is sent to the remote server using HTTP POST.
• The Database server authenticates the AQ agent.
• The AQ servlet is invoked on the remote server.
• The AQ servlet parses the XML message, performs security checks, and performs the
requested action.
• A response is transmitted to the client as an XML message.

If the client has a transaction ID in the IDAP message header, then the AQ operations are
performed in the context of this transaction. When the response message is generated,
the transaction ID is sent back as a cookie

B2B / AQ Enhancements 2--20


Propagation of Messages Between AQ’s
Using HTTP
• AQ messages between queues on different
databases can be propagated over HTTP.
• Such a propagation can be across firewalls.

Oracle9i Oracle9i

Source AQ Servlet Destination


e HTTP

Propagation of Messages using HTTP


In release 9i, AQ propagation can be enabled over HTTP and HTTPS as well as Net8. The
primary advantage of using an open protocol like HTTP is that, unlike Net8 it is easy to
configure for firewalls.
HTTP based propagation uses the infrastructure for internet to access AQ.
The background process doing propagation pushes the messages to an AQ Servlet which
enqueues them into the destination database.

B2B / AQ Enhancements 2--21


Enabling HTTP Propagation

• Steps required to configure HTTP propagation


– Enable the source database for Java and
XML.
– Create DBLINK on source Database with
protocol HTTP, Host and port of the
webserver.
– Create and deploy the AQ servlet.
– Ensure that AQ HTTP Agent is authorized to
perform AQ operation.
• Then invoke propagation at the source queue.

The additional steps to configure for propagation usning HTTP are:


•The source database should be created for running java and XML.
•The dblink at the source database should specify the protocol as http. The host and the
port of the webserver running the AQ servlet should also be specified. The username,
password of the dblink will be used for authentication with the webserver.
For Example if webserver is on webdest.acme.com, at port 8081, then the
connect string of the database would look like:
(DESCRIPTION=(ADDRESS=(PROTOCOL=http) (HOST=
webdest.acme.com)(PORT=8081)))
The database link for would be created (where John is a user with password
welcome).
CREATE PUBLIC DATABASE LINK destq CONNECT TO john IDENTIFIED
BY welcome USING
‘(DESCRIPTION=(ADDRESS=(PROTOCOL=http) (HOST=
webdest.acme.com)(PORT=8081)))’
When using the SSL, Oracle wallet should be created for the user. The wallet
is used for secure communication of messages over HTTP with
encryption, however, it is not used for authentication of user in AQ.

B2B / AQ Enhancements 2--22


The additional steps to configure for propagation usning HTTP (Continued)
• An AQ servlet which connects to the destination database should be deployed. Create a
class AQPropServlet that extends AQxmlServlet that is provided with AQ. This servlet
should deployed on the webserver in the path aqserv/servlet and connect to the destination
database. Make sure that the AQ HTTP agent (John) is authorized to perform AQ
operation. This is done by the following two steps at the destination database.
– Register the AQ agent.
dbms_aqadm.create_aq_agent(agent_name => 'John', enable_http => true);
– Map the AQ agent to a database user.
dbms_aqadm.enable_db_access(agent_name =>'John',
db_username=>'CBADM')‘
• Start propagation at the source queue site by calling the
dbms_aqadm.schedule_propogation procedure.
– DBMS_AQADM.SCHEDULE_PROPAGATION( ‘src_queue’, ‘destq’);

B2B / AQ Enhancements 2--23


Security using HTTP

• Security is provided by the Web Server


– Oracle9iAS uses SSL
• Authentication can be performed in two ways:
– User/Password based authentication
– The user is enters encrypted username/password
– Details are sent to the database over SSL,
– Database then grants or denies access

– Digital Certificate based authentication Is this


now available?
Client obtains a digital certificate from an external
authority which is stored on the client machine. The
browser then sends the client’s X.509 certificate to
the server and it is checked against a library of
certificates for verification.

Security using HTTP


• For Oracle9iAS, security will be provided by the SSL (Secure Socket Layer) protocol.
SSL sits between the application layer protocol (eg. HTTP) and the low-level transport
protocol (TCP/IP). It handles the details of security management using public key
cryptography to encrypt all client/server communication.
• SSL includes support for server certificates only. It provides authentication of the server,
confidentiality and integrity. Server authentication requires that the server obtains a digital
certificate from a certificate authority (CA) and install it on its site. The digital format
used in SSL is X.509
• Here’s how server authentication works:
• A user connects to the secure site using HTTPS
• The server sends its X.509 certificate (which has the server’s public key) to the client
• The client application checks to see whether a trusted certificate authority signed the key.
If one didn’t, the client asks the user if the key can be trusted and proceeds as directed.
• The client generated an asymmetric key for the session, which is encrypted with the
server’s public key and sent back to the server. This new key is used to encrypt all
subsequent transactions.
• Client authentication is done using SSL also, thus once the client has authenticated the
server, the server establishes the client’s identity. We could accomplish this in one of the
following ways:

B2B / AQ Enhancements 2--24


Security using HTTP (Continued)
• User/Passwd based authentication
– The user is required to enter a username/password which is encrypted and then send
to the server over SSL. The server checks the users credentials against its
userid/password database and then grants access to the user. Note that since all of the
data is going over an SSL connection, it cannot be stolen during transmission. Also,
no malicious server can successfully pretend to be the original webserver, in an
attempt to steal the user’s password.
• Digital Certificate based authentication
– SSL certificate based client authorization: In this model, the client has to obtain its
own digital certificate from an external CA and install it on the client machine (or
possibly a smartcard). The browser then sends the client’s X.509 certificate to the
server. The server checks this certificate from a library of existing certificates or from
a certificate authority (CA) to verify the client’s identity and then grants appropriate
access to the user.

B2B / AQ Enhancements 2--25


AQ Communication Using Email

Oracle9i
AQ client
XML messages
over SMTP AQ AQ Queue
Servlet

Web
Server
OID

Oracle
Email Server

To use SMTP protocol:


•The client constructs the request (send, receive, or register) in the specified XML format
and signs it
•The message is sent to the database’s e-mail address <database-name>@<domain-name>
•The e-mail server receives the message, parses it, and sends an HTTP POST message
containing the client request
•The AQ Servlet is invoked to process the request
•A response is then sent back to the client as an XML formatted e-mail.

B2B / AQ Enhancements 2--26


Setting up AQ to use Email
• Currently, these operations are supported by Oracle
Email Server 5.5 and above.
• In addition steps as defined in the set for Internet
Access for AQ perform the following steps:
– Set up Web Server: Configure web server to receive
requests from a user called
ORACLE_SMTP_AGENT.
– Set up Oracle Email Server:
– Run $ORACLE_HOME/admin/ emailrule.sql to
create an AQ schema on the email server
database.
– Create an email account for the destination
database.
– Set up an email rule for the destination
database.
• Now clients can write IDAP requests and send via email
to AQ Servlet.

Setting up AQ to use Email


Currently, these operations are supported by Oracle Email Server 5.5 and above. Please
follow steps as defined in the set for Internet Access for AQ. In addition please perform the
following steps:
•Set up Web Server: Configure web server to receive requests from a user called
ORACLE_SMTP_AGENT. This user would be used to access the AQ Servlet. In
addition also specify setEmailServerAddr or setEmailServerHost in init() method of AQ
Servlet.
•Set up Oracle Email Server:
• Run $ORACLE_HOME/admin/emailrule.sql to create an AQ schema on the email
server database.
• Create an email account for the destination database - database in which the AQ
operations are to be performed
• Set up an email rule for the destination database, so that it can route the AQ
requests to the AQ Servlet on the web server.
•Now clients can write IDAP requests and send via email to AQ Servlet.

B2B / AQ Enhancements 2--27


AQ Privileges for Internet Users

• The privileges for an internet user can be


represented as the union of privileges of
several database users.
• The internet user is registered for Internet
access in the database by using
DBMS_AQADM.CREATE_AQ_AGENT.
• Each AQ agent is then granted mapped to one
or more database users using
DBMS_AQADM.ENABLE_DB_ACCESS.
• AQ privileges are granted to the database
users.

B2B / AQ Enhancements 2--28


Accessing AQ as an Internet User
Example

https://aq.us.oracle.com:8000/aqserv/servlet
https://aq.us.oracle.com:8000/aqserv/servlet
/AQTestServlet
/AQTestServlet

Db_user2
AQ
i_user1 AQ Agent
Servlet
Database

Authorization
Module

Accessing AQ as an Internet User: Example


Consider an internet user i_user1. Inside the authorization module, we have associated i_user1
with database users db_user1 and db_user2 (using the authorization module functions, covered
later). User db_user1 has privileges (enqueue and dequeue) on q1 and q2, and user db_user2
has privileges on q2 and q3.
If i_user1 issues an enqueue request on q3, the AQ servlet will obtain the appropriate database
username from the Authorization module function get_db_user_for_agent_command. In this
case, the function would return the username db_user2 because it is the only username in
i_user1’s privilege set that is allowed to enqueue on q3. The AQ servlet would then proxy as
this database username when issuing the command.
If a request arrived for enqueue on q2, the Authorization module could return either db_user1
or db_user2 since both have privileges on q2.
If a request is issued on q4, since neither db_user1 or db_user2 have privileges on this queue,
the Authorization module would signal an authorization error.

B2B / AQ Enhancements 2--29


Authorization Functions

• To create and manage internet users, use the


following:
– DBMS_AQADM.CREATE_AQ_AGENT
– DBMS_AQADM.ALTER_AQ_AGENT
– DBMS_AQADM.DROP_AQ_AGENT

DBMS_AQADM.CREATE_AQ_AGENT(
DBMS_AQADM.CREATE_AQ_AGENT(
agent_name
agent_name IN
IN VARCHAR2,
VARCHAR2,
certificate_location
certificate_location IN
IN VARCHAR2
VARCHAR2 DEFAULT
DEFAULT NULL,
NULL,
enable_http
enable_http IN
IN BOOLEAN
BOOLEAN DEFAULT FALSE,
DEFAULT FALSE,
enable_smtp
enable_smtp IN
IN BOOLEAN
BOOLEAN DEFAULT
DEFAULT FALSE,
FALSE,
enable_anyp
enable_anyp IN
IN BOOLEAN
BOOLEAN DEFAULT FALSE)
DEFAULT FALSE)

DBMS_AQADM.CREATE_AQ_AGENT
The paramter description is as follows:
agent_name:
• Specifies the username of the internet user. This function enforces the restriction that two internet
users cannot share the same username, and will throw an error if this username has already been
created with a previous call to CREATE_AQ_USER.
Certificate_location: Will be used later for authentication purposes. Presently ignored.
Enable_http: Specifies whether the agent should be enabled for HTTP access.
This procedure will throw an error if none of the protocol access
methods are enabled.
Enable_smtp:Specifies whether the agent should be enabled for SMTP access.
This procedure will throw an error if none of the protocol access
methods are enabled.
Enable_anyp: Specifies whether the agent should be enabled for all access types.
If this parameter is set to TRUE, all other enable inputs are ignored.
This procedure will throw an error if none of the protocol access
methods are enabled.
Example:
DBMS_AQADM.CREATE_AQ_AGENT(
agent_name => ‘KURT’, enable_http => TRUE, enable_smtp => TRUE,
certificate_location =>
‘ldap://ldaphst:389
cn=kurt,cn=OracleDBAgents,cn=db1,cn=acme,cn=com’);
B2B / AQ Enhancements 2--30
Authorization Functions

• To manage database privileges for internet


users, use the following:
– DBMS_AQADM.ENABLE_DB_ACCESS
– DBMS_AQADM.DISABLE_DB_ACCESS

DBMS_AQADM.ENABLE_DB_ACCESS(
DBMS_AQADM.ENABLE_DB_ACCESS(
agent_name
agent_name IN
IN VARCHAR2,
VARCHAR2,
db_username
db_username IN
IN VARCHAR2
VARCHAR2 ))

DBMS_AQADM.DISABLE_DB_ACCESS(
DBMS_AQADM.DISABLE_DB_ACCESS(
agent_name
agent_name IN
IN VARCHAR2,
VARCHAR2,
db_username
db_username IN
IN VARCHAR2
VARCHAR2 ))

DBMS_AQADM.ENABLE_DB_ACCESS and DISABLE_DB_ACCESS


Parameter Description
agent_name Specifies the username of the internet user to be granted or to lose the privileges
of a database username. This procedure will throw an error is this username has not already
been created with a previous call to CREATE_AQ_AGENT.
db_username This is the database username that the internet user will add to or remove from
his or her privilege set. This procedure will throw an error if this username does not exist.

Examples :
• DBMS_AQADM.ENABLE_DB_ACCESS( agent_name => ‘KURT’,
db_username=> ‘AQ_USER_ENQ’ );
• DBMS_AQADM.ENABLE_DB_ACCESS(agent_name => ‘KURT’,
db_username=> ‘AQ_USER_DEQ’ );

B2B / AQ Enhancements 2--31


Managing Internet Users

• The data dictionary view AQ$INTERENT_USERS


can be used to manage Internet users.
• Shows the database usernames associated
with an agent name and their protocols

Agent_name db_username http_en smtp_en

scott system YES NO


scott buyer YES NO
Kurt Aq_user_enq YES YES

Kurt Aq_user_deq YES YES

Managing Internet Users


SQL> describe aq$internet_users;

Name Null? Type


-------------- ----- ------------
AGENT_NAME VARCHAR2(30)
DB_USERNAME VARCHAR2(30)
HTTP_ENABLED VARCHAR2(4)
SMTP_ENABLED VARCHAR2(4)

B2B / AQ Enhancements 2--32


Data Dictionary Structures

• SYSTEM.AQ$_Internet_Agents
– Maintains the information that is specific to
each internet user
– Includes protocols and a spare column for
future authentication purposes
– Primary key is the internet username

Agent_name protocol spare1

scott 2

Admin 5

B2B / AQ Enhancements 2--33


Data Dictionary Structures

• SYSTEM.AQ$_Internet_Agent_Privs
– Stores the agent name to database user
mapping
– Internet username used as a foreign key to
(AQ$_internet_agents).
agent_name db_username

scott system

scott buyer
Admin SYS
Admin seller

AQ$_Internet_agent_privs
This table is created upon AQ startup in SYSTEM and modified by the Authorization Module
functions. Additionally, when a database user is dropped, all entries in this table with that
database username are removed from the table.

B2B / AQ Enhancements 2--34


Secure Message Transmission with AQ

• If HTTP(S) is being used to transmit AQ


messages, the underlying network protocol
will take care of secure transmission.
• If the transmission method is Oracle Net,
confidentiality of messages using digital
enveloping can be achieved through the
Advanced Security Option of Oracle Net
Services

B2B / AQ Enhancements 2--35


Using XML Payloads with AQ

• The queue table is created specifying the


payload type as an object type.
• The object type can contain an attribute of type
XMLType.
• XMLType stores XML documents internally as
NCLOBs.
• XMLType columns can be queried using the
XML operators ExistsNode() and
SchemaMatch().

Using XML Payloads with AQ


To use XML payloads, you create a queue table with the payload type set to an Oracle object
type. This can be any object type, or it can contain an attribute of type XMLType. The
XMLType stores XML documents as CLOBs. If an object type is used which does not contain
an XML attribute, the XML nodes are translated into object type attributes.

B2B / AQ Enhancements 2--36


Using XML Payloads with AQ
Subscriptions
The steps to create and use XML Payloads in AQ
are:
– Create an object type with XMLTYPE
attribute.
– Create a Queue table that uses the object
type.
– Create a queue in the queue table.
– Create procedures to enqueue and
dequeue messages.
– Add subscribers to the queue.

Using XML Payloads with AQ – An Example:


•Create Object with XML Type attribute.
CREATE TYPE order_xml_typ as OBJECT ( orderno NUMBER, details
XMLTYPE);
•Create the Queue Table
BEGIN
dbms_aqadm.create_queue_table(
queue_table => 'OS_orders_pr_mqtab',
comment => 'Overseas Shipping MultiConsumer Orders queue table',
multiple_consumers => TRUE,
queue_payload_type => 'OS.order_xml_typ',
compatible => '8.1');
END;
•Create Queue in the Queue Table.
BEGIN
dbms_aqadm.create_queue (
queue_name => 'OS_bookedorders_que',
queue_table => 'OS_orders_pr_mqtab');
END;

B2B / AQ Enhancements 2--37


Using XML Payloads with AQ – An Example (Continued)
•Create Procedures for enqueue and dequeue operations.
•Add a rule-based subscriber (for Overseas Shipping) to the Booked orders queues with
Transformation Overseas Shipping handles all non-US orders: */
DECLARE
subscriber aq$_agent;
BEGIN
subscriber := aq$_agent('Overseas_Shipping','OS.OS_bookedorders_que',null);
dbms_aqadm.add_subscriber(
queue_name => 'OE.OE_bookedorders_que',
subscriber => subscriber,
rule => 'tab.user_data.orderregion = ''INTERNATIONAL'''
transformation => 'OS.OE2XML');
END;

B2B / AQ Enhancements 2--38


Using XML Payloads with AQ

• AQ is integrated with a server-based data


transformation engine.
• The payload for IDAP conformant messages is
mapped automatically to an object type payload if
the XML values and object type attributes match
exactly.
• DBMS_TRANSFORM allows you to convert AQ
messages between object types, enabling you to:
– Enqueue or dequeue messages from a queue in
the format of your choice
– Specify the desired message format when
subscribing to queues

Using XML Payloads with AQ (continued)


Transformation is a key requirement for application integration and business to business e-
commerce. Existing applications that need to be integrated might have data in different formats.
Thus any application integration solution requires a way to transform data.

Since Oracle’s aim is to provide a complete solution for application integration, Oracle9i
introduces a transformation tool. The transformation engine is integrated with Advanced
Queues. The engine supports those transforms expressible in SQL and PL/SQL and transform
data represented as relational scalar data or as Abstract Datatypes (ADTs). Since XML is the
format of choice of many B2B applications, the transformation engine also supports XSLT
transformations of XML documents. XML documents which conform to the IDAP model must
use values and attributes which match the Oracle object payload type exactly for the
transformation to take place.

B2B / AQ Enhancements 2--39


Messaging Gateways

ORACLE
MQ Series
Gateway
Links
Agent
Advanced Queues
Rendezvous

Gateway to third party messaging systems


– MQ Series
– TIBCO
• Configuration similar to AQ propagation
• Focuses on robustness, scalability, and high
performance

Messaging Gateway
Oracle Messaging Gateway propagates messages between Oracle AQ (generic queues) and
non-Oracle messaging systems. Propagation is materialized with the help of a gateway agent
and the agent represents a running instance of the Messaging Gateway. Oracle Messaging
Gateway supports the following:
• propagation between AQ queues and MQSeries queues
• propagation between AQ queues and TIBCO Rendezvous queues.

Oracle Messaging Gateway provides a common interface for the gateway agent to
communicate with the non-Oracle messaging systems for messaging operations and
administrative operations. An implementation of an interface is called a driver. An instance of a
driver, which runs in the gateway agent address space as a client of a non-Oracle messaging
system, is referred as a messaging system link. Messages are enqueued and dequeued by the
gateway agent through messaging system links.

B2B / AQ Enhancements 2--40


Messaging Gateways
• Messaging Gateways are used to propagate
messages between Oracle AQ and non-Oracle
messaging systems.
• Messaging gateways support both queues
(point-to-point model) and topics
(publish/subscribe model)
• Support IBM MQ Series and TIBCO
Rendezvous systems
• Quality of propagation depends on the queue
drivers supported by the messaging systems

Messaging Gateway (continued)


Oracle Messaging Gateway propagates messages between Oracle AQ and non-Oracle
messaging systems such as IBM MQSeries and TIBCO Rendezvous by dequeueing messages
from a propagation source in one messaging system and enqueuing them to a propagation
destination in another messaging system.
Oracle Messaging Gateway supports both queues (point-to-point model) and topics
(publish/subscribe model) as propagation sources and destinations. However, because of
limitations in the functionality and APIs provided by different messaging systems, not all
combinations of sources and destinations are supported for propagation purposes.
The quality of service of message propagation depends on whether the queue drivers involved
in the propagation job support transactions and whether the messages are persistent. If both the
source queue driver and the destination queue driver of a propagation job support transaction
and the messages in the source queue are persistent, exactly-once delivery is guaranteed.
Otherwise, at-most-once delivery is guaranteed which means that messages may get lost when
the messaging systems or the messaging gateway agent fails.

B2B / AQ Enhancements 2--41


Summary

In this lesson, you should have learned about:


– How to use iDAP to transmit AQ messages
over the Internet.
– How an internet user is authorized to
access Oracle AQ.
– AQ message propogation between Oracle
Databases using HTTP and email.
– Setup AQ to use HTTP or HTTPS.
– Setup AQ to use email.
– Structure of XML payloads under IDAP
– Messaging gateways.

B2B / AQ Enhancements 2--42


3
B2B Communication
from One Business Process to Another

Message Transformations

B2B / AQ enhancements 3 - 1
Objectives

After this lesson, you should be able to:


• Define transformation mapping using
DBMS_TRANSFORM package
• Use the transformation mapping in AQ
operations

B2B / AQ enhancements 3 - 2
Overview

• Enterprise Application Integration can be


defined as the coordination and
synchronization of multiple, heterogeneous
applications within or across applications.
• Existing applications that need to be integrated
might have data in different formats.
• Any application integration solution requires a
way to transform data.
• In Oracle9i, an infrastructure is provided for
users to specify their transformation mapping
to be used in AQ operations.

B2B / AQ enhancements 3 - 3
Message Transformation Concepts

Oracle CRM
Application
Web
Application

Transformation Oracle AQ

Custom built
Application

Message Transformation Concepts


This picture depicts the usual deployment of message transformation. Different applications
Oracle CRM application, custom-built application, and web application may have their own
message format.
The new functionality provides the following:
Allows users to define the mappings from one Oracle object type to another using
DBMS_TRANSFORM package.
Use the above defined mappings for AQ operations such as enqueue, dequeue, and
propagation.
In the above example, when the Oracle CRM or custom-built app or web application enqueues
the messsage into an AQ queue automatically the message will be tranformed to the message
format of the queue. Similarly at dequeue, the message will be automatically transformed from
the queue format to the format of the application.

B2B / AQ enhancements 3 - 4
Message Transformation Concepts

• Mappings are defined as expressions from


source type to destination type
• Expression can be either SQL, PL/SQL, or Java
stored functions
• Expression can be defined for the entire
destination type or for each attribute of the
destination type
execute
execute DBMS_TRANSFORM.MODIFY_TRANSFORMATION(
DBMS_TRANSFORM.MODIFY_TRANSFORMATION(
schema
schema =>
=> ’SALES’,
’SALES’,
name
name =>
=> ’MYMAP’,
’MYMAP’,
attribute_number
attribute_number =>
=> 4,
4,
Transformation
Transformation =>
=> ’’’+1.’’||source.user_data.ph_num’);
’’’+1.’’||source.user_data.ph_num’);

Message Transformation Concepts


In the example above, we are calling the transformation routine
MODIFY_TRANSFORMATION to transform the phone numbers from an American
application into an international phone number format. The transformation engine will append
the country code for the United States(+1) to the beginning of each American phone number.
The PL/SQL functions used for mappings can be implemented as either PL/SQL, Java, or
external C callout. This provides an hook to integrate with third-party tranformation vendor.
XSLT transformation can be defined for XMLType attributes of an object type.
The transformation may be defined in two ways:
A separate expression specified for each attribute of the target type. This representation is more
readable and allows the application fine grain control over the transformation.
A single PL/SQL function that returns an object of the target type or the constructor of the
target type. The application may prefer this representation for very simple transformations or
transformations that are not easily broken down into independent transformations for each
attribute.

B2B / AQ enhancements 3 - 5
Message Transformation with AQ

• The defined mappings can be used for AQ


operations - enqueue, dequeue, or propagation
• Mapping can be specified in enqueue_options
at enqueue
• Mapping can be specified with add_subscriber
or in dequeue_options to be used for
propagation (for remote subscriber) and
dequeue

Message Transformation with AQ


Since transformations and messaging often go hand in hand, it makes sense to allow the AQ
messaging system to automatically invoke the needed transformations
Users can specify the transformation mapping to be used at various points - enqueue, dequeue,
and propgation.
Trnasformation mapping for enqueue has to be specified in enqueue options.
For specifying transformation mapping for dequeue there are two options - in dequeue options
and in add_subscriber. Mapping specified at add_subsciber will be called every time the
specified subscriber dequeues a message. If the subscriber is a remote queue (for propagation),
the mapping will be used before propagating to the subscriber. If you specify the transformation
mapping at both dequeue options and add_susbcriber, the mapping specified in dequeue
options will override the mapping specified at add_subscriber.

B2B / AQ enhancements 3 - 6
Defining Message Transformations

Execute
Execute DBMS_TRANSFORM.CREATE_TRANSFORMATION(
DBMS_TRANSFORM.CREATE_TRANSFORMATION(
schema
schema =>
=> ’SCOTT’,
’SCOTT’, name
name =>
=> ’MYMAP’,
’MYMAP’,
from_schema
from_schema =>
=> ’SCOTT’,
’SCOTT’, from_name
from_name =>
=> ’CART_POINT’
’CART_POINT’
to_schema
to_schema =>
=> ’SCOTT’,
’SCOTT’, to_type
to_type =>
=> ’POLAR_POINT’);
’POLAR_POINT’);

Execute
Execute DBMS_TRANSFORM.MODIFY_TRANSFORMATION(
DBMS_TRANSFORM.MODIFY_TRANSFORMATION(
schema
schema =>
=> ’SCOTT’,
’SCOTT’, name
name =>
=> ‘MYMAP’,
‘MYMAP’,
attribute_number
attribute_number =>=> 1,
1,
transformation
transformation =>
=>
’sqrt(source.user_data.X
’sqrt(source.user_data.X ** source.user_data.X
source.user_data.X ++
source.user_data.Y
source.user_data.Y ** source.user_data.Y)’
source.user_data.Y)’ );
);

Execute
Execute DBMS_TRANSFORM.MODIFY_TRANSFORMATION(
DBMS_TRANSFORM.MODIFY_TRANSFORMATION(
name
name =>
=> ‘MYMAP’,
‘MYMAP’, attribute_number
attribute_number =>
=> 2,
2,
transformation_expression
transformation_expression =>
=> ‘atan(source.
‘atan(source.
user_data.Y
user_data.Y // source.user_data.X)’
source.user_data.X)’ );
);

Specifying Message Transformations


In this example, we use a transformation to convert the ADT Cartesian_point into the ADT
Polar_point by specifying a separate expression for each attribute.
Cartesian_point (
x NUMBER,
y NUMBER)
Polar_point (
r NUMBER,
theta NUMBER)

The mapping between the two sets of coordinates is defined as:


• r = sqrt(x^2 + y^2)
• theta = atan(y/x)

B2B / AQ enhancements 3 - 7
Defining Message Transformations

CREATE
CREATE FUNCTION
FUNCTION map_cart_pt
map_cart_pt ((
SOURCE
SOURCE scott.polar_point)
scott.polar_point)
RETURNS
RETURNS scott.cartesian_point
scott.cartesian_point
BEGIN
BEGIN
RETURN
RETURN scott.cartesian_point(
scott.cartesian_point(
SQRT(source.X*source.X
SQRT(source.X*source.X ++ source.Y*source.Y),
source.Y*source.Y),
atan(source.Y/source.X)
atan(source.Y/source.X)
);
);
END;
END;

Execute
Execute DBMS_TRANSFORM.CREATE_TRANSFORMATION(
DBMS_TRANSFORM.CREATE_TRANSFORMATION(
schema
schema =>
=> ’SCOTT’,
’SCOTT’, name
name =>
=> ’MYMAP’,
’MYMAP’,
from_schema
from_schema =>
=> ’SCOTT’,
’SCOTT’, from_name
from_name =>
=> ’CART_POINT’
’CART_POINT’
to_schema
to_schema =>
=> ’SCOTT’,
’SCOTT’, to_type
to_type =>
=> ’POLAR_POINT’,
’POLAR_POINT’,
transformation
transformation =>
=> ’MAP_CART_PT(source.user_data)’);
’MAP_CART_PT(source.user_data)’);

Specifying Message Transformations


In this example, we use a transformation to convert the ADT Cartesian_point into the ADT
Polar_point by specifying a PL/SQL function.
Cartesian_point (
x NUMBER,
y NUMBER)
Polar_point (
r NUMBER,
theta NUMBER)

The mapping between the two sets of coordinates is defined as:


• r = sqrt(x^2 + y^2)
• theta = atan(y/x)

B2B / AQ enhancements 3 - 8
XML Transformations

• Oracle9i supports a new data type ‘XMLType’to


efficiently handle XML data.
• Transformation mappings can be defined from
Oracle object to XML and from XML to Oracle
object.
• XSLT transformations can be used to transfrom
data from one XML format to another.
• SYS_XMLGEN, XML Parser and XML Processor
functionality can be used to define XML
Transformations.

XML Transformations
An Example:
Create type Ord_xml_typ as object ( orderno number, details
XMLType);
create function Ord2XML (in_ord OE.Order_typ)
return OE.Ord_xml_typ as
xm SYS.XMLType;
new_order OE.Ord_xml_typ;
begin
select sys_xmlgen(in_ord) into xm from dual;
new_order:= OE.Ord_xml_typ(in_ord.orderno,xm);
return new_order;
End Ord2XML;/

execute DBMS_TRANSFORM.CREATE_TRANSFORMATION(
schema => ’OE’, name =>’Obj2XML’,
from_schema => ‘OE’, from_name => ’OE.Order_typ’,
to_schema => ’OE’ to_type=>’OE.Order_xml_typ’,
transformation => ’Ord2XML(source.user_data)’);

B2B / AQ enhancements 3 - 9
DBMS_TRANSFORM Package

• A new package has been added to the


database.
• DBMS_TRANSFORM provides:
– An API to create, alter, and drop
transformations.
– An interface to invoke the transformation
runtime engine.

DBMS_TRANSFORM.CREATE_TRANSFORMATION
DBMS_TRANSFORM.CREATE_TRANSFORMATION
DBMS_TRANSFORM.MODIFY_TRANSFORMATION
DBMS_TRANSFORM.MODIFY_TRANSFORMATION
DBMS_TRANSFORM.DROP_TRANSFORMATION
DBMS_TRANSFORM.DROP_TRANSFORMATION
DBMS_TRANSFORM.COMPUTE
DBMS_TRANSFORM.COMPUTE

B2B / AQ enhancements 3 - 10
DBMS_TRANSFORM Package

DBMS_TRANSFORM.CREATE_TRANSFORMATION
DBMS_TRANSFORM.CREATE_TRANSFORMATION ((
schema
schema IN
IN VARCHAR2,
VARCHAR2,
name
name IN
IN VARCHAR2,
VARCHAR2,
from_schema
from_schema IN
IN VARCHAR2,
VARCHAR2,
from_type
from_type IN
IN VARCHAR2,
VARCHAR2,
to_schema
to_schema IN
IN VARCHAR2,
VARCHAR2,
to_type
to_type IN
IN VARCHAR2,
VARCHAR2,
transformation
transformation IN
IN VARCHAR2
VARCHAR2 default
default NULL)
NULL)

DBMS_TRANSFORM.DROP_TRANSFORMATION
DBMS_TRANSFORM.DROP_TRANSFORMATION ((
schema
schema IN
IN VARCHAR2,
VARCHAR2,
name
name IN
IN VARCHAR2
VARCHAR2 ))

DBMS_TRANSFORM Package
DBMS_TRANSFORM.CREATE_TRANSFORMATION
• Creates a transformation of the specified name that transforms an object of the source type
to an object of the destination type.
• PROCEDURE CREATE_TRANSFORMATION(
• schema IN VARCHAR2,
– name IN VARCHAR2,
– from_schema IN VARCHAR2,
– from_type IN VARCHAR2,
– to_schema IN VARCHAR2,
– to_type IN VARCHAR2,
– transformation IN VARCHAR2 default null)

DBMS_TRANSFORM.DROP_TRANSFORMATION
• Drops a given transformation.
– DBMS_TRANSFORM.DROP_TRANSFORMATION (
– schema IN VARCHAR2,
– name IN VARCHAR2 )

B2B / AQ enhancements 3 - 11
DBMS_TRANSFORM Package

DBMS_TRANSFORM.ADD_ATTRIBUTE_MAP
DBMS_TRANSFORM.ADD_ATTRIBUTE_MAP ((
schema
schema IN
IN VARCHAR2,
VARCHAR2,
name
name IN
IN VARCHAR2,
VARCHAR2,
attribute_number
attribute_number IN
IN NUMBER,
NUMBER,
transformation
transformation IN
IN VARCHAR2)
VARCHAR2)

FUNCTION
FUNCTION DBMS_TRANSFORM.COMPUTE_TRANSFORMATION
DBMS_TRANSFORM.COMPUTE_TRANSFORMATION ((
message
message IN
IN “<ADT_1>”,
“<ADT_1>”,
transformation_schema
transformation_schema IN
IN VARCHAR2,
VARCHAR2,
transformation_name
transformation_name IN
IN VARCHAR2,
VARCHAR2,
transformation_message
transformation_message OUT
OUT “<ADT_1>”)
“<ADT_1>”)

DBMS_TRANSFORM Package
DBMS_TRANSFORM.MODIFY_TRANSFORMATION
Modifies transformation mapping for the specified attribute of the target type. An attribute
number zero must be specified for a scalar target type. If the target type is an object type, then
the expression must be a function returning an object of the target type or a constructor
expression for the target type.
PROCEDURE MODIFY_TRANSFORMATION(
schema IN VARCHAR2,
name IN VARCHAR2,
attribute_number IN NUMBER,
transformation IN VARCHAR2)

DBMS_TRANSFORM.COMPUTE
Transforms the given message according to the given transformation.
PROCEDURE COMPUTE_TRANSFORMATION(
message IN "<ADT_1>",
transformation_schema IN VARCHAR2,
transformation_name IN VARCHAR2,
transformed_message OUT "<ADT_1>")

B2B / AQ enhancements 3 - 12
Specifying Transformations

• Both the DBMS_AQ.enqueue_options_t and


DBMS_AQ.dequeue_options_t object types
have been updated to include an attribute
called transformation.
• The DBMS_AQADM.ADD_SUBSCRIBER
procedure also has been updated to allow a
transformation to be specified for a
subscription.
execute
execute DBMS_AQADM.ADD_SUBSCRIBER(
DBMS_AQADM.ADD_SUBSCRIBER(
queue_name
queue_name =>
=> 'QS_WS.QS_WS_backorders_q',
'QS_WS.QS_WS_backorders_q',
subscriber
subscriber =>
=> subscriber,
subscriber,
transformation
transformation =>‘QS_WS_trans_backorders’);
=>‘QS_WS_trans_backorders’);

Specifying Transformations
The example shown above creates a queue subscriber for the QS_WS_backorders_q queue,
specifying that the QS_WS_trans_backorders transformation is to be used by default when
retrieving messages from a queue.
Below are the modifications which have been made to DBMS_AQ and DBMS_AQADM.
TYPE enqueue_options_t IS
RECORD(
visibility BINARY_INTEGER NOT NULL DEFAULT ON_COMMIT
relative_msgid RAW(16) DEFAULT NULL,
sequence_deviation BINARY_INTEGER DEFAULT NULL,
transformation VARCHAR2(60) DEFAULT NULL);

TYPE dequeue_options_t IS
RECORD(
consumer_name VARCHARr2(30) DEFAULT NULL,
dequeue_mode BINARY_INTEGER NOT NULL DEFAULT REMOVE,
navigation BINARY_INTEGER NOT NULL DEFAULT NEXT_MESSAGE,
visibility BINARY_INTEGER NOT NULL DEFAULT ON_COMMIT,
wait BINARY_INTEGER NOT NULL DEFAULT FOREVER,
msgid RAW(16) DEFAULT NULL,
correlation VARCHAR2(128) DEFAULT NULL,
transformation VARCHAR2(60) DEFAULT NULL);

B2B / AQ enhancements 3 - 13
Specifying Transformations

• Transformation field in enqueue_options_t can


be used to specify transformation at enqueue

create
create procedure
procedure FwdOrd2Ship(booked_order
FwdOrd2Ship(booked_order
OE.order_typ)
OE.order_typ)
enq_opt
enq_opt dbms_aq.enqueue_options_t;
dbms_aq.enqueue_options_t;
begin
begin
enq_opt.transformation
enq_opt.transformation :=:= ’OE.OE2WS’;
’OE.OE2WS’;
dbms.aq.enqueue(
dbms.aq.enqueue(
queue_name
queue_name =>
=> ’WS.ws_orders_topic’,
’WS.ws_orders_topic’,
enqueue_options
enqueue_options =>
=> enq_opt,
enq_opt,
payload
payload =>
=> booked_order);
booked_order);
end;
end;
//

B2B / AQ enhancements 3 - 14
Specifying Transformations

• Transformation field in dequeue_options_t can


be set to specify transformation at dequeue
time

create
create procedure
procedure FwdOrd2Ship(booked_order
FwdOrd2Ship(booked_order
OE.order_typ)
OE.order_typ)
deq_opt
deq_opt dbms_aq.dequeue_options_t;
dbms_aq.dequeue_options_t;
booked_order
booked_order WS.order_typ_sh;
WS.order_typ_sh;
begin
begin
deq_opt.transformation
deq_opt.transformation :=:= ’OE.OE2WS’;
’OE.OE2WS’;
dbms.aq.dequeue(
dbms.aq.dequeue(
queue_name
queue_name =>
=> ’WS.ws_orders_topic’,
’WS.ws_orders_topic’,
dequeue_options
dequeue_options =>
=> enq_opt,
enq_opt,
payload
payload =>
=> booked_order);
booked_order);
end;
end;
//

B2B / AQ enhancements 3 - 15
Managing Transformations

DBA_TRANSFORMATIONS
USER_TRANSFORMATIONS
Transformation_id NUMBER
owner VARCHAR2(30) NOT NULL
name VARCHAR2(30) NOT NULL
Namespace INTEGER
From_type_schema VARCHAR2(30)
From_type_name VARCHAR2(30)
To_type_schema VARCHAR2(30)
To_type_name VARCHAR2(30)
Type TYPE
Attribute_name VARCHAR2(30)
Transformation_expression VARCHAR2(4000)
comment VARCHAR2(4000)

Data Dictionary Views


Two new data dictionary views have been added to assist in managing transformations:
DBA_TRANSFORMATIONS
USER_TRANSFORMATIONS
The difference between the two views is that USER_TRANSFORMATIONS does not contain
the owner column, and only list transformations owned by the current schema user.
DBA_TRANSFORMATIONS
• Transformation_id: The transformation identifier
• Name: The name of the transformation
• Owner: The owner of the transformation
• Namespace: This is set to 1 for Oracle transformations. Transformations
from third party are in different namespaces.
• From_type_schema: The schema of the source type.
• From_type_name: The name of the source type.
• To_type_schema: The schema of the target type.
• To_type_name: The name of the target type.
• Type: The type of transformation: PL/SQL, SQL, or XSL.
• Attribute_name: The destination attribute name
• Transformation_expression: The transformation expression.

B2B / AQ enhancements 3 - 16
Managing Transformations

• Transformations can be exported and


imported:
– All transformations are exported during a
full database export
– Transformations owned by a user are
exported during a schema level export
• If an AQ queue table is exported, the
transformations corresponding to the queue
table will also be exported.

Managing Transformations
Transformations will be exported on a full database export. Transformations owned by a user
will also be exported on a schema level export. Transformations used by AQ will also be
exported when the corresponding queue table is exported.
In both queue table export and schema level export, the source and target ADTs are also
exported and created on import, if they don’t already exist.

B2B / AQ enhancements 3 - 17
Summary

In this lesson, you should have learned how to:


• List the message transformation types
available
• Transform messages using the API procedures
in the new package DBMS_TRANSFORM

B2B / AQ enhancements 3 - 18

You might also like