SlideShare a Scribd company logo
Introduction to JMS
Session 1
JMS / Session 1 / 2 of 36
Session Objectives
 Describe messaging
 Discuss JMS and the different scenarios
where it can be used
 Explain the JMS architecture
 JMS components
 Approaches for implementing JMS
 JMS programming model
JMS / Session 1 / 3 of 36
Tightly Coupled Systems
Active connection
Component 1 Component 2
Receiver receives
the data
Communication takes place
Sender sends
the data
Inactive connection
Component 1
Communication
does not take place
Component 2
Sender sends
the data
Receiver not
available
JMS / Session 1 / 4 of 36
Loosely Coupled Systems
Component 1
Communication
still takes place
Component 2
Inactive connection
Sender sends
the data
Receiver receives
the data
Receiver not
available
Active connection
Component 1 Component 2
Receiver receives
the data
Communication takes place
Sender sends
the data
JMS / Session 1 / 5 of 36
Communication
Refers to the process of exchanging data between
entities
Types
Synchronous
Communication
Asynchronous
Communication
JMS / Session 1 / 6 of 36
Synchronous Communication
Request
Response
Client
Server
Client
waits for
server
response
JMS / Session 1 / 7 of 36
Asynchronous Communication
Request
Client
Server
Client
does not
wait for
server
response
JMS / Session 1 / 8 of 36
Messaging (1)
Can send and receive
data from other
messaging clients
Can send and receive
data from other
messaging clients
Messaging System
(MOM)
Messaging Client
acting as a Sender
Messaging Client
acting as a Receiver
Destination
A message is an
encapsulated set
of data
Provides facilities for
creating, sending,
receiving and reading
messages
JMS / Session 1 / 9 of 36
Messaging (2)
 Components are loosely coupled
 Application components need to continuously
communicate irrespective of component
availability
 Communication is asynchronous
Messaging can be used when:
MOM
Receiver
Destination
Sender
JMS / Session 1 / 10 of 36
Messaging (3)
 Components exchanging messages need not
be available at the same time
 Messages translated while being transmitted
 Asynchronous communication
 One message received by multiple receivers
Advantages:
MOM
Receiver
Destination
Sender
JMS / Session 1 / 11 of 36
Messaging (4)
 Not the best choice for highly interactive
components
 Information on message handling is not
