Working with Oracle Queues - Choosing between AQ and JMS

45
Ahmed Aboulnaga Technical Director Raastech, Inc. Working with Oracle Queues Choosing between AQ and JMS

Transcript of Working with Oracle Queues - Choosing between AQ and JMS

Page 1: Working with Oracle Queues - Choosing between AQ and JMS

Ahmed Aboulnaga Technical Director Raastech, Inc.

Working with Oracle Queues Choosing between AQ and JMS

Page 2: Working with Oracle Queues - Choosing between AQ and JMS

Slide 2 of 45 © Raastech, Inc. 2011 | All rights reserved.

1. Introduction

2. Overview of Messaging

3. Asynchronous Messaging

4. Oracle Queues

5. Creating Queues

6. Accessing Queues

7. Oracle WebLogic JMS Bridge

8. Performance & Comparison

9. Summary

Agenda

Page 3: Working with Oracle Queues - Choosing between AQ and JMS

Slide 3 of 45 © Raastech, Inc. 2011 | All rights reserved.

INTRODUCTION

Page 4: Working with Oracle Queues - Choosing between AQ and JMS

Slide 4 of 45 © Raastech, Inc. 2011 | All rights reserved.

Applicable Versions

Oracle Database 10g (10.2.0.x)

Oracle Database 11g (11.1.x)

Oracle Application Server 10g (10.1.x)

Oracle WebLogic Server 11g (10.3.3+)

Oracle SOA Suite 10g (10.1.3.x)

Oracle SOA Suite 11g (11.1.1.3+)

Page 5: Working with Oracle Queues - Choosing between AQ and JMS

Slide 5 of 45 © Raastech, Inc. 2011 | All rights reserved.

Applicable Versions

Oracle Database 10g (10.2.0.x)

Oracle Database 11g (11.1.x)

Oracle Application Server 10g (10.1.x)

Oracle WebLogic Server 11g (10.3.3+)

Oracle SOA Suite 10g (10.1.3.x)

Oracle SOA Suite 11g (11.1.1.3+)

Page 6: Working with Oracle Queues - Choosing between AQ and JMS

Slide 6 of 45 © Raastech, Inc. 2011 | All rights reserved.

OVERVIEW OF MESSAGING

Page 7: Working with Oracle Queues - Choosing between AQ and JMS

Slide 7 of 45 © Raastech, Inc. 2011 | All rights reserved.

Introduction to Messaging Synchronous Transactions

Request-response scenarios are synchronous by nature

A request is made by the client application, and a response

is received (on the same thread) by the target application

Page 8: Working with Oracle Queues - Choosing between AQ and JMS

Slide 8 of 45 © Raastech, Inc. 2011 | All rights reserved.

Introduction to Messaging Synchronous Transactions – Under Load

When numerous, simultaneous requests are made, the

target system may be overloaded

Each layer has a limit to how much it can handle:

– Oracle HTTP Server (number of HTTP connections)

– Application Server (number of threads)

– Database Server (number of processes)

Page 9: Working with Oracle Queues - Choosing between AQ and JMS

Slide 9 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle Queue

Introduction to Messaging Asynchronous Transactions May Be the Solution

The client application ‘enqueues’ or ‘produces’ a message

to a queue

The target application can ‘dequeue’ or ‘consume’ the

message at its own pace

Page 10: Working with Oracle Queues - Choosing between AQ and JMS

Slide 10 of 45 © Raastech, Inc. 2011 | All rights reserved.

ASYNCHRONOUS MESSAGING

Page 11: Working with Oracle Queues - Choosing between AQ and JMS

Slide 11 of 45 © Raastech, Inc. 2011 | All rights reserved.

Asynchronous Messaging Overview

Queues allow ‘indirect’ communication

Asynchronous messaging is a form of loosely coupled

distributed communication

Messages are usually structured XML

Senders do not need to have precise knowledge of their

receivers

Page 12: Working with Oracle Queues - Choosing between AQ and JMS

Slide 12 of 45 © Raastech, Inc. 2011 | All rights reserved.

Asynchronous Messaging Payload Format

Messages are almost always in XML format

<ns4:elements xmlns:ns4="http://ns.raastech.com/Order">

<ns4:element>

<ns4:orderNumber>269041</ns4:orderNumber>

