1 JMS as XML and Object-Based Messaging Integration Infrastructure Michael Wynholds Founder Carbon Five

Slides:



Advertisements
Similar presentations
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advertisements

1
Feichter_DPG-SYKL03_Bild-01. Feichter_DPG-SYKL03_Bild-02.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
RXQ Customer Enrollment Using a Registration Agent (RA) Process Flow Diagram (Move-In) Customer Supplier Customer authorizes Enrollment ( )
Document #07-2I RXQ Customer Enrollment Using a Registration Agent (RA) Process Flow Diagram (Move-In) (mod 7/25 & clean-up 8/20) Customer Supplier.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination. Introduction to the Business.
19 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Developing Web Services.
21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
7 Copyright © 2005, Oracle. All rights reserved. Maintaining State in J2EE Applications.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
16 Copyright © 2005, Oracle. All rights reserved. Developing Message-Driven Beans.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
6 Copyright © 2005, Oracle. All rights reserved. Using Advanced Techniques in Servlets.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 5 second questions
Year 6 mental test 10 second questions
Lecture 15 Linked Lists part 2
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Break Time Remaining 10:00.
PP Test Review Sections 6-1 to 6-6
EU market situation for eggs and poultry Management Committee 20 October 2011.
XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)
2 |SharePoint Saturday New York City
Green Eggs and Ham.
VOORBLAD.
15. Oktober Oktober Oktober 2012.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Copyright © 2013 by John Wiley & Sons. All rights reserved. HOW TO CREATE LINKED LISTS FROM SCRATCH CHAPTER Slides by Rick Giles 16 Only Linked List Part.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Subtraction: Adding UP
Januar MDMDFSSMDMDFSSS
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Analyzing Genes and Genomes
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
1 Chapter 13 Nuclear Magnetic Resonance Spectroscopy.
Energy Generation in Mitochondria and Chlorplasts
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.
1 Java Message Service Манин П Enterprise messaging Key concept: 1. Messages are delivered asynchronously 2. Sender is not required to wait for.
Presentation transcript:

1 JMS as XML and Object-Based Messaging Integration Infrastructure Michael Wynholds Founder Carbon Five

2 THIS PRESENTATION Basics of JMS – 10% Types of integration – 50% –Integrate system components –Integrate dependent objects in EJBs Message payloads – 20% –Java objects –XML Q & A – 20%

3 WHAT IS JMS? Java Messaging Service Java API for enterprise messaging –Non-Java implementations available Multiple messaging paradigms –Point-to-point –Publish/Subscribe

4 REAL WORLD EXAMPLE #1 Major Components vs. Sub-Components

5 INTEGRATING SYSTEM COMPONENTS Major components –Crucial serial functionality –Affects user experience –Example: shopping basket Sub-components –Possibly crucial functionality –Slight delays acceptable –Example: notification engine

6 THE WRONG WAY Processes happening serially: –User does something in major component –Waits for sub-component to finish before continuing on through the application

7 THE WRONG WAY Two things wrong: –Why should the user wait? –What if we decide later we want to perform other non-crucial actions at this time?

8 THE RIGHT WAY: ASYNCHRONOUS

9 ASYNCHRONOUS Fire and continue Can still have guaranteed delivery Sub-components can be moved to other machines

10 THE RIGHT WAY: LOOSE COUPLING

11 LOOSE COUPLING Determine significant events Major components publish Sub-components subscribe Addition or modification of sub-component requires no change to major component

12 EXAMPLE: NOTIFICATION Pet Store What are significant events? –User logs in –User status is changed –User purchases pet –Shipment is delayed (from another publisher)

13 SIGNIFICANT EVENT XML :42:06 PST Guy Incognito ADMINISTRATOR Michael Wynholds REGULAR PREFERRED

14 SIGNIFICANT EVENT OBJECTS

15 NOTIFICATION ENGINE CODE private void init() throws NamingException, JMSException { Context ctx = JNDIUtil.getContext(); String selector = new StringBuffer().append("type = ").append(MessageTypes.CARBONFIVE_EVENT).toString(); tconFactory = (TopicConnectionFactory) ctx.lookup(JMS_FACTORY); tcon = tconFactory.createTopicConnection(); tsession = tcon.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); try { topic = (Topic) ctx.lookup(TOPIC_NAME); } catch (NamingException ne) { topic = tsession.createTopic(TOPIC_NAME); ctx.bind(TOPIC_NAME, topic); } tsubscriber = tsession.createSubscriber(topic, selector, false); tsubscriber.setMessageListener(this); tcon.start(); }