available
Limitations:
MOM
Receiver
Destination
Sender
JMS / Session 1 / 12 of 36
Java Message Service
Helps build asynchronous message-oriented
applications
Not a messaging system but an API
Allows application developers to create, send, receive
and read messages
JMS / Session 1 / 13 of 36
Application Scenario for using
JMS API (1)
Component 2
Component 1
Communication
still takes place
Inactive connection
Sender sends the
data
Receiver receives
the data
Loosely coupled components
Request
Client
Server
Client
does not
wait for
server
response
Asynchronous Communication
JMS / Session 1 / 14 of 36
Application Scenario for using
JMS API (2)
Sender Receivers
One sender – multiple receivers
Personal
Computer
Mainframe
Legacy systems communicating with new systems
JMS / Session 1 / 15 of 36
Applications using JMS API (1)
Inventory
Component
Manufacturing
Unit
Component
Parts
Component
Parts Order
Component
Parts
Inventory
Component
Inventory Management System:
JMS / Session 1 / 16 of 36
Applications using JMS API (2)
HR Component
Accounts
Component
Administration
Component
Human Resource Management System:
JMS / Session 1 / 17 of 36
JMS Architecture
JMS
Components
Messaging
Domains
JMS
Programming
Model
JMS / Session 1 / 18 of 36
JMS Components
JMS Client 1
JMS Provider (MOM)
JNDI
Connection
Factories
Destinations
JMS Client 4
JMS Client 3
JMS Client 2
1
2
3
4
JMS / Session 1 / 19 of 36
JMS Messaging Models
Point-to-Point Publish/Subscribe
JMS specifications provide different messaging
domains for each of the models
JMS / Session 1 / 20 of 36
Publish/Subscribe (pub/sub)
Publisher
Subscriber
Subscriber
Subscriber
JMS
Provider
Topic
1
1 – Publish Messages to the topic
2 – Subscribe to the topic for Messages
This approach is intended for a One-to-Many
scenario
2
2
2
JMS / Session 1 / 21 of 36
Point-to-Point (p2p)
1 – Message sent to queue
2 – Message fetched from queue
Sender
JMS
Provider
Receiver
1 Queue
This approach is intended for a One-to-One scenario
2
JMS / Session 1 / 22 of 36
JMS Programming Model
The steps are as follows…
JMS / Session 1 / 23 of 36
Step 1: Get the JNDI Context
Through jndi.properties file
java.naming.factory.initial=
org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=
org.jboss.naming:org.jnp.interfaces
Creating the jndi.properties
Context context = new InitialContext();
Obtain the JNDI context in the client’s code
(First method)
JMS / Session 1 / 24 of 36
Step 1: Get the JNDI Context
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "localhost:1099");
properties.put("java.naming.rmi.security.manager", "yes");
properties.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming");
Manually setting the JNDI
(Second method)
JMS / Session 1 / 25 of 36
Step 2: Look up a Connection
Factory
// Get the topic connection factory
TopicConnectionFactory tConFactory =
(TopicConnectionFactory)context.lookup("ConnectionFactory");
// Get the queue connection factory
QueueConnectionFactory qConFactory =
(QueueConnectionFactory)context.lookup("ConnectionFactory");
Connection factories are used by the clients to get a
connection with the JMS provider
Or
JMS / Session 1 / 26 of 36
Step 3: Obtain a Connection
Connection objects represent a connection with the
JMS provider and are used to create session object(s)
// Get the connection object for topic
TopicConnection tCon = tConFactory.createTopicConnection();
// Get the connection object for queue
QueueConnection qCon = qConFactory.createQueueConnection();
tCon.close(); qCon.close();
Close the connection object
Or
Or
JMS / Session 1 / 27 of 36
Step 4: Create a Session
Session is used for producing and consuming messages
// Create a TopicSession object using TopicConnection
TopicSession tSession =
tCon.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
// Create a QueueSession object using QueueConnection
QueueSession qSession = qCon.createQueueSession(true, 0);
Or
JMS / Session 1 / 28 of 36
Step 5: Look up the
Destination
// Look up the topic destination
Topic newTopic =
(Topic)context.lookup("topic/testTopic");
// Look up the queue destination
Queue newQ = (Queue)context.lookup("queue/testQueue");
Destinations specify the target for message
producers and source for message consumers
Or
JMS / Session 1 / 29 of 36
Step 6A: Create a Message
Producer
// Create a publisher for the topic, newTopic
TopicPublisher tPublisher = tSession.createPublisher(newTopic);
// Create a sender for the queue, newQ
QueueSender qSender = qSession.createSender(newQ);
Message producer is created by the session and is
used for sending messages to a destination
Or
JMS / Session 1 / 30 of 36
Step 6B: Create a Message
Consumer
// Create a subscriber for the topic, newTopic
TopicSubscriber tSubscriber =
tSession.createSubscriber(newTopic);
// Create a receiver for the queue, newQ
QueueReceiver qRcvr = qSession.createReceiver(newQ);
Message consumer is created by the session and they
are the receiver of the messages
Or
JMS / Session 1 / 31 of 36
Step 7A: Publish / Send
Messages
// Publish a message using TopicPublisher
tPublisher.publish(msg);
// Send a message using QueueSender
qSender.send(msg);
Or
JMS / Session 1 / 32 of 36
Step 7B: Receive Messages
Receive messages synchronously
tCon.start();
Message msg =
tSubscriber.receive(1000);
qCon.start();
Message msg =
qRcvr.receive();
Receive messages asynchronously
TopicListener tListener = new TopicListener();
/* TopicListener is a user-defined class implementing
MessageListener interface */
tSubscriber.setMessageListener
(tListener);
qRcvr.setMessageListener
(tListener);
Or
Or
JMS / Session 1 / 33 of 36
JMS Programming Model
Summary of steps
7. Send or receive messages
1. Get the JNDI Context
2. Look up a connection factory
3. Obtain a connection
5. Look up the destination
6. Create a message producer and a message consumer
4. Create a session
JMS / Session 1 / 34 of 36
Messages
Message
Header Message
Properties
Message
Bodies
Contains pre-
defined fields to
identify and route
messages
Created for messages
requiring additional values
apart from those provided
by header fields
JMS API provides
various body
formats or
message types
JMS / Session 1 / 35 of 36
Message Header
JMS / Session 1 / 36 of 36
Message Types

