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

Citrix Mfcom Programming For Administrators
Citrix Mfcom Programming For AdministratorsCitrix Mfcom Programming For Administrators
Citrix Mfcom Programming For AdministratorsVishal Ganeriwala
 
Test DB user
Test DB userTest DB user
Test DB usertechweb08
 
test validation
test validationtest validation
test validationtechweb08
 
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: JdonFrameworkbanq jdon
 
JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging ServicePeter R. Egli
 
Jms слайды
Jms слайдыJms слайды
Jms слайдыSergey D
 
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 TestingKnoldus 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 ServiceKasun Madusanke
 
Software testing
Software testingSoftware testing
Software testingnil65
 
iiwas 2010
iiwas 2010iiwas 2010
iiwas 2010steccami
 

Similar to JMSSession1TP-final.ppt (20)

Bpminto
BpmintoBpminto
Bpminto
 
jms-integration
jms-integrationjms-integration
jms-integration
 
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

SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfMeon Technology
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1KnowledgeSeed
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion Clinic
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Krakówbim.edu.pl
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...Alluxio, Inc.
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024Shane Coughlan
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandIES VE
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisNeo4j
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEJelle | Nordend
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareinfo611746
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfFurqanuddin10
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationWave PLM
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockSkilrock Technologies
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAlluxio, Inc.
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabbereGrabber
 
Benefits of Employee Monitoring Software
Benefits of  Employee Monitoring SoftwareBenefits of  Employee Monitoring Software
Benefits of Employee Monitoring SoftwareMera Monitor
 

Recently uploaded (20)

SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Benefits of Employee Monitoring Software
Benefits of  Employee Monitoring SoftwareBenefits of  Employee Monitoring Software
Benefits of Employee Monitoring Software
 

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