Top Banner
Linda Schneider Technical Lead Sun Microsystems, Inc. Using OpenMQ
43

Building With Open MQ

May 27, 2015

Download

Technology

Overview of OpenMQ 4.3, including the new Universal API.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Building With Open MQ

Linda SchneiderTechnical LeadSun Microsystems, Inc.

Using OpenMQ

Page 2: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [2]

What will be covered ?

An introduction to OpenMQ. A Customer example. Basic customer requirements. Building part of the infrastructure.

Warnings:No in depth coverage Assumes basic JMS knowledge

Page 3: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [3]

What is OpenMQ ?

Page 4: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [4]

Allows heterogenous applications to reliability and asynchronously pass data between each other.Open Source Java Message Service (JMS) implementation (+ additions)Default Messaging Provider for GlassfishUseful on its own for standalone JMS applicationsEnterprise level quality (>8 years in development)Open Source since JavaOne 2006Available as a supported product: Sun Java System Message Queue (SJSMQ)

Overview

Page 5: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [5]

Tell Me More

Developer and User discussion forumsStable builds with product releasesEarly access, promoted builds availableNew features, and fixes

Dual license support (GPL v2 and CDDL)Open source version of Java MQ is available from http://mq.dev.java.net

Page 6: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [6]

Using OpenMQ ?

Page 7: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [7]

An example

To mimic problems faced in designing applications, an example:Represents a complex system with loosely connected applicationsUtilizes various types of messagingIs easy to understandIs at least minimally interesting

Page 8: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [8]

Our Example: Santa Claus, Inc

Why, you ask ?

Even if you don't believe in Santa Claus, you must still understand that delivering all those presents would be a daunting taskAnd while its not Christmas which comes but once a year, but requires year round planning and preparation.Just because Santa Claus lives at the North Pole, doesn't imply he can't use technology

Page 9: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [9]

Overall System Requirements

Santa Claus, Inc. software applications need do the following:Handle gift selection and deliveryManage resources e.g.giftsreindeerElves

Track general status informationhow many days before Christmasetc.

Page 10: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [10]

What are we doing:

Focusing on handling christmas gift processingSteps to design it include:Determining the high level operationComing up with the name and type of destinationsDetermining models used for the messagingDetermining load characteristicsLooking at code for some components

Page 11: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [11]

Defining the High Level Operation of the System

Page 12: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [12]

What do we need to do ?

Page 13: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [13]

What do we need to do ? (cont.)

Page 14: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [14]

What are the destinations ?

Page 15: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [15]

The Child Queue

Page 16: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [16]

The Naughty/Nice Queues

Page 17: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [17]

The Wrap Queue

Page 18: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [18]

The Stuff to Pack Queue

Page 19: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [19]

Select-a-gift Queues

Page 20: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [20]

Topic LogChild

Page 21: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [21]

A quick overview to design patterns

Page 22: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [22]

Some basic design patterns:Pattern Description

Request/Reply

Step OperationsBroadcast One message goes to many consumers

ConduitBatch Messages are processed in a chunk

Time Critical/Sensitive

Message is sent to another application who sends back a responseMessages go through several iterations, the message is persisted at key points where processing it again would be expensive

Multiple consumers send messages to a single destination

Messages must be processed within a short period of time (e.g. under an hour) and can not be lost

Page 23: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [23]

More things to think about:

Use persistent messages if it can not afford to be lostUse non-persistent messages for:

non-critical step messages (when it can be repeated)Request/ReplyAnytime a message can be lost on a server crash

Use durables for Topics when it may need to be retrieved laterUse normal or XA transactions when multiple things must process together:

XA if it includes other resources like databases

Page 24: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [24]

Processing Queue ChildConduit: many producers to one queuePersistent: would be time consuming to lose message

Page 25: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [25]

Processing Naughty and NiceStep Pattern: one step of itNaughty Queue: Non-Persistent

its OK if a child who is bad misses their coal

Nice Queue: Persistent. They must get their present.

Page 26: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [26]

Processing NiceStep Pattern: more steps of itMultiple resources so XA

Page 27: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [27]

Processing Nice (Select a gift)Request/Reply PatternNon-persistentAction repeated on failure

Page 28: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [28]

The Wrap Queue Step operationPersistent: end of an expensive set of steps that they don't want to repeat

Page 29: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [29]

The Log Child Topic

Broadcast PatternPersistent because santa wants his database accurate

Page 30: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [30]

In this example:

The batch pattern was not usedSanta does use It for processing HR updates for the elves

The time sensitive/critical data pattern was not used:Santa does use it during present delivery on christmas eve

to track where he is

Because he has no time sensitive/critical data, reliability is important however data availability isn't

Page 31: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [31]

Performance Requirements

22 billion kids364 days for preparation (since christmas is taken)

