480 likes | 628 Views
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 )
E N D
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 ) JMS (Java Messaging Service) is a standard Java API for message providers In general this is called MOM (Message Oriented Middleware Introduction
Topics • Messaging in general • Concept • Architecture • Models • Delivery types • Java Messaging Service (JMS) • EAS MessageService
Application A Application B Messaging API Messaging API Messaging Adapter Messaging Adapter Concept of MessagingMessage Oriented Middleware Message- Oriented Middleware
Hub-and-spoke architecture App. A Messaging Client App. B Messaging Client Message Provider App.C Messaging Client App. D Messaging Client
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.
Subscriber Publisher Topic Subscriber Publish and Subscribe ( 1-> many ) (pub/sub) Receiver Sender Queue Receiver Point-to-Point ( 1-> 1 ) (p2p, PTP) Messaging Models
Application A Application B Messaging API Messaging API Messaging Adapter Messaging Adapter Message Oriented MiddlewareGuaranteed Delivery Store & Forward Message- Oriented Middleware
Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService
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
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
JMSRedelivered boolean isRedelivered = msg.getJMSRedelivered(); JMSPriority int priority = msg.getJMSPriority(); The JMS message in detailHEADER
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)
Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService
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
Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService
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
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
Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService
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
Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService
P2P • Queues: • one receiver to process • once and only once • peek ahead to see message to be delivered • very similar to topic in usage
(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 !!!
(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
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
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);
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); …
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.
Connecting with other “events” Email SMS HTTP FTP Sockets MQ Tibco Database App. A Messaging Client Message Provider App.C Messaging Client
Topics • Messaging in general • Java Messaging Service (JMS) • Header • Selector • Messagetypes • Topics / Subscriptions • Delivery - publish/receive • Message Driven Bean MDB • EAS MessageService
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)
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(); }
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
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(); }
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
PB with MessageService • Demonstration • PB8 supports • CORBA IDL union types • MessageService
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
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
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
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
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
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.
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
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). • }.
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();
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.
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