16 public void onMessage(javax.jms.Message msg) { synchronized (this) { int type = msg.getIntProperty("type"); Event event = (Event) ((ObjectMessage) msg).getObject(); switch (msg.getIntProperty("type")) { case MessageTypes.USER_STATUS_CHANGE: = generate ((UserStatusChangeEvent) event); .send(); break; default: break; } NOTIFICATION ENGINE CODE

17 private generate (UserStatusChangeEvent event) { = new (); .setTo(event.getUser().get ()); .setSubject("Your status has changed"); .setBody(getBody()); return ; } NOTIFICATION ENGINE CODE

18 MESSAGE SENDER CODE private void init() throws NamingException, JMSException { Context ctx = JNDIUtil.getContext(); tconFactory = (TopicConnectionFactory) ctx.lookup(JMS_FACTORY); tcon = tconFactory.createTopicConnection(); tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); try { topic = (Topic) ctx.lookup(TOPIC_NAME); } catch (NamingException ne) { topic = tsession.createTopic(TOPIC_NAME); ctx.bind(TOPIC_NAME, topic); } tpublisher = tsession.createPublisher(topic); }

19 public void send(Serializable obj, int type) throws JMSException { if (obj == null) { throw new NullPointerException("obj is null"); } ObjectMessage msg = tsession.createObjectMessage(); msg.setObject(obj); msg.setIntProperty("type", type); tpublisher.publish(msg); msg = null; // gc } MESSAGE SENDER CODE

20 USER STATUS CHANGE CODE private void handleStatusChange(ServletRequest request) { HttpSession session = request.getSession(true); User user = UserManager.getUserById(request.getParameter("user_id")); User me = session.getCurrentUser(); UserStatusChangeEvent event = new UserStatusChangeEvent(); EventContext ctx = new EventContext(); ctx.setUser(me); ctx.setTimestamp(new Date()); event.setContext(ctx); event.setUser(user); event.setNewStatus(request.getParameter("new_status")); MessageSender.send(event, MessageTypes.USER_STATUS_CHANGE_EVENT); user.setStatus(request.getParameter("new_status")); }

21 Entity EJB persistence optimization REAL WORLD EXAMPLE #2

22 ENTITY EJB PERSISTENCE Entity EJB guarantees synchronization with persistent store Overhead in EJB container Coarse-grained Entity Beans are better isModified() method often used to optimize So whats the problem?

23 THE PROBLEM Multiple beans modify same dependent object Bean instance may be on separate machines

24 SOLUTION #1 Make dependent object an EJB No longer coarse-grained –EJB overhead takes toll Multiple machine problem not fixed

25 Dont use isModified() Slooooooowwwwwww…. Every getter hits the database –Something may have changed –But most of the time, nothing has changed SOLUTION #2

26 JMS-based isModified() Dependent object publishes to topic when a setter is called Entity Beans subscribe to events corresponding to their dependent objects Efficient Spans multiple machines SOLUTION #3

27 DEPENDENT OBJECT CODE public class Thing { private String name; public void setName(String name) { this.name = name; fireModificationEvent(this.getClass().getName(), this.hashCode()); }

28 EJB isModified() private void init() throws NamingException, JMSException { Context ctx = JNDIUtil.getContext(); String selector = new StringBuffer().append(class = ).append(Thing.class.getName()).toString(); tconFactory = (TopicConnectionFactory) ctx.lookup(JMS_FACTORY); tcon = tconFactory.createTopicConnection(); tsession = tcon.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); try { topic = (Topic) ctx.lookup(TOPIC_NAME); } catch (NamingException ne) { topic = tsession.createTopic(TOPIC_NAME); ctx.bind(TOPIC_NAME, topic); } tsubscriber = tsession.createSubscriber(topic, selector, false); tsubscriber.setMessageListener(this); tcon.start(); }

29 EJB isModified() public void onMessage(javax.jms.Message msg) { synchronized (this) { ModEvent event = (ModEvent) ((ObjectMessage) msg).getObject(); if (Thing.class.getName().equals(event.getClassName())) { if (this.thing.hashCode == event.getHashCode()) { this.setModified(true); }

30 ISSUES Class-based, not object-based events – May receive many messages when using common objects hashCode() method not always unique – Just means you do a database hit Must implement hashCode() in objects to work across machines Can use hash code in selector – Which is more efficient? – I dont know.

31 MESSAGE PAYLOADS Objects – Rule of thumb: Use objects when you can use objects. XML – Rule of thumb: Use XML when you need to use XML.

32 OBJECT MESSAGES Easy to create / use Little processing overhead No need for XML tools Better within same JVM or when JVM is guaranteed Full functionality of Java inside message

33 XML MESSAGES Can be much smaller size – Better for high-traffic distributed systems Potential direct interaction with receiving systems Producer or consumer may be non-Java JMS client No class sync needed

34 REFERENCES Contains links to this and other Carbon Five presentations.