More Related Content

Similar to JMSSession1TP-final.ppt

jms-integration
jms-integrationjms-integration
jms-integration
XAVIERCONSULTANTS
 
Bpminto
BpmintoBpminto
Citrix Mfcom Programming For Administrators
Citrix Mfcom Programming For AdministratorsCitrix Mfcom Programming For Administrators
Citrix Mfcom Programming For Administrators
Vishal Ganeriwala
 
Jms using j boss
Jms using j bossJms using j boss
Jms using j boss
Skillwise Group
 
Test DB user
Test DB userTest DB user
Test DB user
techweb08
 
test validation
test validationtest validation
test validation
techweb08
 
Jms intro
Jms introJms intro
Jms intro
Manav Prasad
 
Jms
JmsJms
Message Driven Beans (6)
Message Driven Beans (6)Message Driven Beans (6)
Message Driven Beans (6)
Abdalla Mahmoud
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFramework
banq jdon
 
JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging Service
Peter R. Egli
 
Jms слайды
Jms слайдыJms слайды
Jms слайды
Sergey D
 
JMS
JMSJMS
Martin Gijsen - Effective Test Automation a la Carte
Martin Gijsen -  Effective Test Automation a la Carte Martin Gijsen -  Effective Test Automation a la Carte
Martin Gijsen - Effective Test Automation a la Carte
TEST Huddle
 
Mastering Distributed Performance Testing
Mastering Distributed Performance TestingMastering Distributed Performance Testing
Mastering Distributed Performance Testing
Knoldus Inc.
 
Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS
Arvind Kumar G.S
 
JMS-Java Message Service
JMS-Java Message ServiceJMS-Java Message Service
JMS-Java Message Service
Kasun Madusanke
 
Software testing
Software testingSoftware testing
Software testing
nil65
 
6. TinyOS_2.pdf
6. TinyOS_2.pdf6. TinyOS_2.pdf
6. TinyOS_2.pdf
Jesus Cordero
 
iiwas 2010
iiwas 2010iiwas 2010
iiwas 2010
steccami
 

Similar to JMSSession1TP-final.ppt (20)

jms-integration
jms-integrationjms-integration
jms-integration
 
Bpminto
BpmintoBpminto
Bpminto
 
Citrix Mfcom Programming For Administrators
Citrix Mfcom Programming For AdministratorsCitrix Mfcom Programming For Administrators
Citrix Mfcom Programming For Administrators
 
Jms using j boss
Jms using j bossJms using j boss
Jms using j boss
 
Test DB user
Test DB userTest DB user
Test DB user
 
test validation
test validationtest validation
test validation
 
Jms intro
Jms introJms intro
Jms intro
 
Jms
JmsJms
Jms
 
Message Driven Beans (6)
Message Driven Beans (6)Message Driven Beans (6)
Message Driven Beans (6)
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFramework
 
JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging Service
 
Jms слайды
Jms слайдыJms слайды
Jms слайды
 
JMS
JMSJMS
JMS
 
Martin Gijsen - Effective Test Automation a la Carte
Martin Gijsen -  Effective Test Automation a la Carte Martin Gijsen -  Effective Test Automation a la Carte
Martin Gijsen - Effective Test Automation a la Carte
 
Mastering Distributed Performance Testing
Mastering Distributed Performance TestingMastering Distributed Performance Testing
Mastering Distributed Performance Testing
 
Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS
 
JMS-Java Message Service
JMS-Java Message ServiceJMS-Java Message Service
JMS-Java Message Service
 
Software testing
Software testingSoftware testing
Software testing
 
6. TinyOS_2.pdf
6. TinyOS_2.pdf6. TinyOS_2.pdf
6. TinyOS_2.pdf
 
iiwas 2010
iiwas 2010iiwas 2010
iiwas 2010
 

Recently uploaded

Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdfSoftware Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
kalichargn70th171
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
Anand Bagmar
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
OnePlan Solutions
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical OperationsEnsuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
OnePlan Solutions
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
Luigi Fugaro
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
ICS
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio, Inc.
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
sandeepmenon62
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
Alina Yurenko
 

Recently uploaded (20)

Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdfSoftware Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
 
bgiolcb
bgiolcbbgiolcb
bgiolcb
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical OperationsEnsuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
 

