0
ably                                 probWhats comingin Java Message Service 2.0Arun Gupta, Java EE & GlassFish Guyblogs.o...
The following is intended to outline our general product direction. It isintended for information purposes only, and may n...
Agenda   •  JSR 343 Update   •  Whats in the JMS 2.0 Early Draft            –  Simplifying the JMS API            –  Impro...
JMS   •  Java Message Service (JMS) specification            –  Part of Java EE but also stands alone            –  Last m...
JMS 2.0•  March 2011: JSR 343 launched to   develop JMS 2.0•  Target: to be part of Java EE 7 in Q2   2013•  Early Draft r...
JSR 343 Expert Group                                                                              ...6 | Copyright © 2012,...
Initial goals of JMS 2.0•  Simpler and easier to use                                                    •  Standardise int...
JMS 2.0 Timeline     ✔	                              Forma0on	  of	  expert	  group	        Q2	  2011	       ✔	           ...
Whats in the Early Draft   •  Here are some items in the JMS 2.0 Early Draft            –  Based on Expert Group members p...
Simplifying the JMS API10 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
Whats wrong with the JMS API?    Not a lot...11 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
Receiving messages in Java EE         @MessageDriven(mappedName = "jms/inboundQueue")         public class MyMDB implement...
Sending messages in Java EE      @Resource(lookup = "jms/connFactory")      ConnectionFactory cf;      @Resource(lookup="j...
Sending messages in Java EE      @Resource(lookup = "jms/connFactory")                                    Need to create  ...
Sending messages in Java EE        @Resource(lookup = "jms/connFactory")        ConnectionFactory cf;                     ...
Sending messages in Java EE      @Resource(lookup = "jms/connFactory")      ConnectionFactory cf;      @Resource(lookup="j...
Sending messages in Java EE      public void sendMessage (String payload) throws JMSException {         try {            C...
Sending messages in Java EE      public void sendMessage (String payload) {         Connection conn = null;         try { ...
Approaches to simplification    •  Simplify the existing API    •  Define new simplified API    •  Use CDI annotations to ...
Simplify the existing API•  Need to maintain backwards compatibility limits scope for change   –  New methods on javax.jms...
Sending a Message (Java EE)    Standard API        @Resource(lookup = "jms/connectionFactory ")        ConnectionFactory c...
Sending a Message (Java EE)    New Simplified API        @Resource(mappedName="jms/contextFactory")        ContextFactory ...
Sending a Message (Java EE)    New Simplified API (With Injection)        @Inject        @JMSConnectionFactory("jms/contex...
Receiving a Message Asynchronously    Standard API        @Resource(lookup = "jms/connectionFactory")        ConnectionFac...
Receiving a Message Asynchronously    New Simplified API        @Resource(lookup = "jms/connectionFactory")        Connect...
Receiving a Message Asynchronously    New Simplified API (With Injection)        @Inject        @JMSConnectionFactory("jms...
Some other simplifications27 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
Making durable subscriptions easier to use    •  Durable subscriptions are identified by       {clientId, subscriptionName...
New features for PaaS29 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
Annotations to create resources in Java EE    •  Currently no standard way for an application to define       what JMS res...
Annotations to create resources in Java EE    •  JSR 342 (Java EE 7) will define new annotations    •  Possible new SPI to...
Improving Integration    with    Application Servers32 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reser...
Defining the interface between    JMS provider and an application server    •  Requirement: allowing any JMS provider to w...
JMS 1.1 Chapter 8    JMS Application Server Facilities    •  Interfaces all optional, so not all vendors implement them   ...
Java EE Connector Architecture (JCA)    •  Designed for integrating pooled, transactional resources       in an applicatio...
Defining the interface between    JMS provider and an application server    •  JMS 2.0 will make provision of a JCA adapto...
Improvements to MDBs    •  Proposals being sent to JSR 342 (EJB 3.2)    •  Fill "gaps" in MDB configuration    •  Surprisi...
Defining the destination used by a MDB    •  annotation...               @MessageDriven(messageDestinationLookup="jms/inbo...
Defining the connection factory used by a MDB    •  annotation...          @MessageDriven(connectionFactoryLookup="jms/myC...
Defining the clientId and    durable subscription name used by a MDB    •  Define as standard activation config properties...
New API Features41 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
New API features    •  Delivery delay    •  Send a message with async acknowledgement from server    •  JMSXDeliveryCount ...
Delivery delay    •  Allows a JMS client to schedule the future delivery of a message    •  New method on MessageProducer ...
Send a message with async    acknowledgement from server    •  Send a message and return immediately without blocking unti...
Make JMSXDeliveryCount mandatory    •  JMS 1.1 defines an optional JMS defined message       property JMSXDeliveryCount.  ...
Multiple consumers on a topic subscription    •  Allows scalable consumption of messages from a topic subscription        ...
Get involved!    •  Early Draft Already Available    •  Mailing lists, issue tracker and wiki:             –  jms-spec.jav...
Questions & Answers48 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
Upcoming SlideShare
Loading in...5
×

GIDS 2012: Java Message Service 2.0

3,959

Published on

GIDS 2012: Java Message Service 2.0

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,959
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
49
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "GIDS 2012: Java Message Service 2.0"

  1. 1. ably probWhats comingin Java Message Service 2.0Arun Gupta, Java EE & GlassFish Guyblogs.oracle.com/arungupta, @arungupta 1 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  2. 2. The following is intended to outline our general product direction. It isintended for information purposes only, and may not be incorporated into anycontract. It is not a commitment to deliver any material, code, or functionality,and should not be relied upon in making purchasing decisions. Thedevelopment, release, and timing of any features or functionality describedfor Oracle s products remains at the sole discretion of Oracle.2 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 2  
  3. 3. Agenda •  JSR 343 Update •  Whats in the JMS 2.0 Early Draft –  Simplifying the JMS API –  Improving integration with application servers –  New API features •  Q&A3 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 3   3  
  4. 4. JMS •  Java Message Service (JMS) specification –  Part of Java EE but also stands alone –  Last maintenance release (1.1) was in 2003 •  Does not mean JMS is moribund! –  Multiple active commercial and open source implementations –  Shows strength of existing spec •  Meanwhile –  Java EE has moved on since, and now Java EE 7 is planned –  Time for JMS 2.04 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 4  
  5. 5. JMS 2.0•  March 2011: JSR 343 launched to develop JMS 2.0•  Target: to be part of Java EE 7 in Q2 2013•  Early Draft released•  Community involvement invited –  Visit jms-spec.java.net and get involved –  Join the mailing list –  Submit suggestions to the issue tracker 5 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 5  
  6. 6. JSR 343 Expert Group ...6 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  7. 7. Initial goals of JMS 2.0•  Simpler and easier to use •  Standardise interface with –  simplify the API application servers –  make use of CDI (Contexts and •  Clarify relationship with other Dependency Injection) Java EE specs –  clarify any ambiguities in the spec –  some JMS behaviour defined in•  Support new themes of Java EE 7 other specs –  PaaS •  New messaging features –  Multi-tenancy –  standardize some existing vendor extensions (or will retrospective standardisation be difficult?) 7 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 7  
  8. 8. JMS 2.0 Timeline ✔ Forma0on  of  expert  group   Q2  2011   ✔ Prepara0on  of  early  dra;   ✔ Early  dra;  review   Q1  2012   Prepara0on  of  public  dra;   Public  review   Q3  2012   Comple0on  of  RI  and  TCK   Q1  2013   Final  approval  ballot  8 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 8  
  9. 9. Whats in the Early Draft •  Here are some items in the JMS 2.0 Early Draft –  Based on Expert Group members priorities –  All items in JIRA at jms-spec.java.net •  Things are still changing •  Its not too late –  to give us your views on these items –  to propose additional items for a later draft or revision9 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 9  
  10. 10. Simplifying the JMS API10 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  11. 11. Whats wrong with the JMS API? Not a lot...11 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  12. 12. Receiving messages in Java EE @MessageDriven(mappedName = "jms/inboundQueue") public class MyMDB implements MessageListener { public void onMessage(Message message) { String payload = (TextMessage)textMessage.getText(); // do something with payload } }12 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  13. 13. Sending messages in Java EE @Resource(lookup = "jms/connFactory") ConnectionFactory cf; @Resource(lookup="jms/inboundQueue") Destination dest; public void sendMessage (String payload) throws JMSException { Connection conn = cf.createConnection(); Session sess = conn.createSession(false,Session.AUTO_ACKNOWLEDGE); MessageProducer producer = sess.createProducer(dest); TextMessage textMessage = sess.createTextMessage(payload); messageProducer.send(textMessage); connection.close(); }13 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  14. 14. Sending messages in Java EE @Resource(lookup = "jms/connFactory") Need to create ConnectionFactory cf; intermediate objects @Resource(lookup="jms/inboundQueue") just to satisfy the API Destination dest; public void sendMessage (String payload) throws JMSException { Connection conn = cf.createConnection(); Session sess = conn.createSession(false,Session.AUTO_ACKNOWLEDGE); MessageProducer producer = sess.createProducer(dest); TextMessage textMessage = sess.createTextMessage(payload); messageProducer.send(textMessage); connection.close(); }14 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  15. 15. Sending messages in Java EE @Resource(lookup = "jms/connFactory") ConnectionFactory cf; Redundant @Resource(lookup="jms/inboundQueue") arguments Destination dest; public void sendMessage (String payload) throws JMSException { Connection conn = cf.createConnection(); Session sess = conn.createSession(false,Session.AUTO_ACKNOWLEDGE); MessageProducer producer = sess.createProducer(dest); TextMessage textMessage = sess.createTextMessage(payload); messageProducer.send(textMessage); connection.close(); }15 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  16. 16. Sending messages in Java EE @Resource(lookup = "jms/connFactory") ConnectionFactory cf; @Resource(lookup="jms/inboundQueue") Destination dest; Boilerplate code public void sendMessage (String payload) throws JMSException { Connection conn = cf.createConnection(); Session sess = conn.createSession(false,Session.AUTO_ACKNOWLEDGE); MessageProducer producer = sess.createProducer(dest); TextMessage textMessage = sess.createTextMessage(payload); messageProducer.send(textMessage); connection.close(); }16 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  17. 17. Sending messages in Java EE public void sendMessage (String payload) throws JMSException { try { Connection conn = null; con = cf.createConnection(); Session sess = conn.createSession(false,Session.AUTO_ACKNOWLEDGE); MessageProducer producer = sess.createProducer(dest); TextMessage textMessage=sess.createTextMessage(payload); messageProducer.send(textMessage); } finally { connection.close(); } } Need to close connections after use17 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  18. 18. Sending messages in Java EE public void sendMessage (String payload) { Connection conn = null; try { con = cf.createConnection(); Session sess = conn.createSession(false,Session.AUTO_ACKNOWLEDGE); MessageProducer producer = sess.createProducer(dest); TextMessage textMessage=sess.createTextMessage(payload); messageProducer.send(textMessage); } catch (JMSException e1) { // do something } finally { try { if (conn!=null) connection.close(); } catch (JMSException e2){ // do something else } And theres } always exception } handling to add18 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  19. 19. Approaches to simplification •  Simplify the existing API •  Define new simplified API •  Use CDI annotations to hide the boilerplate code19 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 19  
  20. 20. Simplify the existing API•  Need to maintain backwards compatibility limits scope for change –  New methods on javax.jms.Connection: •  Keep existing method connection.createSession(transacted,deliveryMode) •  New method for Java SE connection.createSession(sessionMode) •  New method for Java EE connection.createSession() –  Make javax.jms.Connection implement java.lang.AutoCloseable 20 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  21. 21. Sending a Message (Java EE) Standard API @Resource(lookup = "jms/connectionFactory ") ConnectionFactory connectionFactory; @Resource(lookup="jms/inboundQueue") Queue inboundQueue; public void sendMessageOld (String payload) throws JMSException { try (Connection connection = connectionFactory.createConnection()) { Session session = connection.createSession(); MessageProducer messageProducer = session.createProducer(inboundQueue); TextMessage textMessage = session.createTextMessage(payload); messageProducer.send(textMessage); } }21 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  22. 22. Sending a Message (Java EE) New Simplified API @Resource(mappedName="jms/contextFactory") ContextFactory contextFactory; @Resource(mappedName="jms/inboundQueue") Queue inboundQueue; public void sendMessage(String payload) { try (JMSContext context = contextFactory.createContext();){ context.send(inboundQueue,payload); } }22 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  23. 23. Sending a Message (Java EE) New Simplified API (With Injection) @Inject @JMSConnectionFactory("jms/contextFactory") JMSContext context; @Resource(mappedName="jms/inboundQueue") Queue inboundQueue; public void sendMessage(String payload) { context.send(inboundQueue,payload); }23 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  24. 24. Receiving a Message Asynchronously Standard API @Resource(lookup = "jms/connectionFactory") ConnectionFactory connectionFactory; @Resource(lookup="jms/inboundQueue") Queue inboundQueue; public String receiveMessageOld() throws JMSException { try (Connection connection = connectionFactory.createConnection()) { connection.start(); Session session = connection.createSession(); MessageConsumer messageConsumer = session.createConsumer(inboundQueue); TextMessage textMessage = (TextMessage)messageConsumer.receive(); String payload = textMessage.getText(); return payload; } }24 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  25. 25. Receiving a Message Asynchronously New Simplified API @Resource(lookup = "jms/connectionFactory") ConnectionFactory connectionFactory; @Resource(lookup="jms/inboundQueue") Queue inboundQueue; public String receiveMessageNew() { try (JMSContext context = connectionFactory.createContext()) { JMSConsumer consumer = context.createConsumer(inboundQueue); return consumer.receivePayload(String.class); } }25 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  26. 26. Receiving a Message Asynchronously New Simplified API (With Injection) @Inject @JMSConnectionFactory("jms/connectionFactory") private JMSContext context; @Resource(lookup="jms/inboundQueue") Queue inboundQueue; public String receiveMessageNew() { JMSConsumer consumer = context.createConsumer(inboundQueue); return consumer.receivePayload(String.class); }26 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  27. 27. Some other simplifications27 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  28. 28. Making durable subscriptions easier to use •  Durable subscriptions are identified by {clientId, subscriptionName} •  ClientId will no longer be mandatory when using durable subscriptions •  For a MDB, container will generate default subscription name (EJB 3.2)28 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 28  
  29. 29. New features for PaaS29 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  30. 30. Annotations to create resources in Java EE •  Currently no standard way for an application to define what JMS resources should be created in the application server and registered in JNDI •  No equivalent to DataSourceDefinition: @DataSourceDefinition(name="java:global/MyApp/MyDataSource", className="com.foobar.MyDataSource", portNumber=6689, serverName="myserver.com", user="lance", password="secret" )30 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  31. 31. Annotations to create resources in Java EE •  JSR 342 (Java EE 7) will define new annotations •  Possible new SPI to create the physical destinations @JMSConnectionFactoryDefinition( name="java:app/MyJMSFactory", resourceType="javax.jms.QueueConnectionFactory", clientId="foo", resourceAdapter="jmsra", initialPoolSize=5, maxPoolSize=15 ) @JMSDestinationDefinition( name="java:app/orderQueue", resourceType="javax.jms.Queue", resourceAdapter="jmsra", destinationName="orderQueue")31 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  32. 32. Improving Integration with Application Servers32 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  33. 33. Defining the interface between JMS provider and an application server •  Requirement: allowing any JMS provider to work in any Java EE application server •  Current solution: JMS 1.1 Chapter 8 JMS Application Server Facilities33 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  34. 34. JMS 1.1 Chapter 8 JMS Application Server Facilities •  Interfaces all optional, so not all vendors implement them •  No requirement for application servers to support them •  Some omissions –  No support for pooled connections •  Meanwhile…34 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  35. 35. Java EE Connector Architecture (JCA) •  Designed for integrating pooled, transactional resources in an application server •  Designed to support async processing of messages by MDBs •  JCA support already mandatory in Java EE •  Many JMS vendors already provide JCA adapters35 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  36. 36. Defining the interface between JMS provider and an application server •  JMS 2.0 will make provision of a JCA adaptor mandatory •  JMS 1.1 Chapter 8 API remains optional, under review36 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  37. 37. Improvements to MDBs •  Proposals being sent to JSR 342 (EJB 3.2) •  Fill "gaps" in MDB configuration •  Surprisingly, no standard way to specify –  JNDI name of queue or topic (using annotation) –  JNDI name of connection –  clientID! –  durableSubscriptionName!37 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  38. 38. Defining the destination used by a MDB •  annotation... @MessageDriven(messageDestinationLookup="jms/inboundQueue”) public class MyMDB implements MessageListener { ... •  ejb-jar.xml... <ejb-jar> <enterprise-beans> <message-driven> <ejb-name>MessageBean</ejb-name> <message-destination-lookup-name> jms/inboundQueue <message-destination-lookup-name> … all names are provisional38 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  39. 39. Defining the connection factory used by a MDB •  annotation... @MessageDriven(connectionFactoryLookup="jms/myCF") public class MyMDB implements MessageListener { ... •  ejb-jar.xml... <ejb-jar> <enterprise-beans> <message-driven> <ejb-name>MessageBean</ejb-name> <connection-factory-lookup-name> jms/myCF <connection-factory-lookup-name> ...all names provisional39 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  40. 40. Defining the clientId and durable subscription name used by a MDB •  Define as standard activation config properties @MessageDriven(activationConfig = { @ActivationConfigProperty( propertyName="subscriptionDurability",propertyValue="Durable"), @ActivationConfigProperty( propertyName="clientId",propertyValue="MyMDB"), @ActivationConfigProperty( propertyName="subscriptionName",propertyValue="MySub") }) •  Many app servers support these already40 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  41. 41. New API Features41 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  42. 42. New API features •  Delivery delay •  Send a message with async acknowledgement from server •  JMSXDeliveryCount becomes mandatory •  Multiple consumers on the same topic subscription (both durable and non-durable) •  Some products implement some of these already42 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  43. 43. Delivery delay •  Allows a JMS client to schedule the future delivery of a message •  New method on MessageProducer public void setDeliveryDelay(long deliveryDelay) •  Sets the minimum length of time in milliseconds from its dispatch time that a produced message should be retained by the messaging system before delivery to a consumer. •  Why? If the business requires deferred processing, e.g. end of day43 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  44. 44. Send a message with async acknowledgement from server •  Send a message and return immediately without blocking until an acknowledgement has been received from the server. •  Instead, when the acknowledgement is received, an asynchronous callback will be invoked producer.send(message, new AcknowledgeListener(){ public void onAcknowledge(Message message) { // process ack } }); •  Why? Allows thread to do other work whilst waiting for the acknowledgement44 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  45. 45. Make JMSXDeliveryCount mandatory •  JMS 1.1 defines an optional JMS defined message property JMSXDeliveryCount. –  When used, this is set by the JMS provider when a message is received, and is set to the number of times this message has been delivered (including the first time). The first time is 1, the second time 2, etc •  JMS 2.0 will make this mandatory •  Why? Allows app servers and applications to handle "poisonous" messages better45 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  46. 46. Multiple consumers on a topic subscription •  Allows scalable consumption of messages from a topic subscription –  multiple threads –  multiple JVMs •  No further change to API for durable subscriptions (clientID not used) •  New API for non-durable subscriptions MessageConsumer messageConsumer= session.createSharedConsumer(topic,sharedSubscriptionName); •  Why? Scalability •  Why? Allows greater scalability46 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  47. 47. Get involved! •  Early Draft Already Available •  Mailing lists, issue tracker and wiki: –  jms-spec.java.net •  Join users@jms-spec.java.net to follow and contribute •  Applications to join the expert group –  http://jcp.org/en/jsr/summary?id=343 •  Contact the spec lead –  nigel.deakin@oracle.com47 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  48. 48. Questions & Answers48 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×