39
Ahmed Aboulnaga Technical Director IPN Web, Inc. March 23, 2011 Working with Oracle Queues Choosing between AQ and JMS

WMOUG_2011Spring_IPNWEB_Queues.pdf

Embed Size (px)

DESCRIPTION

spring

Citation preview

Page 1: WMOUG_2011Spring_IPNWEB_Queues.pdf

Ahmed AboulnagaTechnical DirectorIPN Web, Inc.March 23, 2011

Working with Oracle QueuesChoosing between AQ and JMS

Page 2: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 2 of 39 © IPN Web, Inc. 2011 All rights reserved.

INTRODUCTION

Page 3: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 3 of 39 © IPN Web, Inc. 2011 All rights reserved.

Founded in 2004 & headquartered in Rockville, MD

Specializes in Oracle Fusion Middleware implementations

SBA Certified 8(a) & Small Disadvantage Business

Cleared staff across multiple agencies (ATF, DoD, DoJ)

Certified staff in multiple disciplines (OCE, OCP, OCA)

IPN Web at a Glance

Page 4: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 4 of 39 © IPN Web, Inc. 2011 All rights reserved.

OVERVIEW OF MESSAGING

Page 5: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 5 of 39 © IPN Web, Inc. 2011 All rights reserved.

Introduction to MessagingSynchronous 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 6: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 6 of 39 © IPN Web, Inc. 2011 All rights reserved.

Introduction to MessagingSynchronous 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 7: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 7 of 39 © IPN Web, Inc. 2011 All rights reserved.

Oracle Queue

Introduction to MessagingAsynchronous 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 8: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 8 of 39 © IPN Web, Inc. 2011 All rights reserved.

ASYNCHRONOUS MESSAGING

Page 9: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 9 of 39 © IPN Web, Inc. 2011 All rights reserved.

Asynchronous MessagingOverview

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 10: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 10 of 39 © IPN Web, Inc. 2011 All rights reserved.

Asynchronous MessagingWhen 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 11: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 11 of 39 © IPN Web, Inc. 2011 All rights reserved.

Asynchronous MessagingQueue Approaches

Page 12: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 12 of 39 © IPN Web, Inc. 2011 All rights reserved.

Asynchronous MessagingTypes of Queues

Oracle AQ (Advanced Queue)

OJMS (Oracle JMS)

WebLogic JMS

Page 13: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 13 of 39 © IPN Web, Inc. 2011 All rights reserved.

ORACLE QUEUES

Page 14: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 14 of 39 © IPN Web, Inc. 2011 All rights reserved.

Oracle QueuesOracle 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 15: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 15 of 39 © IPN Web, Inc. 2011 All rights reserved.

Oracle QueuesOracle JMS

JMS implementation and interface

Underlying model is AQ

All the benefits of AQ

All the accessibility of JMS

Page 16: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 16 of 39 © IPN Web, Inc. 2011 All rights reserved.

Oracle QueuesWebLogic 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 17: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 17 of 39 © IPN Web, 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 QueuesWebLogic JMS

Page 18: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 18 of 39 © IPN Web, Inc. 2011 All rights reserved.

Oracle QueuesWebLogic JMS

Page 19: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 19 of 39 © IPN Web, Inc. 2011 All rights reserved.

Oracle QueuesWebLogic JMS

Page 20: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 20 of 39 © IPN Web, Inc. 2011 All rights reserved.

CREATING QUEUES

Page 21: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 21 of 39 © IPN Web, 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 QueuesCreating 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 22: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 22 of 39 © IPN Web, 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 QueuesCreating 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 23: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 23 of 39 © IPN Web, 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 QueuesCreating a WebLogic JMS Queue

Page 24: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 24 of 39 © IPN Web, Inc. 2011 All rights reserved.

ACCESSING QUEUES

Page 25: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 25 of 39 © IPN Web, 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.ipnweb.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 QueuesEnqueing Messages via PL/SQL

Page 26: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 26 of 39 © IPN Web, Inc. 2011 All rights reserved.

Accessing QueuesProducing 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 27: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 27 of 39 © IPN Web, Inc. 2011 All rights reserved.

Accessing QueuesProducing 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 28: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 28 of 39 © IPN Web, Inc. 2011 All rights reserved.

ORACLE WEBLOGIC JMS BRIDGE

Page 29: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 29 of 39 © IPN Web, Inc. 2011 All rights reserved.

Oracle WebLogic JMS BridgeBridging Oracle AQ and WebLogic JMS Queues

Page 30: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 30 of 39 © IPN Web, Inc. 2011 All rights reserved.

Oracle WebLogic JMS BridgeBridging 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)

Page 31: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 31 of 39 © IPN Web, Inc. 2011 All rights reserved.

PERFORMANCE & COMPARISON

Page 32: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 32 of 39 © IPN Web, Inc. 2011 All rights reserved.

Oracle AQ Oracle JMS WebLogic JMS

Not Proprietary

Database Persisted

File System Persisted

Memory Persisted

Centralized access *

Best Performance *

Least Problems ?

Oracle QueuesComparison

Page 33: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 33 of 39 © IPN Web, Inc. 2011 All rights reserved.

Messages Action AQ JMS (file-based)

JMS(db-based)

5000 Enqueue 5:45 3:40 4:25

Dequeue 9:52 11:06 10:12

Errors29 enqueue

3 dequeue

1000 Enqueue 0:22 0:54 1:21

Dequeue 2:42 2:09 2:35

Errors? enqueue

? dequeue

Oracle QueuesPerformance Summary

Page 34: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 34 of 39 © IPN Web, 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

Processing Time of

Last Message1:43 4:40 3:09

Oracle QueuesPerformance Summary

Page 35: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 35 of 39 © IPN Web, Inc. 2011 All rights reserved.

SUMMARY

Page 36: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 36 of 39 © IPN Web, 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

implementations 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

– File-based persistent stores are not considerably faster than

JDBC-based persistent stores

SummaryChoosing Queue Technology

Page 37: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 37 of 39 © IPN Web, 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

SummaryFinal Thoughts

Page 38: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 38 of 39 © IPN Web, Inc. 2011 All rights reserved.

SummaryReferences

Introduction to Advanced Queues (AQ)

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

Creating a JMS queue for SOA consumption

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

Creating an AQ queue for SOA consumption

http://blog.ipnweb.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 39: WMOUG_2011Spring_IPNWEB_Queues.pdf

Slide 39 of 39 © IPN Web, Inc. 2011 All rights reserved.

Contact Information

Ahmed Aboulnaga

Technical Director

[email protected]