Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Working with Oracle Queues - Choosing between AQ and JMS

9,403 views

Published on

WMOUG 11

Published in: Technology

Working with Oracle Queues - Choosing between AQ and JMS

  1. 1. Ahmed Aboulnaga Technical Director Raastech, Inc. Working with Oracle Queues Choosing between AQ and JMS
  2. 2. 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
  3. 3. Slide 3 of 45 © Raastech, Inc. 2011 | All rights reserved. INTRODUCTION
  4. 4. 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+)
  5. 5. 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+)
  6. 6. Slide 6 of 45 © Raastech, Inc. 2011 | All rights reserved. OVERVIEW OF MESSAGING
  7. 7. 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
  8. 8. 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)
  9. 9. 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
  10. 10. Slide 10 of 45 © Raastech, Inc. 2011 | All rights reserved. ASYNCHRONOUS MESSAGING
  11. 11. 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
  12. 12. 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>
  13. 13. 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
  14. 14. 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
  15. 15. Slide 15 of 45 © Raastech, Inc. 2011 | All rights reserved. Asynchronous Messaging Types of Queues  Oracle AQ (Advanced Queue)  OJMS (Oracle JMS)  WebLogic JMS
  16. 16. Slide 16 of 45 © Raastech, Inc. 2011 | All rights reserved. ORACLE QUEUES
  17. 17. 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
  18. 18. 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
  19. 19. 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
  20. 20. 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
  21. 21. 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
  22. 22. Slide 22 of 45 © Raastech, Inc. 2011 | All rights reserved. Oracle Queues WebLogic JMS
  23. 23. Slide 23 of 45 © Raastech, Inc. 2011 | All rights reserved. Oracle Queues WebLogic JMS Architecture
  24. 24. Slide 24 of 45 © Raastech, Inc. 2011 | All rights reserved. Oracle Queues WebLogic JMS Architecture Persistent Store JMS Server JMS Module  Subdeployment Queue Topic
  25. 25. Slide 25 of 45 © Raastech, Inc. 2011 | All rights reserved. CREATING QUEUES
  26. 26. 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);
  27. 27. 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');
  28. 28. 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
  29. 29. Slide 29 of 45 © Raastech, Inc. 2011 | All rights reserved. ACCESSING QUEUES
  30. 30. 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
  31. 31. 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’
  32. 32. 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();
  33. 33. 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>");
  34. 34. Slide 34 of 45 © Raastech, Inc. 2011 | All rights reserved. ORACLE WEBLOGIC JMS BRIDGE
  35. 35. 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
  36. 36. Slide 36 of 45 © Raastech, Inc. 2011 | All rights reserved. PERFORMANCE & COMPARISON
  37. 37. 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
  38. 38. 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
  39. 39. 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
  40. 40. 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
  41. 41. Slide 41 of 45 © Raastech, Inc. 2011 | All rights reserved. SUMMARY
  42. 42. 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
  43. 43. 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
  44. 44. 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
  45. 45. Slide 45 of 45 © Raastech, Inc. 2011 | All rights reserved. Contact Information Ahmed Aboulnaga Technical Director 571-249-1155 ahmed.aboulnaga@raastech.com

×