<ns4:quantity>12</ns4:quantity>

<ns4:product>Milky Way</ns4:product>

<ns4:price>0.99</ns4:price>

</ns4:element>

</ns4:elements>

Page 13: Working with Oracle Queues - Choosing between AQ and JMS

Slide 13 of 45 © Raastech, Inc. 2011 | All rights reserved.

Asynchronous Messaging When should you consider queues?

When downtime scheduled by target applications do not

synchronize with client applications

When an immediate response is not required

When you want to integrate heterogeneous systems

without the client having precise knowledge of their

receiver

When you want to reduce bottlenecks

When you want to implement priority

When you want to implement a publish-subscribe model,

where a single message can be propagated to multiple

consumers

Page 14: Working with Oracle Queues - Choosing between AQ and JMS

Slide 14 of 45 © Raastech, Inc. 2011 | All rights reserved.

Asynchronous Messaging Queue Approaches

Can be dequeued

based on priority or

enqueue time

Explicit (and implicit) recipients

can be specified when

messages are enqueued

Like JMS topics, can be multi-

consumer; messages can remain in

the queue for a specified time period

Page 15: Working with Oracle Queues - Choosing between AQ and JMS

Slide 15 of 45 © Raastech, Inc. 2011 | All rights reserved.

Asynchronous Messaging Types of Queues

Oracle AQ (Advanced Queue)

OJMS (Oracle JMS)

WebLogic JMS

Page 16: Working with Oracle Queues - Choosing between AQ and JMS

Slide 16 of 45 © Raastech, Inc. 2011 | All rights reserved.

ORACLE QUEUES

Page 17: Working with Oracle Queues - Choosing between AQ and JMS

Slide 17 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle Queues Oracle AQ

Database-integrated message queuing functionality

Built on top of Oracle Streams

Leverages the functions of Oracle Database

(high availability, scalability, indexing, recovery, security, etc.)

Can be monitored by tools such as OEM

Queue tables can be imported and exported

Messages can be queried using standard SQL (to access message properties, history, and payload)

Does not support DML operations

Page 18: Working with Oracle Queues - Choosing between AQ and JMS

Slide 18 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle Queues Oracle AQ

COUNT QUEUE CONSUMER_NAME ACTION_NAME FROM_PARTY TO_PARTY

----- ------------- ------------- ---------------- ---------- ----------

3 AQ$_QTAB_E B2BUSER PROCESS_OTM CNTRL Essentials

1 HL7_OUT_QUEUE B2BUSER PROCESS_OTM CNTRL Essentials

644 IP_IN_QUEUE B2BERRORUSER Exception CNTRL HI

1800 IP_IN_QUEUE B2BERRORUSER Exception CNTRL Essentials

1 IP_IN_QUEUE OTMUSER PROCESS_OTM_O01 CCS CNTRL

Page 19: Working with Oracle Queues - Choosing between AQ and JMS

Slide 19 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle Queues Oracle JMS

JMS implementation and interface

Underlying model is AQ

All the benefits of AQ

All the accessibility of JMS

Page 20: Working with Oracle Queues - Choosing between AQ and JMS

Slide 20 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle Queues WebLogic JMS

JMS = Java Message Service

JMS is a standard API for accessing enterprise messaging

systems

Enables Java applications that share a messaging system

to exchange messages

Simplifies application development by providing a standard

interface for creating, sending, and receiving messages

Java and SOA applications can move from one JMS

provider to another without any code modification

Page 21: Working with Oracle Queues - Choosing between AQ and JMS

Slide 21 of 45 © Raastech, Inc. 2011 | All rights reserved.

WebLogic JMS queues can be based off of a:

– JDBC Persistent Store

– File Persistent Store

Database-persisted WebLogic JMS queues ≠ OJMS

Oracle Queues WebLogic JMS

Page 22: Working with Oracle Queues - Choosing between AQ and JMS

Slide 22 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle Queues WebLogic JMS

Page 23: Working with Oracle Queues - Choosing between AQ and JMS

Slide 23 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle Queues WebLogic JMS Architecture

Page 24: Working with Oracle Queues - Choosing between AQ and JMS

Slide 24 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle Queues WebLogic JMS Architecture

Persistent Store

JMS Server

JMS Module

Subdeployment

