4 Understanding the Simplified API Programming Model
- About JMS 2.0 Simplified API
The JMS 2.0 simplified API provides the same basic functionality as the JMS 1.1 API (classic API), but the new interfaces and several API changes make it easier to use. - New Interfaces in the Simplified JMS API
The JMS 2.0 simplified API consists of three new interfaces. - New Methods to Simplify Messaging in JMS 2.0
In addition to the methods for sending and receiving messages onJMSContextobjects, JMS 2.0 introduces a few more methods to simplify the code.
About JMS 2.0 Simplified API
The JMS 2.0 simplified API provides the same basic functionality as the JMS 1.1 API (classic API), but the new interfaces and several API changes make it easier to use.
The following interfaces provided by the simplified API were implemented in Oracle WebLogic Server 12.2.1 release:
-
ConnectionFactory: An administered object used by a client to create aConnection. This interface is also used by the classic API. -
JMSContext: An active connection to a JMS provider and a single-threaded context used to send or receive messages. -
JMSProducer: An object created by aJMSContextto send messages to a queue or topic. -
JMSConsumer: An object created by aJMSContextto receive messages sent to a.queue or topic
Figure 4-1 shows how these objects fit together in a JMS client application.
Figure 4-1 Simplified API Programming Model

Description of "Figure 4-1 Simplified API Programming Model"
For more information about the JMS 2.0 interfaces, see the
javax.jms package documentation at https://javaee.github.io/javaee-spec/javadocs/javax/jms/package-summary.html.
Parent topic: Understanding the Simplified API Programming Model
New Interfaces in the Simplified JMS API
The JMS 2.0 simplified API consists of three new interfaces.
JMSContext
The main interface in the simplified API is JMSContext . It combines the functions of the Connection and Session objects of the JMS 1.1 API. Creating a single JMSContext object eliminates the need to create a connection, session, and a text message separately.
For more information about the JMSContext interface, see https://javaee.github.io/javaee-spec/javadocs/javax/jms/JMSContext.html.
The WLJMSContext interface in the weblogic.jms.extensions package defines the fields and methods that are not supported by javax.jms.JMSContext. It provides the same extension features as WLConnection and WLSession. See the Javadoc for WLJMSContext in Java API Reference for Oracle WebLogic Server.
Parent topic: New Interfaces in the Simplified JMS API
JMSProducer
To send messages in the simplified API, use a JMSProducer object. You can create a JMSProducer object by calling the createProducer method on a JMSContext object.
Note:
You do not need to save the JMSProducer object in a variable. It is recommended that you create this object when sending a message. For more information, see Sending Messages Using the Simplified JMS API.
For more information about the JMSProducer interface, see https://javaee.github.io/javaee-spec/javadocs/javax/jms/JMSProducer.html.
The WLJMSProducer interface defines methods and attributes specific to WebLogic JMS. You can use these features by casting the JMSProducer instance to the WLSJMSProducer interface defined in the weblogic.jms.extensions package. See the Javadoc for WLJMSProducer in Java API Reference for Oracle WebLogic Server.
Parent topic: New Interfaces in the Simplified JMS API
JMSConsumer
The JMSConsumer object receives messages from a queue or topic. You can create a JMSConsumer object by passing a Queue or Topic object to one of the createConsumer methods on a JMSContext or by passing a Topic object to one of the createSharedConsumer or createDurableConsumer methods on a JMSContext object.
For more information about the JMSConsumer interface, see https://javaee.github.io/javaee-spec/javadocs/javax/jms/JMSConsumer.html.
Parent topic: New Interfaces in the Simplified JMS API
New Methods to Simplify Messaging in JMS 2.0
In addition to the methods for sending and receiving messages on JMSContext objects, JMS 2.0 introduces a few more methods to simplify the code.
- Method to Extract the Body Directly from a Message
- Method to Receive a Message Body Directly
- Method to Create a Session
Parent topic: Understanding the Simplified API Programming Model
Method to Extract the Body Directly from a Message
The getBody method provides an easy way to obtain the body from a message. This method applies to both the classic and simplified API.
void onMessage(Message message){ // delivers a BytesMessage
byte[] bytes = message.getBody(byte[].class);
...For more information, see the Javadoc at
https://javaee.github.io/javaee-spec/javadocs/javax/jms/Message.html
Parent topic: New Methods to Simplify Messaging in JMS 2.0
Method to Receive a Message Body Directly
The receiveBody method can be used to receive any type of message except for StreamMessage and Message, as long as the class of the expected body is known in advance.
JMSConsumer consumer = ... String body = consumer.receiveBody(String.class,1000);
For more information, see the Javadoc at:
https://javaee.github.io/javaee-spec/javadocs/javax/jms/JMSConsumer.html
Parent topic: New Methods to Simplify Messaging in JMS 2.0
Method to Create a Session
A new createSession method, that accepts a single parameter or no parameter, was added to the javax.jms.Connection. See Create a Session Using the createSession Method.
Parent topic: New Methods to Simplify Messaging in JMS 2.0