SlideShare a Scribd company logo
ably
                                 prob
What's coming
in Java Message Service 2.0
Arun Gupta, Java EE & GlassFish Guy
blogs.oracle.com/arungupta, @arungupta
 1 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
The following is intended to outline our general product direction. It is
intended for information purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any material, code, or functionality,
and should not be relied upon in making purchasing decisions. The
development, release, and timing of any features or functionality described
for Oracle s products remains at the sole discretion of Oracle.




2 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |   2	
  
Agenda

   •  JSR 343 Update
   •  What's in the JMS 2.0 Early Draft
            –  Simplifying the JMS API
            –  Improving integration with application servers
            –  New API features
   •  Q&A



3 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |   3	
  
                                                                                      3	
  
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.0
4 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |   4	
  
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	
  
JSR 343 Expert Group




                                                                              ...
6 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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	
  
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	
  
What's 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
   •  It's not too late
            –  to give us your views on these items
            –  to propose additional items for a later draft or revision



9 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |   9	
  
Simplifying the JMS API




10 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
What's 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 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. |
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. |
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. |
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. |
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. |
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 use


17 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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 there's
         }                                                always exception
      }                                                   handling to add

18 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
Approaches to simplification

    •  Simplify the existing API
    •  Define new simplified API
    •  Use CDI annotations to hide the boilerplate code




19 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |   19	
  
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. |
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. |
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. |
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. |
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. |
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. |
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. |
Some other simplifications




27 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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	
  
New features for PaaS




29 | 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 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. |
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. |
Improving Integration
    with
    Application Servers




32 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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 Facilities




33 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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. |
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 adapters



35 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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 review




36 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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. |
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 provisional
38 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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 provisional
39 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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 already

40 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
New API Features




41 | 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 becomes mandatory
    •  Multiple consumers on the same topic subscription (both durable
       and non-durable)
    •  Some products implement some of these already




42 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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 day



43 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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
       acknowledgement

44 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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 better
45 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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 scalability


46 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
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.com

47 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
Questions & Answers




48 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |

More Related Content

PDF
GIDS 2012: PaaSing a Java EE Application
PDF
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
PDF
Java EE 6 and GlassFish v3: Paving the path for future
PDF
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
PDF
Java EE 6 & GlassFish v3 @ DevNexus
PDF
Java EE 6 : Paving The Path For The Future
PDF
GlassFish REST Administration Backend at JavaOne India 2012
PDF
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010
GIDS 2012: PaaSing a Java EE Application
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 and GlassFish v3: Paving the path for future
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
Java EE 6 & GlassFish v3 @ DevNexus
Java EE 6 : Paving The Path For The Future
GlassFish REST Administration Backend at JavaOne India 2012
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010

What's hot (20)

PDF
GlassFish REST Administration Backend
PDF
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
PDF
Java EE7 Demystified
PDF
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
PDF
Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012
PDF
Java EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
PDF
Understanding the nuts & bolts of Java EE 6
PDF
PaaSing a Java EE 6 Application at Geecon 2012
PDF
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
PDF
Java EE 6 Component Model Explained
PDF
Java EE 6 Hands-on Workshop at Dallas Tech Fest 2010
PDF
Java EE 6 workshop at Dallas Tech Fest 2011
PDF
GlassFish & Java EE Business Update @ CEJUG
PDF
Java Summit Chennai: JAX-RS 2.0
PDF
Java EE 6 & GlassFish 3
PDF
Running your Java EE 6 applications in the Cloud
PPT
Java EE7 in action
PDF
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
PDF
Sun Java EE 6 Overview
PDF
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
GlassFish REST Administration Backend
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
Java EE7 Demystified
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012
Java EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
Understanding the nuts & bolts of Java EE 6
PaaSing a Java EE 6 Application at Geecon 2012
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 Component Model Explained
Java EE 6 Hands-on Workshop at Dallas Tech Fest 2010
Java EE 6 workshop at Dallas Tech Fest 2011
GlassFish & Java EE Business Update @ CEJUG
Java Summit Chennai: JAX-RS 2.0
Java EE 6 & GlassFish 3
Running your Java EE 6 applications in the Cloud
Java EE7 in action
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Sun Java EE 6 Overview
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
Ad

Similar to GIDS 2012: Java Message Service 2.0 (20)

