1 / 47

E140 Java Messaging Service in EAServer

E140 Java Messaging Service in EAServer. Volker Saggau Business Consultant Sybase FSI CER Volker.Saggau@Sybase.com. Messaging is the concept of sending or receiving information to/from a service provider. (Mail as an example )

Download Presentation

E140 Java Messaging Service in EAServer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. E140 Java Messaging Service in EAServer • Volker Saggau Business Consultant Sybase FSI CER Volker.Saggau@Sybase.com

  2. Messaging is the concept of sending or receiving information to/from a service provider. (Mail as an example ) JMS (Java Messaging Service) is a standard Java API for message providers In general this is called MOM (Message Oriented Middleware Introduction

  3. Topics • Messaging in general • Concept • Architecture • Models • Delivery types • Java Messaging Service (JMS) • EAS MessageService

  4. Application A Application B Messaging API Messaging API Messaging Adapter Messaging Adapter Concept of MessagingMessage Oriented Middleware Message- Oriented Middleware

  5. Hub-and-spoke architecture App. A Messaging Client App. B Messaging Client Message Provider App.C Messaging Client App. D Messaging Client

  6. Peer-to-Peer architecture Sample: • TCP • FIX • new type of music exchanges App. A Messaging App. App. B Messaging App. App.C Messaging App. App. D Messaging App.

  7. Subscriber Publisher Topic Subscriber Publish and Subscribe ( 1-> many ) (pub/sub) Receiver Sender Queue Receiver Point-to-Point ( 1-> 1 ) (p2p, PTP) Messaging Models

  8. Application A Application B Messaging API Messaging API Messaging Adapter Messaging Adapter Message Oriented MiddlewareGuaranteed Delivery Store & Forward Message- Oriented Middleware

  9. Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService

  10. JMS • JMS Java Messaging Interface • is a Java interface declaration to message transport system • Declares both general types as • sub/sub • P2P • is availabe for many systems like MQ or TIBCO • is “nativ” to EAS since it was in mind when first introduced as MessageService with CORBA API

  11. JMSDestination Topic destination = (Topic) msg.getJMSDestination(); JMSDeliveryMode TopicPublisher tp = topicSession.createPublisher(topic); tp.setDeliveryMode(DeliveryMode.NON_PERSISTENT);//PERSISTENT = default JMSMessageID string msgID = msg.getJMSMessageID(); JMSTimestamp long timestamp = msg.getJMSTimestamp(); JMSExpiration long timeToLive = msg.setTimeToLive(0); //default The JMS message in detailHEADER

  12. JMSRedelivered boolean isRedelivered = msg.getJMSRedelivered(); JMSPriority int priority = msg.getJMSPriority(); The JMS message in detailHEADER

  13. JMSReplyTo msg.setJMSReplyTo(topic); JMSCorrelationID msg.setJMSCorrelationID(Identifier); // string JMSMessageType msg.setJMSMessageType(Identifier); // string Properties msg.setStringProperty(“username”,username); // String, boolean, byte, double, float, int, // long, short, Object msg.clearProperties(); Enumeration enum = msg.getPropertyNames(); The JMS message in detailHEADER (user)

  14. Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService

  15. The selector allows the consumer to be more selective on the message to receive. Message selectors use header and property criteria in conditional expressions. TopicSubscriber ts = session.createSubscriber(Topic,”username =‘SMITH’”, false); A subset of ANSI SQL92 is used. “username =‘SMITH’ and age > 25 “ // or, like, +, -, *, / etc. The JMS message in detailSELECTOR

  16. Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService

  17. The message types ( interfaces ) are defined for the respective payload they carry: TextMessage MapMessage similar to Properties ByteMessage StreamMessage similar to Byte but keep track of order and type ObjectMessage ( only useful in Java-only env. ) The JMS message in detailMESSAGETYPE

  18. 1.) Subscribe to “BUY ORDER” topic 2.) Subscribe to “OFFERS” topic 3.) Publish msg for “OFFERS” topic 4.) Receive “OFFERS” msg 6.) Receive “BUY ORDER” msg 5.) publish msg for “BUY ORDER” topic B2B example Sybase JMS/EAS Wholesaler Retailer

  19. Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService

  20. Temporary Topics vs Durable Subscription Temporary Topic exists for the client session Durable Subscription keeps track of the messages for a client. If the client reconnects all missing message are provided

  21. Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService

  22. P2P • Queues: • one receiver to process • once and only once • peek ahead to see message to be delivered • very similar to topic in usage

  23. (5) ack msg (1) publish msg (4) receive msg Guaranteed Messaging ASE ASA (2) store (6) remove Sybase JMS/EAS Msg Producer Msg Consumer (3) returned publish/send “ack” for the producer this function is transactional !!!

  24. (1) publish msg Msg Consumer Failure scenarios1.) non persistent msg (3) msg lost !!!!! Sybase JMS/EAS Sybase JMS/EAS Msg Producer (2) returned publish/send “ack” for the producer

  25. ASE ASA (6) ack msg (1) publish msg (5) receive msg Failure scenarios1.) persistent msg (2) store (7) remove (4) recover Sybase JMS/EAS Sybase JMS/EAS Msg Producer Msg Consumer (3) returned publish/send

  26. Publish Topic chatTopic = (Topic) jndi.lookup(topicName); TopicSession pubSession = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); TopicPublisher publisher = pubSession.createPublisher(chatTopic); TextMessage message = pubSession.createTextMessage(); message.setText(username + " : " + text); publisher.publish(message);

  27. Receive TopicSession subSession = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); TopicSubscriber subscriber = subSession.createSubscriber(chatTopic); subscriber.setMessageListener(this); … public void onMessage(javax.jms.Message message ) … javax.jms.TextMessage textMessage = (javax.jms.TextMessage) message; String text = textMessage.getText(); System.out.println(text); …

  28. JMS to JMS/others • JMS to JMS and • JMS to others • Will require “adapter” with both system clients. • This is a wide field since this will incorporate “payload • analysis”. As parse, validate, transform and routing. • See MessageBroker or NeON sessions.

  29. Connecting with other “events” Email SMS HTTP FTP Sockets MQ Tibco Database App. A Messaging Client Message Provider App.C Messaging Client

  30. Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService

  31. Message Driven Bean • Instead of an external consumer or dedicated client as component ( has to be started as service or stateful comp.) • The server will instantiate a declared component with the MessageListener interface and send the message to the component. (a.k.a. component notification) • EAS supports component notification for all component types as CORBA (C++/COM/PB)

  32. MDB implements a MessageListener // implement the interface of MessageListener public void onMessage(javax.jms.Message message) { try { String text = ((TextMessage)message).getText(); System.out.println(text); } catch (JMSException ex) { ex.printStackTrace(); _context.setRollbackOnly(); }

  33. Topics • Messaging in general • Java Messaging Service (JMS) • EAS MessageService • Component Notification ( non EJB Components ) • PB with MessageService • MQ and former New Era of Network products • Scheduled Messages ( type of CRON with Messages ) • Cluster operation • Tips and Tricks • Singleton, Performance

  34. Component Notification // implement the interface of MessageListener public void onMessage(CtsComponents.Message message) { try { String text = message.text; System.out.println(text); } catch (Exception ex) { ex.printStackTrace(); throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK(); }

  35. Topics • Messaging in general • Java Messaging Service (JMS) • EAS MessageService • Component Notification ( non EJB Components ) • PB with MessageService • MQ and former New Era of Network products • Scheduled Messages ( type of CRON with Messages ) • Cluster operation • Tips and Tricks • Singleton, Performance

  36. PB with MessageService • Demonstration • PB8 supports • CORBA IDL union types • MessageService

  37. Topics • Messaging in general • Java Messaging Service (JMS) • EAS MessageService • Component Notification ( non EJB Components ) • PB with MessageService • MQ and former New Era of Network products • Scheduled Messages ( type of CRON with Messages ) • Cluster operation • Tips and Tricks • Singleton, Performance

  38. eBIZ Integrator / OTI access • Interoperation: • eBIZ access to EAS ( CTS-OTI ) • use eBIZ to bridge between various transport systems by leveraging Sybase technology • JMS to SAP • JMS to DB • JMS to MQ • What is OTI • sample and demo to provide

  39. Topics • Messaging in general • Java Messaging Service (JMS) • EAS MessageService • Component Notification ( non EJB Components ) • PB with MessageService • MQ and former New Era of Network products • Scheduled Messages ( type of CRON with Messages ) • Cluster operation • Tips and Tricks • Singleton, Performance

  40. Variables: hour hour_of_day minute second year month date day_of_month day_of_week day_of_week_in_month day_of_year week_of_month week_of_year Monday to Sunday January to December (see java.util.Calendar) Messages Published By Schedule Per-Second Messages topic = ‘<second:NN>’ where 00 <= NN <= 59 Per-Minute Messages topic = ‘<minute:NN>’ where 00 <= NN <= 59 Example: // Schedule a message each hour from 9 a.m. to 9 p.m. // Monday, Wednesday and Friday: cms.addSelector("MyQueue", "topic = '<minute:00>' ” + "and day_of_week in (Monday, Wednesday, Friday) " + "and hour_of_day between 9 and 21"); Message Properties: "@t" as a doubleValue - time in milliseconds since 1 Jan, 1970 "ts" as a stringValue - time in format "YYYY-MM-DD HH:MM:SS" Scheduled Messages

  41. Topics • Messaging in general • Java Messaging Service (JMS) • EAS MessageService • Component Notification ( non EJB Components ) • PB with MessageService • MQ and former New Era of Network products • Scheduled Messages ( type of CRON with Messages ) • Cluster operation • Tips and Tricks • Singleton, Performance

  42. Cluster Operation • Message Service in cluster provides a single-systemimage (unless ‘store’ option is false for queue). • Queues by default support shared access by multipleclients, even if the clients are connected to differentservers (unless ‘share’ option is false for queue). • Permanent queues are always available from anyserver in the cluster. • Temporary queues are tied to one server and can fail. • Component notification load is shared across all nodes.

  43. Topics • Messaging in general • Java Messaging Service (JMS) • EAS MessageService • Component Notification ( non EJB Components ) • PB with MessageService • MQ and former New Era of Network products • Scheduled Messages ( type of CRON with Messages ) • Cluster operation • Tips and Tricks • Singleton, Performance

  44. Tips and Tricks - Singleton • Cluster-wide singleton thread with automatic failover. • class MySingletonImpl. • {. • void run(). • {. • cms.addListener(“MyQueue”, “MyPackage/MySingleton[MyThreadPool]”); • Message msg = new Message(); • msg.key = new byte[] { (byte)0 }; • cms.send(“MyQueue”, msg, PERSISTENT.value + IGNORE_DUPLICATE_KEY.value); • }. • void onMessage(Message msg). • {. • // loop forever performing singleton task. • }. • …. (start, stop etc). • }.

  45. Tips and Tricks - Singleton(Sample Client Code) See handout for complete example source code. SendMessage task = smHome.create("MyQueue", "Timeout Message"); Schedule schedule = new Schedule(); schedule.after = new TimeDuration(); schedule.after.seconds = timeout; ScheduledTask st = stHome.create("MyTask", schedule, task); To cancel a scheduled task: st.remove();

  46. Tips and Tricks - Performance • High-volume client notification (e.g. stock ticker) for published non-persistent messages. • JMS - use temporary subscription, use THREAD_POOL connection factory property. • Message Service - use getUniqueName for queue, use thread pool in ‘config’ parameter with getMessageQueue. • In general, use non-persistent messages where guaranteed delivery is not required.

  47. JMS • Questions? • Books: • O´Reilly Java Message Service • ISBN:0-596-00068-5 • Links: • http://java.sun.com/products/jms/tutorial/html/jmsTOC.fm.html • http://localhost:8080/ir/CtsComponents__MessageService.html

More Related