JMSSession1TP-final.ppt

  • 2. JMS / Session 1 / 2 of 36 Session Objectives  Describe messaging  Discuss JMS and the different scenarios where it can be used  Explain the JMS architecture  JMS components  Approaches for implementing JMS  JMS programming model
  • 3. JMS / Session 1 / 3 of 36 Tightly Coupled Systems Active connection Component 1 Component 2 Receiver receives the data Communication takes place Sender sends the data Inactive connection Component 1 Communication does not take place Component 2 Sender sends the data Receiver not available
  • 4. JMS / Session 1 / 4 of 36 Loosely Coupled Systems Component 1 Communication still takes place Component 2 Inactive connection Sender sends the data Receiver receives the data Receiver not available Active connection Component 1 Component 2 Receiver receives the data Communication takes place Sender sends the data
  • 5. JMS / Session 1 / 5 of 36 Communication Refers to the process of exchanging data between entities Types Synchronous Communication Asynchronous Communication
  • 6. JMS / Session 1 / 6 of 36 Synchronous Communication Request Response Client Server Client waits for server response
  • 7. JMS / Session 1 / 7 of 36 Asynchronous Communication Request Client Server Client does not wait for server response
  • 8. JMS / Session 1 / 8 of 36 Messaging (1) Can send and receive data from other messaging clients Can send and receive data from other messaging clients Messaging System (MOM) Messaging Client acting as a Sender Messaging Client acting as a Receiver Destination A message is an encapsulated set of data Provides facilities for creating, sending, receiving and reading messages
  • 9. JMS / Session 1 / 9 of 36 Messaging (2)  Components are loosely coupled  Application components need to continuously communicate irrespective of component availability  Communication is asynchronous Messaging can be used when: MOM Receiver Destination Sender
  • 10. JMS / Session 1 / 10 of 36 Messaging (3)  Components exchanging messages need not be available at the same time  Messages translated while being transmitted  Asynchronous communication  One message received by multiple receivers Advantages: MOM Receiver Destination Sender
  • 11. JMS / Session 1 / 11 of 36 Messaging (4)  Not the best choice for highly interactive components  Information on message handling is not available Limitations: MOM Receiver Destination Sender
  • 12. JMS / Session 1 / 12 of 36 Java Message Service Helps build asynchronous message-oriented applications Not a messaging system but an API Allows application developers to create, send, receive and read messages
  • 13. JMS / Session 1 / 13 of 36 Application Scenario for using JMS API (1) Component 2 Component 1 Communication still takes place Inactive connection Sender sends the data Receiver receives the data Loosely coupled components Request Client Server Client does not wait for server response Asynchronous Communication
  • 14. JMS / Session 1 / 14 of 36 Application Scenario for using JMS API (2) Sender Receivers One sender – multiple receivers Personal Computer Mainframe Legacy systems communicating with new systems
  • 15. JMS / Session 1 / 15 of 36 Applications using JMS API (1) Inventory Component Manufacturing Unit Component Parts Component Parts Order Component Parts Inventory Component Inventory Management System:
  • 16. JMS / Session 1 / 16 of 36 Applications using JMS API (2) HR Component Accounts Component Administration Component Human Resource Management System:
  • 17. JMS / Session 1 / 17 of 36 JMS Architecture JMS Components Messaging Domains JMS Programming Model
  • 18. JMS / Session 1 / 18 of 36 JMS Components JMS Client 1 JMS Provider (MOM) JNDI Connection Factories Destinations JMS Client 4 JMS Client 3 JMS Client 2 1 2 3 4
  • 19. JMS / Session 1 / 19 of 36 JMS Messaging Models Point-to-Point Publish/Subscribe JMS specifications provide different messaging domains for each of the models
  • 20. JMS / Session 1 / 20 of 36 Publish/Subscribe (pub/sub) Publisher Subscriber Subscriber Subscriber JMS Provider Topic 1 1 – Publish Messages to the topic 2 – Subscribe to the topic for Messages This approach is intended for a One-to-Many scenario 2 2 2
  • 21. JMS / Session 1 / 21 of 36 Point-to-Point (p2p) 1 – Message sent to queue 2 – Message fetched from queue Sender JMS Provider Receiver 1 Queue This approach is intended for a One-to-One scenario 2
  • 22. JMS / Session 1 / 22 of 36 JMS Programming Model The steps are as follows…
  • 23. JMS / Session 1 / 23 of 36 Step 1: Get the JNDI Context Through jndi.properties file java.naming.factory.initial= org.jnp.interfaces.NamingContextFactory java.naming.provider.url=localhost:1099 java.naming.factory.url.pkgs= org.jboss.naming:org.jnp.interfaces Creating the jndi.properties Context context = new InitialContext(); Obtain the JNDI context in the client’s code (First method)
  • 24. JMS / Session 1 / 24 of 36 Step 1: Get the JNDI Context Hashtable properties = new Hashtable(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties.put(Context.PROVIDER_URL, "localhost:1099"); properties.put("java.naming.rmi.security.manager", "yes"); properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming"); Manually setting the JNDI (Second method)
  • 25. JMS / Session 1 / 25 of 36 Step 2: Look up a Connection Factory // Get the topic connection factory TopicConnectionFactory tConFactory = (TopicConnectionFactory)context.lookup("ConnectionFactory"); // Get the queue connection factory QueueConnectionFactory qConFactory = (QueueConnectionFactory)context.lookup("ConnectionFactory"); Connection factories are used by the clients to get a connection with the JMS provider Or
  • 26. JMS / Session 1 / 26 of 36 Step 3: Obtain a Connection Connection objects represent a connection with the JMS provider and are used to create session object(s) // Get the connection object for topic TopicConnection tCon = tConFactory.createTopicConnection(); // Get the connection object for queue QueueConnection qCon = qConFactory.createQueueConnection(); tCon.close(); qCon.close(); Close the connection object Or Or
  • 27. JMS / Session 1 / 27 of 36 Step 4: Create a Session Session is used for producing and consuming messages // Create a TopicSession object using TopicConnection TopicSession tSession = tCon.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); // Create a QueueSession object using QueueConnection QueueSession qSession = qCon.createQueueSession(true, 0); Or
  • 28. JMS / Session 1 / 28 of 36 Step 5: Look up the Destination // Look up the topic destination Topic newTopic = (Topic)context.lookup("topic/testTopic"); // Look up the queue destination Queue newQ = (Queue)context.lookup("queue/testQueue"); Destinations specify the target for message producers and source for message consumers Or
  • 29. JMS / Session 1 / 29 of 36 Step 6A: Create a Message Producer // Create a publisher for the topic, newTopic TopicPublisher tPublisher = tSession.createPublisher(newTopic); // Create a sender for the queue, newQ QueueSender qSender = qSession.createSender(newQ); Message producer is created by the session and is used for sending messages to a destination Or
  • 30. JMS / Session 1 / 30 of 36 Step 6B: Create a Message Consumer // Create a subscriber for the topic, newTopic TopicSubscriber tSubscriber = tSession.createSubscriber(newTopic); // Create a receiver for the queue, newQ QueueReceiver qRcvr = qSession.createReceiver(newQ); Message consumer is created by the session and they are the receiver of the messages Or
  • 31. JMS / Session 1 / 31 of 36 Step 7A: Publish / Send Messages // Publish a message using TopicPublisher tPublisher.publish(msg); // Send a message using QueueSender qSender.send(msg); Or
  • 32. JMS / Session 1 / 32 of 36 Step 7B: Receive Messages Receive messages synchronously tCon.start(); Message msg = tSubscriber.receive(1000); qCon.start(); Message msg = qRcvr.receive(); Receive messages asynchronously TopicListener tListener = new TopicListener(); /* TopicListener is a user-defined class implementing MessageListener interface */ tSubscriber.setMessageListener (tListener); qRcvr.setMessageListener (tListener); Or Or
  • 33. JMS / Session 1 / 33 of 36 JMS Programming Model Summary of steps 7. Send or receive messages 1. Get the JNDI Context 2. Look up a connection factory 3. Obtain a connection 5. Look up the destination 6. Create a message producer and a message consumer 4. Create a session
  • 34. JMS / Session 1 / 34 of 36 Messages Message Header Message Properties Message Bodies Contains pre- defined fields to identify and route messages Created for messages requiring additional values apart from those provided by header fields JMS API provides various body formats or message types
  • 35. JMS / Session 1 / 35 of 36 Message Header
  • 36. JMS / Session 1 / 36 of 36 Message Types