SlideShare une entreprise Scribd logo
1  sur  45
Télécharger pour lire hors ligne
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.2
What’s New in
Java Message Service 2?
Sivakumar Thyagarajan
Oracle India
sivakumar.thyagarajan@oracle.com
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3
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.
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4
JMS
 Small, successful messaging API
 JMS 1.1 last updated in 2002
 JMS 2 launched in 2011 as JSR 343
 Final release aligned with Java EE 7
 More information at http://jms-spec.java.net
 Join the user email alias and get involved!
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Goals of
JMS 2
 API modernization/simplicity
 New features
 Better Java EE integration
– define the slightly different JMS API more clearly
– simpler resource configuration
– standardized configuration of JMS MDBs
 Minor corrections and clarifications
 Cloud/PaaS deferred to Java EE 8
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6
Modernizing the JMS API
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7
JMS 1.1: Sending a Message
@Resource(lookup = "java:global/jms/demoConnectionFactory")
ConnectionFactory connectionFactory;
@Resource(lookup = "java:global/jms/demoQueue")
Queue demoQueue;
public void sendMessage(String payload) {
try {
Connection connection = connectionFactory.createConnection();
try {
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(demoQueue);
TextMessage textMessage = session.createTextMessage(payload);
messageProducer.send(textMessage);
} finally {
connection.close();
}
} catch (JMSException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8
Simplifying the JMS API
 Simplify existing JMS 1.1 API where it won't break compatibility
 Define new simplified API requiring fewer objects
– JMSContext, JMSProducer, JMSConsumer
 In Java EE, allow JMSContext to be injected and managed by the
container
Strategy
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9
Simplifying the Existing JMS 1.1 API
 Need to maintain backwards compatibility limits scope for change
 New methods on javax.jms.Connection to create a Session:
– Existing method (will remain)
– New method mainly for Java SE
– New method mainly for Java EE
Simpler API to create a Session
connection.createSession(transacted,deliveryMode)
connection.createSession(sessionMode)
connection.createSession()
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10
Simplifying the Existing JMS 1.1 API
 Make JMS objects implement java.jang.AutoCloseable
– Connection
– Session
– MessageProducer
– MessageConsumer
– QueueBrowser
 Requires Java SE 7
Simpler API to close JMS objects
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11
Simplifying the Existing JMS 1.1 API
 Make JMS objects implement java.jang.AutoCloseable
– Connection, Session, MessageProducer, MessageConsumer,
QueueBrowser
Simpler API to close JMS objects
@Resource(lookup = "jms/connFactory")
ConnectionFactory cf;
@Resource(lookup="jms/inboundQueue")
Destination dest;
public void sendMessage (String payload) throws JMSException {
try ( Connection conn = connectionFactory.createConnection();
Session session = conn.createSession();
MessageProducer producer = session.createProducer(dest);
){
Message mess = sess.createTextMessage(payload);
producer.send(mess);
} catch(JMSException e){
// exception handling
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12
New Simplified API for JMS 2.0
Introducing JMSContext and JMSProducer
@Resource(lookup = "java:global/jms/demoConnectionFactory")
ConnectionFactory connectionFactory;
@Resource(lookup = "java:global/jms/demoQueue")
Queue demoQueue;
public void sendMessageNew(String payload) {
try (JMSContext context = connectionFactory.createContext();){
context.createProducer().send(demoQueue, payload);
} catch (JMSRuntimeException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13
JMSContext (1/2)
 A new object which encapsulates a Connection, a Session and an
anonymous MessageProducer
 Created from a ConnectionFactory
 Call close() after use, or create in a try-with-resources block
 Can also be injected (into a Java EE web or EJB application)
JMSContext context = connectionFactory.createContext(sessionMode);
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14
JMSContext (2/2)
 Can also create from an existing JMSContext
(to reuse its connection – Java SE only)
 Used to create JMSProducer objects for sending messages
 Used to create JMSConsumer objects for receiving messages
 Methods on JMSContext, JMSProducer and JMSConsumer throw only
unchecked exceptions
JMSContext context2 = context1.createContext(sessionMode);
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15
JMSProducer
 Messages are sent by creating a JMSProducer object
– does not encapsulate a MessageProducer so is lightweight
– supports method chaining for a fluid style
 JMS 1.1
 JMS 2.0
MessageProducer producer = session.createProducer();
producer.send(destination,message);
JMSProducer producer = context.createProducer();
producer.send(destination,message);
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16
JMSProducer
 JMS 1.1
 JMS 2.0
Setting message delivery options using method chaining
context.createProducer().setDeliveryMode(DeliveryMode.NON_PERSISTENT).
setPriority(1).setTimeToLive(1000).send(destination,message);
MessageProducer producer = session.createProducer();
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.setPriority(1);
producer.setTimeToLive(1000);
producer.send(destination,message);
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17
JMSProducer
 JMS 1.1 (need to set on the message)
 JMS 2.0 (can also set on the JMSProducer)
Setting message properties and headers
context.createProducer().setProperty("foo","bar").send(destination,"Hello");
MessageProducer producer = session.createProducer();
TextMessage textMessage = session.createTextMessage("Hello);
textMessage.setStringProperty("foo","bar");
producer.send(destination,message);
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18
JMSProducer
 Methods on JMSProducer to send a Message
– send(Destination dest, Message message)
 No need to create a Message
– send(Destination dest, Map<String,Object> payload)
– send(Destination dest, Serializable payload)
– send(Destination dest, String payload)
– send(Destination dest, byte[] payload)
 Use methods on JMSProducer to set delivery options, message
headers and message properties
Sending message payloads directly
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19
JMSConsumer
 Messages are consumed by creating a JMSConsumer object
– encapsulates a MessageConsumer
– similar functionality and API to MessageConsumer
 Synchronous
 Asynchronous
 Connection is automatically started (configurable)
JMSConsumer consumer = context.createConsumer(destination);
Message message = consumer.receive(1000);
JMSConsumer consumer = context.createConsumer(destination);
consumer.setMessageListener(messageListener);
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20
JMSConsumer
Receiving Message Payloads Directly
 Methods on JMSConsumer that return a Message
– Message receive();
– Message receive(long timeout);
– Message receiveNoWait();
 Methods on JMSConsumer that return message payload directly
– <T> T receivePayload(Class<T> c);
– <T> T receivePayload(Class<T> c, long timeout);
– <T> T receivePayloadNoWait(Class<T> c);
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.21
JMSConsumer
Receiving Message Payloads Directly
public String receiveMessage() throws NamingException {
InitialContext initialContext = getInitialContext();
ConnectionFactory connectionFactory =
(ConnectionFactory) initialContext.lookup("jms/connectionFactory");
Queue inboundQueue = (Queue)initialContext.lookup("jms/inboundQueue");
try (JMSContext context = connectionFactory.createContext();) {
JMSConsumer consumer = context.createConsumer(inboundQueue);
return consumer.receivePayload(String.class);
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22
Injection of JMSContext Objects
into a Java EE web or EJB container
@Inject
@JMSConnectionFactory("jms/connectionFactory")
private JMSContext context;
@Resource(mappedName = "jms/inboundQueue")
private Queue inboundQueue;
public void sendMessage (String payload) {
context.createProducer().send(inboundQueue, payload);
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23
Injection of JMSContext Objects
 Connection factory will default to platform default JMS
 Specifying session mode
 Specifying user and password (may be aliased)
into a Java EE web or EJB container
@Inject private JMSContext context;
@Inject
@JMSConnectionFactory("jms/connectionFactory")
@JMSSessionMode(JMSContext.AUTO_ACKNOWLEDGE)
private JMSContext context;
@Inject
@JMSConnectionFactory("jms/connectionFactory")
@JMSPasswordCredential(userName="admin",password="mypassword")
private JMSContext context;
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.24
Injection of JMSContext Objects
 Injected JMSContext objects have a scope
– In a JTA transaction, scope is the transaction
– If no JTA transaction, scope is the request
 JMSContext is automatically closed when scope ends
 Inject two JMSContext objects within the same scope and you get the
same object
– if @JMSConnectionFactory, @JMSPasswordCredential and
@JMSSessionMode annotations match
– Makes it easier to use same session within a transaction
into a Java EE web or EJB container
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.25
JMS 2:
New Features
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.26
Delivery Delay
 Allows a JMS client to schedule the future delivery of a message
 New method on MessageProducer
 New method on JMSProducer
 Sets minimum time in ms from that a 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
public JMSProducer setDeliveryDelay(long deliveryDelay)
public void setDeliveryDelay(long deliveryDelay)
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.27
Asynchronous Send
 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
 New methods on MessageProducer
 Feature also available on JMSProducer
 Why? Allows thread to do other work whilst waiting for the
acknowledgement
messageProducer.send(message,completionListener)
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.28
Asynchronous Send
 Application specifies a CompletionListener instance
public interface CompletionListener {
void onCompletion(Message message);
void onException(Message message, Exception exception);
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.29
Better Handling of “Poison" Messages
 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
Make JMSMXDeliveryCount mandatory
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.30
Multiple Consumers on a Topic Subscription
 Allows scalable consumption of messages from a topic subscription
– multiple threads, multiple JVMs
 New methods needed for non-durable subscriptions
 Existing methods used for durable subscriptions
 Also available on JMSContext
MessageConsumer messageConsumer=
session.createSharedConsumer(topic,sharedSubscriptionName);
MessageConsumer messageConsumer=
session.createDurableConsumer(topic,durableSubscriptionName);
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.31
Easier Definition of JMS
Resources in Java EE
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.32
Easier Definition of JMS Resources in Java EE
 Java EE and JMS recommend applications should obtain JMS
ConnectionFactory and Destination resources by lookup from JNDI
 Keeps application code portable
 Creating these resources is a burden on the deployer, and is non-
standard
The problem
@Resource(lookupName = "jms/inboundQueue")
private Queue inboundQueue;
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.33
Platform Default Connection Factory
 if you simply want to use the application server's built in JMS
Making the simple case simple
@Resource(lookup="java:comp/defaultJMSConnectionFactory")
ConnectionFactory myJMScf;
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.34
Easier Definition of JMS Resources in Java EE
 Application may specify the JMS connection factories and JMS
destinations that it needs using annotations
 Deployer can further define requirements using deployment descriptor
elements
 Application server can use this information to create resources
automatically when application is deployed
 The JMS equivalent to @DataSourceDefinition annotations
 Supporting these automatically is optional
New optional feature in Java EE 7
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.35
Easier Definition of JMS Resources in Java EE
 Can also specify deployment-specific properties via annotations, but
these are best added at deployment time
Application defines required resources using annotations
@JMSDestinationDefinition(
name = "java:global/jms/demoQueue",
description = "Queue to use in demonstration",
interfaceName = "javax.jms.Queue",
destinationName="demoQueue")
@JMSConnectionFactoryDefinition(
name = "java:global/jms/demoConnectionFactory",
interfaceName = "javax.jms.ConnectionFactory",
description = "ConnectionFactory to use in demonstration")
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.36
Easier Definition of JMS Resources in Java EE
Deployer adds further requirements using deployment descriptor
<jms-connection-factory>
<name>java:global/jms/demoConnectionFactory</name>
<property>
<name>addressList</name>
<value>mq://localhost:7676</value>
</property>
<max-pool-size>30</max-pool-size>
<min-pool-size>20</min-pool-size>
<max-idle-time>5</max-idle-time>
</jms-connection-factory>
<jms-destination>
<name>java:global/jms/demoQueue</name>
<interface-name>javax.jms.Queue</interface-name>
<resource-adapter-name>jmsra</resource-adapter-name>
<destination-name>demoQueue</destination-name>
</jms-destination>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.37
More Standardized
Configuration of JMS MDBs
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.38
More Standardized Configuration of JMS MDBs
 Configuration of JMS MDBs is surprisingly non-standard
 EJB 3.1 does not define how to specify
– JNDI name of queue or topic (using annotation)
– JNDI name of connection factory
– clientID
– durableSubscriptionName
 EJB 3.1 does not define how topic messages delivered to clustered
MDBs
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.39
More Standardized Configuration of JMS MDBs
 Can also be configured in ejb-jar.xml
New activation property to specify the queue or topic
@MessageDriven(activationConfig = {
@ActivationConfigProperty(
propertyName = "destinationLookup",
propertyValue = "jms/myTopic"),
. . .
})
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.40
More Standardized Configuration of JMS MDBs
 Can also be configured in ejb-jar.xml
New activation property to specify the connection factory
@MessageDriven(activationConfig = {
@ActivationConfigProperty(
propertyName = "connectionFactoryLookup",
propertyValue = "jms/myCF"),
. . .
})
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.41
More Standardized Configuration of JMS MDBs
 Surprisingly, these have never been standardized before
New activation properties to specify durable subscriptions
@MessageDriven(activationConfig = {
@ActivationConfigProperty(
propertyName = "subscriptionDurability",
propertyValue = "Durable"),
@ActivationConfigProperty(
propertyName = "clientId",
propertyValue = "myClientID"),
@ActivationConfigProperty(
propertyName = "subscriptionName",
propertyValue = "MySub"),
. . .
})
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.42Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
What's
new in
JMS 2
 API modernization/simplicity
 New messaging features
– multi-threaded topic subscribers
– delivery delay
– asynchronous send
 Better Java EE integration
– simpler resource configuration
– standardized configuration of JMS MDBs
 Minor corrections and clarifications
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.43
Where to Find Out More
 Read the draft spec and API docs at http://jms-spec.java.net
 Join users@jms-spec.java.net and send questions and comments
 GlassFish 4.0
– http://glassfish.java.net/
– http://dlc.sun.com.edgesuite.net/glassfish/4.0/promoted/
 Open Message Queue 5.0
– http://mq.java.net/
– http://mq.java.net/5.0.html
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.44
Graphic Section Divider
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.45

Contenu connexe

Tendances

Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introductionejlp12
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Arun Gupta
 
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Arun Gupta
 
Java EE7
Java EE7Java EE7
Java EE7Jay Lee
 
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUGThe Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUGArun Gupta
 
As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0Bruno Borges
 
Java EE 7 and HTML5: Developing for the Cloud
Java EE 7 and HTML5: Developing for the CloudJava EE 7 and HTML5: Developing for the Cloud
Java EE 7 and HTML5: Developing for the CloudArun Gupta
 
GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0Arun Gupta
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesArun Gupta
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 javatwo2011
 
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012Arun Gupta
 
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonJAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonArun Gupta
 
GIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE ApplicationGIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE ApplicationArun Gupta
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration BackendArun Gupta
 
Utilize the Full Power of GlassFish Server and Java EE Security
Utilize the Full Power of GlassFish Server and Java EE SecurityUtilize the Full Power of GlassFish Server and Java EE Security
Utilize the Full Power of GlassFish Server and Java EE SecurityMasoud Kalali
 
PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012Arun Gupta
 

Tendances (20)

Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
 
Java EE7
Java EE7Java EE7
Java EE7
 
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUGThe Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
 
Websocket 1.0
Websocket 1.0Websocket 1.0
Websocket 1.0
 
As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0
 
Java EE 7 and HTML5: Developing for the Cloud
Java EE 7 and HTML5: Developing for the CloudJava EE 7 and HTML5: Developing for the Cloud
Java EE 7 and HTML5: Developing for the Cloud
 
GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0
 
Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web Services
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望
 
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
 
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonJAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
 
GIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE ApplicationGIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE Application
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
 
Utilize the Full Power of GlassFish Server and Java EE Security
Utilize the Full Power of GlassFish Server and Java EE SecurityUtilize the Full Power of GlassFish Server and Java EE Security
Utilize the Full Power of GlassFish Server and Java EE Security
 
PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012
 

Similaire à What's new in Java Message Service 2?

'New JMS features in GlassFish 4.0' by Nigel Deakin
'New JMS features in GlassFish 4.0' by Nigel Deakin'New JMS features in GlassFish 4.0' by Nigel Deakin
'New JMS features in GlassFish 4.0' by Nigel DeakinC2B2 Consulting
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...jaxLondonConference
 
GlassFish BOF
GlassFish BOFGlassFish BOF
GlassFish BOFglassfish
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Max Andersen
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java PlatformSivakumar Thyagarajan
 
ActiveMQ Configuration
ActiveMQ ConfigurationActiveMQ Configuration
ActiveMQ ConfigurationAshish Mishra
 
Whats Next for JCA?
Whats Next for JCA?Whats Next for JCA?
Whats Next for JCA?Fred Rowe
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012Arun Gupta
 
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021StreamNative
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkbanq jdon
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083Divyam Pateriya
 
How Scala, Wicket, and Java EE Can Improve Web Development
How Scala, Wicket, and Java EE Can Improve Web DevelopmentHow Scala, Wicket, and Java EE Can Improve Web Development
How Scala, Wicket, and Java EE Can Improve Web DevelopmentBruno Borges
 
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesMert Çalışkan
 
10 Tips for Java EE 7 with PrimeFaces - JavaOne 2013
10 Tips for Java EE 7 with PrimeFaces - JavaOne 201310 Tips for Java EE 7 with PrimeFaces - JavaOne 2013
10 Tips for Java EE 7 with PrimeFaces - JavaOne 2013Martin Fousek
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVMStaffan Larsen
 
GlassFish in Production Environments
GlassFish in Production EnvironmentsGlassFish in Production Environments
GlassFish in Production EnvironmentsBruno Borges
 
MarvelSoft SchoolAdmin Dev Framework
MarvelSoft SchoolAdmin Dev FrameworkMarvelSoft SchoolAdmin Dev Framework
MarvelSoft SchoolAdmin Dev FrameworkRanganath Shivaram
 
Indic threads pune12-java ee 7 platformsimplification html5
Indic threads pune12-java ee 7 platformsimplification html5Indic threads pune12-java ee 7 platformsimplification html5
Indic threads pune12-java ee 7 platformsimplification html5IndicThreads
 
Introduction to JavaFX on Raspberry Pi
Introduction to JavaFX on Raspberry PiIntroduction to JavaFX on Raspberry Pi
Introduction to JavaFX on Raspberry PiBruno Borges
 

Similaire à What's new in Java Message Service 2? (20)

'New JMS features in GlassFish 4.0' by Nigel Deakin
'New JMS features in GlassFish 4.0' by Nigel Deakin'New JMS features in GlassFish 4.0' by Nigel Deakin
'New JMS features in GlassFish 4.0' by Nigel Deakin
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
 
GlassFish BOF
GlassFish BOFGlassFish BOF
GlassFish BOF
 
WhatsNewInJMS21
WhatsNewInJMS21WhatsNewInJMS21
WhatsNewInJMS21
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java Platform
 
ActiveMQ Configuration
ActiveMQ ConfigurationActiveMQ Configuration
ActiveMQ Configuration
 
Whats Next for JCA?
Whats Next for JCA?Whats Next for JCA?
Whats Next for JCA?
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
 
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFramework
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 
How Scala, Wicket, and Java EE Can Improve Web Development
How Scala, Wicket, and Java EE Can Improve Web DevelopmentHow Scala, Wicket, and Java EE Can Improve Web Development
How Scala, Wicket, and Java EE Can Improve Web Development
 
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
 
10 Tips for Java EE 7 with PrimeFaces - JavaOne 2013
10 Tips for Java EE 7 with PrimeFaces - JavaOne 201310 Tips for Java EE 7 with PrimeFaces - JavaOne 2013
10 Tips for Java EE 7 with PrimeFaces - JavaOne 2013
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVM
 
GlassFish in Production Environments
GlassFish in Production EnvironmentsGlassFish in Production Environments
GlassFish in Production Environments
 
MarvelSoft SchoolAdmin Dev Framework
MarvelSoft SchoolAdmin Dev FrameworkMarvelSoft SchoolAdmin Dev Framework
MarvelSoft SchoolAdmin Dev Framework
 
Indic threads pune12-java ee 7 platformsimplification html5
Indic threads pune12-java ee 7 platformsimplification html5Indic threads pune12-java ee 7 platformsimplification html5
Indic threads pune12-java ee 7 platformsimplification html5
 
Introduction to JavaFX on Raspberry Pi
Introduction to JavaFX on Raspberry PiIntroduction to JavaFX on Raspberry Pi
Introduction to JavaFX on Raspberry Pi
 

Dernier

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Dernier (20)

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

What's new in Java Message Service 2?

  • 1. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1
  • 2. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.2 What’s New in Java Message Service 2? Sivakumar Thyagarajan Oracle India sivakumar.thyagarajan@oracle.com
  • 3. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3 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.
  • 4. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4 JMS  Small, successful messaging API  JMS 1.1 last updated in 2002  JMS 2 launched in 2011 as JSR 343  Final release aligned with Java EE 7  More information at http://jms-spec.java.net  Join the user email alias and get involved!
  • 5. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Goals of JMS 2  API modernization/simplicity  New features  Better Java EE integration – define the slightly different JMS API more clearly – simpler resource configuration – standardized configuration of JMS MDBs  Minor corrections and clarifications  Cloud/PaaS deferred to Java EE 8
  • 6. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6 Modernizing the JMS API
  • 7. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7 JMS 1.1: Sending a Message @Resource(lookup = "java:global/jms/demoConnectionFactory") ConnectionFactory connectionFactory; @Resource(lookup = "java:global/jms/demoQueue") Queue demoQueue; public void sendMessage(String payload) { try { Connection connection = connectionFactory.createConnection(); try { Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(demoQueue); TextMessage textMessage = session.createTextMessage(payload); messageProducer.send(textMessage); } finally { connection.close(); } } catch (JMSException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } }
  • 8. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8 Simplifying the JMS API  Simplify existing JMS 1.1 API where it won't break compatibility  Define new simplified API requiring fewer objects – JMSContext, JMSProducer, JMSConsumer  In Java EE, allow JMSContext to be injected and managed by the container Strategy
  • 9. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9 Simplifying the Existing JMS 1.1 API  Need to maintain backwards compatibility limits scope for change  New methods on javax.jms.Connection to create a Session: – Existing method (will remain) – New method mainly for Java SE – New method mainly for Java EE Simpler API to create a Session connection.createSession(transacted,deliveryMode) connection.createSession(sessionMode) connection.createSession()
  • 10. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10 Simplifying the Existing JMS 1.1 API  Make JMS objects implement java.jang.AutoCloseable – Connection – Session – MessageProducer – MessageConsumer – QueueBrowser  Requires Java SE 7 Simpler API to close JMS objects
  • 11. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11 Simplifying the Existing JMS 1.1 API  Make JMS objects implement java.jang.AutoCloseable – Connection, Session, MessageProducer, MessageConsumer, QueueBrowser Simpler API to close JMS objects @Resource(lookup = "jms/connFactory") ConnectionFactory cf; @Resource(lookup="jms/inboundQueue") Destination dest; public void sendMessage (String payload) throws JMSException { try ( Connection conn = connectionFactory.createConnection(); Session session = conn.createSession(); MessageProducer producer = session.createProducer(dest); ){ Message mess = sess.createTextMessage(payload); producer.send(mess); } catch(JMSException e){ // exception handling } }
  • 12. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12 New Simplified API for JMS 2.0 Introducing JMSContext and JMSProducer @Resource(lookup = "java:global/jms/demoConnectionFactory") ConnectionFactory connectionFactory; @Resource(lookup = "java:global/jms/demoQueue") Queue demoQueue; public void sendMessageNew(String payload) { try (JMSContext context = connectionFactory.createContext();){ context.createProducer().send(demoQueue, payload); } catch (JMSRuntimeException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } }
  • 13. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13 JMSContext (1/2)  A new object which encapsulates a Connection, a Session and an anonymous MessageProducer  Created from a ConnectionFactory  Call close() after use, or create in a try-with-resources block  Can also be injected (into a Java EE web or EJB application) JMSContext context = connectionFactory.createContext(sessionMode);
  • 14. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14 JMSContext (2/2)  Can also create from an existing JMSContext (to reuse its connection – Java SE only)  Used to create JMSProducer objects for sending messages  Used to create JMSConsumer objects for receiving messages  Methods on JMSContext, JMSProducer and JMSConsumer throw only unchecked exceptions JMSContext context2 = context1.createContext(sessionMode);
  • 15. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15 JMSProducer  Messages are sent by creating a JMSProducer object – does not encapsulate a MessageProducer so is lightweight – supports method chaining for a fluid style  JMS 1.1  JMS 2.0 MessageProducer producer = session.createProducer(); producer.send(destination,message); JMSProducer producer = context.createProducer(); producer.send(destination,message);
  • 16. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16 JMSProducer  JMS 1.1  JMS 2.0 Setting message delivery options using method chaining context.createProducer().setDeliveryMode(DeliveryMode.NON_PERSISTENT). setPriority(1).setTimeToLive(1000).send(destination,message); MessageProducer producer = session.createProducer(); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); producer.setPriority(1); producer.setTimeToLive(1000); producer.send(destination,message);
  • 17. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17 JMSProducer  JMS 1.1 (need to set on the message)  JMS 2.0 (can also set on the JMSProducer) Setting message properties and headers context.createProducer().setProperty("foo","bar").send(destination,"Hello"); MessageProducer producer = session.createProducer(); TextMessage textMessage = session.createTextMessage("Hello); textMessage.setStringProperty("foo","bar"); producer.send(destination,message);
  • 18. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18 JMSProducer  Methods on JMSProducer to send a Message – send(Destination dest, Message message)  No need to create a Message – send(Destination dest, Map<String,Object> payload) – send(Destination dest, Serializable payload) – send(Destination dest, String payload) – send(Destination dest, byte[] payload)  Use methods on JMSProducer to set delivery options, message headers and message properties Sending message payloads directly
  • 19. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19 JMSConsumer  Messages are consumed by creating a JMSConsumer object – encapsulates a MessageConsumer – similar functionality and API to MessageConsumer  Synchronous  Asynchronous  Connection is automatically started (configurable) JMSConsumer consumer = context.createConsumer(destination); Message message = consumer.receive(1000); JMSConsumer consumer = context.createConsumer(destination); consumer.setMessageListener(messageListener);
  • 20. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20 JMSConsumer Receiving Message Payloads Directly  Methods on JMSConsumer that return a Message – Message receive(); – Message receive(long timeout); – Message receiveNoWait();  Methods on JMSConsumer that return message payload directly – <T> T receivePayload(Class<T> c); – <T> T receivePayload(Class<T> c, long timeout); – <T> T receivePayloadNoWait(Class<T> c);
  • 21. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.21 JMSConsumer Receiving Message Payloads Directly public String receiveMessage() throws NamingException { InitialContext initialContext = getInitialContext(); ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("jms/connectionFactory"); Queue inboundQueue = (Queue)initialContext.lookup("jms/inboundQueue"); try (JMSContext context = connectionFactory.createContext();) { JMSConsumer consumer = context.createConsumer(inboundQueue); return consumer.receivePayload(String.class); } }
  • 22. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22 Injection of JMSContext Objects into a Java EE web or EJB container @Inject @JMSConnectionFactory("jms/connectionFactory") private JMSContext context; @Resource(mappedName = "jms/inboundQueue") private Queue inboundQueue; public void sendMessage (String payload) { context.createProducer().send(inboundQueue, payload); }
  • 23. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23 Injection of JMSContext Objects  Connection factory will default to platform default JMS  Specifying session mode  Specifying user and password (may be aliased) into a Java EE web or EJB container @Inject private JMSContext context; @Inject @JMSConnectionFactory("jms/connectionFactory") @JMSSessionMode(JMSContext.AUTO_ACKNOWLEDGE) private JMSContext context; @Inject @JMSConnectionFactory("jms/connectionFactory") @JMSPasswordCredential(userName="admin",password="mypassword") private JMSContext context;
  • 24. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.24 Injection of JMSContext Objects  Injected JMSContext objects have a scope – In a JTA transaction, scope is the transaction – If no JTA transaction, scope is the request  JMSContext is automatically closed when scope ends  Inject two JMSContext objects within the same scope and you get the same object – if @JMSConnectionFactory, @JMSPasswordCredential and @JMSSessionMode annotations match – Makes it easier to use same session within a transaction into a Java EE web or EJB container
  • 25. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.25 JMS 2: New Features
  • 26. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.26 Delivery Delay  Allows a JMS client to schedule the future delivery of a message  New method on MessageProducer  New method on JMSProducer  Sets minimum time in ms from that a 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 public JMSProducer setDeliveryDelay(long deliveryDelay) public void setDeliveryDelay(long deliveryDelay)
  • 27. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.27 Asynchronous Send  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  New methods on MessageProducer  Feature also available on JMSProducer  Why? Allows thread to do other work whilst waiting for the acknowledgement messageProducer.send(message,completionListener)
  • 28. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.28 Asynchronous Send  Application specifies a CompletionListener instance public interface CompletionListener { void onCompletion(Message message); void onException(Message message, Exception exception); }
  • 29. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.29 Better Handling of “Poison" Messages  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 Make JMSMXDeliveryCount mandatory
  • 30. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.30 Multiple Consumers on a Topic Subscription  Allows scalable consumption of messages from a topic subscription – multiple threads, multiple JVMs  New methods needed for non-durable subscriptions  Existing methods used for durable subscriptions  Also available on JMSContext MessageConsumer messageConsumer= session.createSharedConsumer(topic,sharedSubscriptionName); MessageConsumer messageConsumer= session.createDurableConsumer(topic,durableSubscriptionName);
  • 31. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.31 Easier Definition of JMS Resources in Java EE
  • 32. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.32 Easier Definition of JMS Resources in Java EE  Java EE and JMS recommend applications should obtain JMS ConnectionFactory and Destination resources by lookup from JNDI  Keeps application code portable  Creating these resources is a burden on the deployer, and is non- standard The problem @Resource(lookupName = "jms/inboundQueue") private Queue inboundQueue;
  • 33. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.33 Platform Default Connection Factory  if you simply want to use the application server's built in JMS Making the simple case simple @Resource(lookup="java:comp/defaultJMSConnectionFactory") ConnectionFactory myJMScf;
  • 34. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.34 Easier Definition of JMS Resources in Java EE  Application may specify the JMS connection factories and JMS destinations that it needs using annotations  Deployer can further define requirements using deployment descriptor elements  Application server can use this information to create resources automatically when application is deployed  The JMS equivalent to @DataSourceDefinition annotations  Supporting these automatically is optional New optional feature in Java EE 7
  • 35. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.35 Easier Definition of JMS Resources in Java EE  Can also specify deployment-specific properties via annotations, but these are best added at deployment time Application defines required resources using annotations @JMSDestinationDefinition( name = "java:global/jms/demoQueue", description = "Queue to use in demonstration", interfaceName = "javax.jms.Queue", destinationName="demoQueue") @JMSConnectionFactoryDefinition( name = "java:global/jms/demoConnectionFactory", interfaceName = "javax.jms.ConnectionFactory", description = "ConnectionFactory to use in demonstration")
  • 36. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.36 Easier Definition of JMS Resources in Java EE Deployer adds further requirements using deployment descriptor <jms-connection-factory> <name>java:global/jms/demoConnectionFactory</name> <property> <name>addressList</name> <value>mq://localhost:7676</value> </property> <max-pool-size>30</max-pool-size> <min-pool-size>20</min-pool-size> <max-idle-time>5</max-idle-time> </jms-connection-factory> <jms-destination> <name>java:global/jms/demoQueue</name> <interface-name>javax.jms.Queue</interface-name> <resource-adapter-name>jmsra</resource-adapter-name> <destination-name>demoQueue</destination-name> </jms-destination>
  • 37. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.37 More Standardized Configuration of JMS MDBs
  • 38. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.38 More Standardized Configuration of JMS MDBs  Configuration of JMS MDBs is surprisingly non-standard  EJB 3.1 does not define how to specify – JNDI name of queue or topic (using annotation) – JNDI name of connection factory – clientID – durableSubscriptionName  EJB 3.1 does not define how topic messages delivered to clustered MDBs
  • 39. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.39 More Standardized Configuration of JMS MDBs  Can also be configured in ejb-jar.xml New activation property to specify the queue or topic @MessageDriven(activationConfig = { @ActivationConfigProperty( propertyName = "destinationLookup", propertyValue = "jms/myTopic"), . . . })
  • 40. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.40 More Standardized Configuration of JMS MDBs  Can also be configured in ejb-jar.xml New activation property to specify the connection factory @MessageDriven(activationConfig = { @ActivationConfigProperty( propertyName = "connectionFactoryLookup", propertyValue = "jms/myCF"), . . . })
  • 41. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.41 More Standardized Configuration of JMS MDBs  Surprisingly, these have never been standardized before New activation properties to specify durable subscriptions @MessageDriven(activationConfig = { @ActivationConfigProperty( propertyName = "subscriptionDurability", propertyValue = "Durable"), @ActivationConfigProperty( propertyName = "clientId", propertyValue = "myClientID"), @ActivationConfigProperty( propertyName = "subscriptionName", propertyValue = "MySub"), . . . })
  • 42. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.42Copyright © 2012, Oracle and/or its affiliates. All rights reserved. What's new in JMS 2  API modernization/simplicity  New messaging features – multi-threaded topic subscribers – delivery delay – asynchronous send  Better Java EE integration – simpler resource configuration – standardized configuration of JMS MDBs  Minor corrections and clarifications
  • 43. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.43 Where to Find Out More  Read the draft spec and API docs at http://jms-spec.java.net  Join users@jms-spec.java.net and send questions and comments  GlassFish 4.0 – http://glassfish.java.net/ – http://dlc.sun.com.edgesuite.net/glassfish/4.0/promoted/  Open Message Queue 5.0 – http://mq.java.net/ – http://mq.java.net/5.0.html
  • 44. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.44 Graphic Section Divider
  • 45. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.45