31,526,000 seconds

70 children/second must be processedAssume 60% are “nice”Assume 40% downtime to cover outages and normal processing (so goal is approx 100 kids/second)

Page 32: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [32]

Performance Requirements (cont)

Naughty Kids use1 Persistent queue (child)1 Non-persistent queue (naughty)1 Persistent Topic (log child)

Nice Kids Use:Persistent Queue (child)Persistent Queue (nice)2 Non-Persistent Queues (Inventory request and reply

queues)Non-persistent queue (Wrap)1 Persistent Topic (log child)

Page 33: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [33]

The cold hard requirements

Messages:Child: 100 msgs/second (persistent)Naughty: 40 msgs/second (non-persistent)Log Child: 100msgs/second (persistent)Nice: 60 msgs/second (persistent in XA transaction)Inventory request/reply: 60 msgs/second *2 (non-

persistent)Wrap: 60 msgs/second (persistent)

TOTALS:Persistent: 380 msgs/secondNon-persistent: 160 msgs/second

Page 34: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [34]

Some Sample Code

Page 35: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [35]

Sending the “Child” messagepublic void doPost(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

// retrieve initial context (ic) QueueConnectionFactory qcf = (QueueConnectionFactory) ic.lookup("MyConnectionFactory"); Queue destQueue = (Queue)ic.lookup("Child"); QueueConnection connection = qcf.createQueueConnection(); try { QueueSession session = connection.createQueueSession( False, Session.AUTO_ACKNOWLEDGE); QueueSender sender = session.createSender(destQueue); MapMessage msg = session.createMapMessage(); // Set each item msg.setString(“firstname”, request.getParameter(“firstname”)); // … retrieve other properties … ; sender.send(msg); } finally { connection.close(); }}

Page 36: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [36]

Processing the “nice” queuepublic void onMessage(Message inMessage) { TextMessage msg = null; try { //Message is of type text and has a unique child id msg = (TextMessage) inMessage; String id = msg.getText(); String[] list = db.getList(id); // makes SQL call String item = null; if (list == null) { // no list, send request String item = getListItem(); //next slide } else { item = list[0]; } //update inventory db.updateInventory(item, id);//makes SQL call // put on packing list pack(item, id); } catch (Exception e) { // things went wrong roll back mdc.setRollbackOnly(); }}

Page 37: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [37]

Processing the “nice” queue (step 2)public String getListItem(String childid) throws Exception { QueueConnectionFactory factory = jndiContext.lookup(“MyQueueFactory”); QueueConnection qc = factory.createQueueConnection(); qc.start(); QueueSession session = qc.createSession(true, Session.AUTO_ACKNOWLEDGED); Queue q = session.createQueue(“RandomPresent”); Queue reply = session.createTemporaryQueue(); // get sender and receiver QueueSender sender = session.createSender(q); QueueReceiver receiver = session.createReceiver(q); //send message and wait TextMessage m = session.createTextMessage(childid); m.setJMSReplyTo(reply); //send the message sender.send(m); TextMessage back = (TextMessage) receiver.receive(60*1000); // wait a minute if (back == null) { didn't get anything throw new Exception(“Nothing”); return back.getText();}

Page 38: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [38]

Processing the “nice” queue (step 3)

public String pack(String item, String child_id) throws JMSException{ QueueConnectionFactory factory = jndiContext.lookup(“MyQueueFactory”); QueueConnection qc = factory.createQueueConnection(); QueueSession session = qc.createSession(true, Session.AUTO_ACKNOWLEDGED);); Queue q = session.createQueue(“Pack”);

// get sender QueueSender sender = session.createSender(q);

//send message MapMessage m = session.createMapMessage(childid); m.setString(“child_id”, child_id); m.setString(“present”, item); sender.send(m);}

Page 39: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [39]

You'll need to fill in the rest

Page 40: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [40]

More Information

Page 41: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [41]

OpenMQ -- More Information

Visit the product webpagehttp://sun.com/software/products/message_queue

Join the Open Message Queue projecthttps://mq.dev.java.net

Browse the product documentationhttp://docs.sun.com/app/docs/coll/1307.3

Take the free technical traininghttp://www.sun.com/training/catalog/courses/WMT-SMQ-1491.xml

Page 42: Building With Open MQ

Copyright Sun Microsystems Inc. All Rights Reserved. [42]

Related Information

Java Composite Application Platform Suitehttp://sun.com/software/javaenterprisesystem/javacaps/

Java System Identity Managerhttp://sun.com/software/products/identity

Project GlassFish https://glassfish.dev.java.net/

The Aquarium, A community forumhttp://blogs.sun.com/theaquarium/

Page 43: Building With Open MQ

Using OpenMQ

Linda [email protected]

Thank You!