Queue Topic

Page 25: Working with Oracle Queues - Choosing between AQ and JMS

Slide 25 of 45 © Raastech, Inc. 2011 | All rights reserved.

CREATING QUEUES

Page 26: Working with Oracle Queues - Choosing between AQ and JMS

Slide 26 of 45 © Raastech, Inc. 2011 | All rights reserved.

EXECUTE dbms_aqadm.create_queue_table (

queue_table => 'MyAQQueueTable',

queue_payload_type => 'SYS.XMLType',

multiple_consumers => true,

max_retries => 5,

queue_type => 0, -- normal queue

sort_list => 'PRIORITY, ENQ_TIME',

compatible => '10.0.0');

Creating Queues Creating an Oracle AQ

EXECUTE dbms_aqadm.create_queue (

queue_name => 'MyAQQueue',

queue_table => 'MyAQQueueTable');

EXECUTE dbms_aqadm.start_queue (

queue_name => 'MyAQQueue',

enqueue => TRUE,

dequeue => TRUE);

Page 27: Working with Oracle Queues - Choosing between AQ and JMS

Slide 27 of 45 © Raastech, Inc. 2011 | All rights reserved.

EXECUTE sys.dbms_aqadm.create_queue_table (

queue_table => 'MyJMSQueueTable',

queue_payload_type => 'SYS.AQ$_JMS_MESSAGE',

sort_list => 'PRIORITY, ENQ_TIME',

compatible => '10.0.0',

storage_clause => 'tablespace pctfree 10 initrans 1

maxtrans 255 storage ( initial 64K

minextents 1 maxextents unlimited )');

Creating Queues Creating an Oracle JMS Queue (OJMS)

EXECUTE sys.dbms_aqadm.create_queue (

queue_name => 'MyJMSQueue',

queue_table => 'MyJMSQueueTable',

queue_type => sys.dbms_aqadm.normal_queue);

EXECUTE dbms_aqadm.start_queue (

queue_name => 'MyJMSQueue');

Page 28: Working with Oracle Queues - Choosing between AQ and JMS

Slide 28 of 45 © Raastech, Inc. 2011 | All rights reserved.

Create Persistent Store

Log in to the WebLogic Server Administration Console

Navigate to “soa_domain Services Persistent Stores”

Create a new Persistent Database Store or Persistent File Store (e.g., MyJMSFileStore)

Create JMS Server

Navigate to “soa_domain Services Messaging JMS Servers”

Create a new JMS Server (e.g., MyJMSServer)

Create JMS Module

Navigate to “soa_domain Services Messaging JMS Modules”

Create a new JMS Module (e.g., MyJMSModule)

Create Subdeployment

Navigate to “soa_domain Services Messaging JMS Modules”

Click on “MyJMSModule” and create a new “Subdeployments” (e.g., MySubdeployment)

Create Queue

Navigate to “soa_domain Services Messaging JMS Modules”

Click on “MyJMSModule” and create a new Queue using the Subdeployment (e.g., MyJMSQueue)

Creating Queues Creating a WebLogic JMS Queue

Page 29: Working with Oracle Queues - Choosing between AQ and JMS

Slide 29 of 45 © Raastech, Inc. 2011 | All rights reserved.

ACCESSING QUEUES

Page 30: Working with Oracle Queues - Choosing between AQ and JMS

Slide 30 of 45 © Raastech, Inc. 2011 | All rights reserved.

DECLARE

l_message clob := '';

v_enqueue_options dbms_aq.enqueue_options_t;

v_msg_props dbms_aq.message_properties_t;

v_msg_id RAW(16);

v_message SYS.AQ$_JMS_MESSAGE :=

SYS.AQ$_JMS_MESSAGE.construct(DBMS_AQ.JMS_TEXT_MESSAGE);

BEGIN

l_message := '<ns4:elements xmlns:ns4="http://ns.raastech.com/Person">

<ns4:element>

<ns4:firstName>Ahmed</ns4:firstName>

<ns4:lastName>Naga</ns4:lastName>

</ns4:element>

</ns4:elements>';

v_message.set_text(xmltype(l_message).getstringval());

dbms_aq.enqueue(

queue_name => 'MyJMSQueue',

enqueue_options => v_enqueue_options,

message_properties => v_msg_props,

payload => v_message,

msgid => v_msg_id);

COMMIT;

END;

/

Accessing Queues Enqueing Messages via PL/SQL

Page 31: Working with Oracle Queues - Choosing between AQ and JMS

Slide 31 of 45 © Raastech, Inc. 2011 | All rights reserved.

Accessing Queues Producing Messages via Oracle SOA Suite

Oracle SOA Suite provides

adapters to access

resources such as AQ,

JMS, and OJMS

Messages can be

enqueued and dequeued

via the ‘AQ Adapter’

Messages can be

produced and consumed

via the ‘JMS Adapter’

Page 32: Working with Oracle Queues - Choosing between AQ and JMS

Slide 32 of 45 © Raastech, Inc. 2011 | All rights reserved.

Accessing Queues Enqueuing Messages via Java

// Create data object

pers = new PERSON();

pers.setName("Ahmed");

// Open a connection and get queue

db_conn = ((AQOracleSession)aq_sess).getDBConnection();

queue = aq_sess.getQueue("aquser", "MyAQQueue");

// Create a message and set payload

message = queue.createMessage();

payload = message.getObjectPayload();

payload.setPayloadData(pers);

// Enqueue a message into MyAQQueue

eq_option = new AQEnqueueOption();

queue.enqueue(eq_option, message);

// Commit

db_conn.commit();

Page 33: Working with Oracle Queues - Choosing between AQ and JMS

Slide 33 of 45 © Raastech, Inc. 2011 | All rights reserved.

Accessing Queues Producing Messages via Java

// Create InitialContext

Hashtable properties = new Hashtable();

properties.put(Context.INITIAL_CONTEXT_FACTORY,

"weblogic.jndi.WLInitialContextFactory");

properties.put(Context.PROVIDER_URL, "t3://localhost:7001");

properties.put(Context.SECURITY_PRINCIPAL, "weblogic");

properties.put(Context.SECURITY_CREDENTIALS, "welcome1");

// Create QueueConnectionFactory

qcf = (QueueConnectionFactory)ctx.lookup("jms/MyConnectionFactory");

// Create QueueConnection

qc = qcf.createQueueConnection();

// Create QueueSession

qsess = qc.createQueueSession(false, 0);

// Lookup Queue

q = (Queue)ctx.lookup("jms/MyQueue");

// Create QueueSender

qsndr = qsess.createSender(q);

// Create TextMessage

message = qsess.createTextMessage();

// Set message text in TextMessage

message.setText(messageText);

// Send message

qsndr.send("<person><firstName>Ahmed</firstName></person>");

Page 34: Working with Oracle Queues - Choosing between AQ and JMS

Slide 34 of 45 © Raastech, Inc. 2011 | All rights reserved.

ORACLE WEBLOGIC JMS BRIDGE

Page 35: Working with Oracle Queues - Choosing between AQ and JMS

Slide 35 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle WebLogic JMS Bridge Bridging Oracle AQ and WebLogic JMS Queues

Viewed from within code as a regular JMS Queue

Underlying storage is Oracle AQ

The WebLogic Messaging Bridge is a forwarding mechanism

The WebLogic Messaging Bridge can be used with other

messaging products

– To JMS queues in other WebLogic domains

– To 3rd party JMS providers (e.g., MQSeries)

Did not have time to experiment and document

Page 36: Working with Oracle Queues - Choosing between AQ and JMS

Slide 36 of 45 © Raastech, Inc. 2011 | All rights reserved.

PERFORMANCE & COMPARISON

Page 37: Working with Oracle Queues - Choosing between AQ and JMS

Slide 37 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle AQ Oracle JMS WebLogic JMS

Not Proprietary

Database

File System

Memory

Persisted

Centralized access

across midtiers/apps

(only if NFS shared)

Best Performance *

Least Problems ?

Oracle Queues Comparison

Page 38: Working with Oracle Queues - Choosing between AQ and JMS

Slide 38 of 45 © Raastech, Inc. 2011 | All rights reserved.

Messages Action DB Table AQ JMS (file-based)

JMS (db-based)

5000 Enqueue 5:45 3:40 4:25

Dequeue Issues 9:52 11:06 10:12

Errors Issues 29 enqueue

3 dequeue

1000 Enqueue 0:20 0:22 0:54 1:21

Dequeue 4:20 2:42 2:09 2:35

Last Proc Time 1:15 1:14 1:15

Errors ? enqueue

? dequeue

Oracle Queues Performance Summary

10 threads

50 ms test delay

0.5 randomness

324 byte payload size

Page 39: Working with Oracle Queues - Choosing between AQ and JMS

Slide 39 of 45 © Raastech, Inc. 2011 | All rights reserved.

Time Action AQ JMS (file-based)

JMS (db-based)

60 secs Enqueue

(Avg Proc Time) 0.745 0.009 0.007

Dequeue

(Avg Proc Time) 0.059 0.030 0.029

Total Messages 1865 1354 1621

Errors 2

Oracle Queues Performance Summary

5 threads

50 ms test delay

0 randomness

324 byte payload size

Page 40: Working with Oracle Queues - Choosing between AQ and JMS

Slide 40 of 45 © Raastech, Inc. 2011 | All rights reserved.

Time Action AQ JMS (file-based)

JMS (db-based)

300 secs Messages 7842 7769 7574

Time to

Complete 6:50 9:34 8:16

Last Proc Time 1:43 4:40 3:09

Errors 5 (pool)

Oracle Queues Performance Summary

5 threads

50 ms test delay

0 randomness

324 byte payload size

Page 41: Working with Oracle Queues - Choosing between AQ and JMS

Slide 41 of 45 © Raastech, Inc. 2011 | All rights reserved.

SUMMARY

Page 42: Working with Oracle Queues - Choosing between AQ and JMS

Slide 42 of 45 © Raastech, Inc. 2011 | All rights reserved.

Oracle AQ

– Use if you are running Oracle E-Business Suite

– Use for database-driven applications

– Avoid the Oracle SOA Suite ‘AQ Adapter’, as many projects

have complained of enqueue/dequeue issues

WebLogic JMS

– Recommend using for Java and SOA based applications

– Use if you are considering switching queue (JMS) providers

– Oracle states that file-based persistent stores are considerably

faster than JDBC-based persistent stores, but tests have

shown otherwise

Summary Choosing Queue Technology

Page 43: Working with Oracle Queues - Choosing between AQ and JMS

Slide 43 of 45 © Raastech, Inc. 2011 | All rights reserved.

There are many other areas related to Oracle Queue

technologies, such as:

– AQ propagation

– WebLogic JMS queue failover

– Store-and-forward

– High availability

– Notifications

– Exception queues

– Guaranteed delivery

Summary Final Thoughts

Page 44: Working with Oracle Queues - Choosing between AQ and JMS

Slide 44 of 45 © Raastech, Inc. 2011 | All rights reserved.

Summary References

Introduction to Advanced Queues (AQ)

http://blog.raastech.com/2008/05/introduction-to-advanced-queues-aq.html

Creating a JMS queue for SOA consumption

http://blog.raastech.com/2009/03/creating-jms-queue-for-soa-consumption.html

Creating an AQ queue for SOA consumption

http://blog.raastech.com/2011/03/create-aq-queue-for-soa-consumption.html

Introduction to Oracle Streams AQ

http://download.oracle.com/docs/cd/B28359_01/server.111/b28420/aq_intro.htm

Introduction to Oracle JMS

http://download.oracle.com/docs/cd/B28359_01/server.111/b28420/jm_create.htm

Configuring and Managing WebLogic JMS

http://download.oracle.com/docs/cd/E12840_01/wls/docs103/jms_admin/index.html

Oracle Fusion Middleware Developer’s Guide for Oracle SOA Suite 11g Release 1 (11.1.1)

http://download.oracle.com/docs/cd/E12839_01/integration.1111/e10224/title.htm

Oracle Streams Advanced Queuing User's Guide 11g Release 1 (11.1)

http://www.oracle.com/pls/db111/portal.portal_db?selected=15

An updated simple WebLogic JMS client

http://redstack.wordpress.com/2010/02/17/an-updated-simple-weblogic-jms-client

Page 45: Working with Oracle Queues - Choosing between AQ and JMS

Slide 45 of 45 © Raastech, Inc. 2011 | All rights reserved.

Contact Information

Ahmed Aboulnaga

Technical Director

571-249-1155

[email protected]