Oracle Advanced Queuing and JMS – bridging from AQ to JMS and vice versa

In preparation for our Oracle Open World session ‘Xenogenetics for PL/SQ – Infusing with Java Best Practices and Design Patterns’ – I have been doing a little work on Advanced Queuing in the Oracle RDBMS, as well as on Java Stored Procedures. The objective of this presentation is to bring best practices, design patterns as well as new functionality to the world of PL/SQL from other worlds, such as Java. Interaction between database applications and the rest of the world is an important part of that. And such interaction, especially when we have a need for decoupled interaction, which we frequently should have, Advanced Queues will be used at the database end to support that interaction.

The concept of queuing – and more generally: messaging – has its Java counterpart in JMS, the Java Message Service. The question I then asked myself is: how exactly can I map AQ to JMS and how can I link the two worlds. How can I expose the AQ Queue or Topic in the RDBMS as a JMS Queue or Topic? And how can I consume messages from JMS into the database, possibly to AQ?

AQandJMS

One of my reasons for making the connection between AQ and JMS has to do with another presentation at OOW I will deliver, introducing Complex Event Processing. The database – for example database triggers – is an excellent source for events. And one fine way to database applications to publish their events is through AQ. However, Oracle CEP does not directly tie into AQ, but it does interact with JMS Queues and Topics as event source. By linking AQ to JMS, I can indirectly link AQ to CEP.

Queues defined using Oracle AQ can be connected to JMS, but under certain circumstances only.

1. Java Clients that want to access an AQ Queue can do so using several Oracle specific JAR-files, including the thick (OCI based) JDBC database driver. The approach is demonstrated in the Oracle RDBMS 11gR2 documentation: http://download.oracle.com/docs/cd/E11882_01/server.112/e11013/aq_demo.htm#i1006898

Java Clients that run inside the Oracle RDBMS JServer (Java Stored Procedures) can also access AQ through JMS, in a more direct manner: access AQ over JMS using the Oracle JMS classes that are automatically loaded when the JServer was installed. See the Java API Documentation for Oracle JMS: http://download.oracle.com/docs/cd/B28359_01/server.111/b28392/toc.htm.

2. Alternatively, WebLogic Server can be used to expose the AQ Queue or Topic as a JMS Queue or Topic. WLS 11g (10.1.3.x) supports the configuration of a Foreign JMS Server that uses the Oracle JDBC Driver to connect to the AQ Queue or Topic. It is completely transparent for JMS clients that the underlying Queue or Topic is in fact one implemented in the RDBMS using AQ. Edwin Biemond describes configuration of this WLS JMS-AQ bridge in an excellent blog-article: http://biemond.blogspot.com/2009/07/using-aq-jms-text-message-in-wls-1031.html. Also see the official Oracle documentation on this: http://download.oracle.com/docs/cd/E12839_01/web.1111/e13738/aq_jms.htm#CJAECHCC.

3. Another option for linking AQ to JMS uses a Java Stored Procedure and a ‘normal’ JMS Queue (or Topic) defined for example in WebLogic Server or any other JEE Application Server that provides JMS support. The AQ has a ‘regular’ PL/SQL based listener on the (AQ) Queue. When a message is passed to it, it will invoke a Java Stored Procedure that will then call out to the JMS Queue. Messages received on AQ are thus propagated to JMS and from there available to any JMS enabled component. In the reverse direction, the Java Stored Procedure registers as a listener on a JMS Queue; any message arriving on the JMS Queue is passed to the JSP that then will propagate it to the AQ Queue or Topic.

AQandJMS