PDF
What's new in JMS 2.0 - OTN Bangalore 2013
PDF
'New JMS features in GlassFish 4.0' by Nigel Deakin
PDF
What's new in Java Message Service 2?
PPTX
Java ee7 1hour
PDF
Java EE 7 in practise - OTN Hyderabad 2014
PDF
Java EE 7 - Overview and Status
PDF
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
PDF
Java EE 7: Boosting Productivity and Embracing HTML5
PDF
PPT
GlassFish BOF
PDF
The Java EE 7 Platform: Productivity++ & Embracing HTML5
PDF
OTN Tour 2013: What's new in java EE 7
PPTX
Whats Next for JCA?
PPTX
Java EE7
PDF
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
PPTX
The Java EE 7 Platform: Developing for the Cloud
PPT
Java EE 7 (Hamed Hatami)
PDF
As novidades do Java EE 7: do HTML5 ao JMS 2.0
PDF
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
PDF
Why should i switch to Java SE 7
What's new in JMS 2.0 - OTN Bangalore 2013
'New JMS features in GlassFish 4.0' by Nigel Deakin
What's new in Java Message Service 2?
Java ee7 1hour
Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 - Overview and Status
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7: Boosting Productivity and Embracing HTML5
GlassFish BOF
The Java EE 7 Platform: Productivity++ & Embracing HTML5
OTN Tour 2013: What's new in java EE 7
Whats Next for JCA?
Java EE7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
The Java EE 7 Platform: Developing for the Cloud
Java EE 7 (Hamed Hatami)
As novidades do Java EE 7: do HTML5 ao JMS 2.0
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
Why should i switch to Java SE 7
Ad

More from Arun Gupta (20)

PDF
5 Skills To Force Multiply Technical Talents.pdf
PPTX
Machine Learning using Kubernetes - AI Conclave 2019
PDF
Machine Learning using Kubeflow and Kubernetes
PPTX
Secure and Fast microVM for Serverless Computing using Firecracker
PPTX
Building Java in the Open - j.Day at OSCON 2019
PPTX
Why Amazon Cares about Open Source
PDF
Machine learning using Kubernetes
PDF
Building Cloud Native Applications
PDF
Chaos Engineering with Kubernetes
PDF
How to be a mentor to bring more girls to STEAM
PDF
Java in a World of Containers - DockerCon 2018
PPTX
The Serverless Tidal Wave - SwampUP 2018 Keynote
PDF
Introduction to Amazon EKS - KubeCon 2018
PDF
Mastering Kubernetes on AWS - Tel Aviv Summit
PDF
Top 10 Technology Trends Changing Developer's Landscape
PDF
Container Landscape in 2017
PDF
Java EE and NoSQL using JBoss EAP 7 and OpenShift
PDF
Docker, Kubernetes, and Mesos recipes for Java developers
PDF
Thanks Managers!
PDF
Migrate your traditional VM-based Clusters to Containers
5 Skills To Force Multiply Technical Talents.pdf
Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubeflow and Kubernetes
Secure and Fast microVM for Serverless Computing using Firecracker
Building Java in the Open - j.Day at OSCON 2019
Why Amazon Cares about Open Source
Machine learning using Kubernetes
Building Cloud Native Applications
Chaos Engineering with Kubernetes
How to be a mentor to bring more girls to STEAM
Java in a World of Containers - DockerCon 2018
The Serverless Tidal Wave - SwampUP 2018 Keynote
Introduction to Amazon EKS - KubeCon 2018
Mastering Kubernetes on AWS - Tel Aviv Summit
Top 10 Technology Trends Changing Developer's Landscape
Container Landscape in 2017
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Docker, Kubernetes, and Mesos recipes for Java developers
Thanks Managers!
Migrate your traditional VM-based Clusters to Containers

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Approach and Philosophy of On baking technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Empathic Computing: Creating Shared Understanding
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Understanding_Digital_Forensics_Presentation.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Approach and Philosophy of On baking technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
Empathic Computing: Creating Shared Understanding
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

GIDS 2012: Java Message Service 2.0

  • 1. ably prob What's coming in Java Message Service 2.0 Arun Gupta, Java EE & GlassFish Guy blogs.oracle.com/arungupta, @arungupta 1 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 2. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle s products remains at the sole discretion of Oracle. 2 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 2  
  • 3. Agenda •  JSR 343 Update •  What's in the JMS 2.0 Early Draft –  Simplifying the JMS API –  Improving integration with application servers –  New API features •  Q&A 3 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 3   3  
  • 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.0 4 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 4  
  • 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. JSR 343 Expert Group ... 6 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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. 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. What's 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 •  It's not too late –  to give us your views on these items –  to propose additional items for a later draft or revision 9 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 9  
  • 10. Simplifying the JMS API 10 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 11. What's wrong with the JMS API? Not a lot... 11 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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. 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. 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. 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. 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. 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 use 17 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 there's } always exception } handling to add 18 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 19. Approaches to simplification •  Simplify the existing API •  Define new simplified API •  Use CDI annotations to hide the boilerplate code 19 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. | 19  
  • 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. 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. 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. 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. 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. 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. 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. Some other simplifications 27 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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. New features for PaaS 29 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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. 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. Improving Integration with Application Servers 32 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 Facilities 33 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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. 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 adapters 35 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 review 36 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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. 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 provisional 38 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 provisional 39 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 already 40 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 41. New API Features 41 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 already 42 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 day 43 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 acknowledgement 44 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 better 45 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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 scalability 46 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 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.com 47 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |
  • 48. Questions & Answers 48 | Copyright © 2012, Oracle and/or it’s affiliates. All rights reserved. |