SlideShare a Scribd company logo
1 of 31
Java
Messaging
Services
KUMAR GAURAV
K10GAURAV@GMAIL.COM
Messaging Systems
 A messaging System allows and promotes the loose coupling
of components
 allows components to post messages for other components
 asynchronous rather than synchronous
 also known as MOM (Message-Oriented Middleware
 Two basic models
 point-to-point
 one component posts a message to a server
 one component (and only one) will consume a posted message
 publish/subscribe
 allows a component to publish a message to a topic on a server
 components interested in a particular topic can subscribe to that
topic (messages can be consumed by a number of components)
 when a component publishes a message, it subscribes to that topic
and will receive the message
What Does JMS Do
 A Java API that allows applications to:
 create
 send
 receive
 read messages
 in principle kind of like a news system, but doesn’t
involve e-mail
Architecture
 A JMS Application consists of :
 A JMS Provider
 a messaging system that implements the JMS interfaces and
provides administrative and control features
 included in Java since JDK 1.3
 JMS Clients
 Java programs/components/objects that produce and
consume messages
 Administered Objects
 preconfigured JMS objects created by an administrator for
the use of clients
 destinations
 connection factories
 Native Clients
 a non-Java program that uses a products native API instead
of the JMS API
 a legacy application modified to use the JMS API
Architecture
Administrative
Tool
JNDI
Namespace
JMS
Client
JMS
Provider
Bind
Lookup
Logical
Connection
CF D
Interaction
 The administrator binds connection factories (CF)
and destinations (D) into a JNDI namespace.
 A JMS client can then lookup the administered
objects and establish a logical connection to
them via the JMS Provider
Point-to-Point Messaging
Domain
 Applications are built around the concepts of
message queues, senders and receivers
 Queues retain all messages until they are either:
 consumed
 expire
 Each message has only one consumer
 There are no timing dependencies
 The receiver acknowledges the successful
processing of a message
Point-to-Point Messaging
Domain
Publish/Subscribe Messaging
Domain
 Clients address messages to a topic
 Publishers and Subscribers are generally
anonymous and may dynamically publish or
subscribe to the content hierarchy
 Topics retain messages only long enough to
distribute them to their current subscribers
 Use publish/scribe messaging when each
message can be processed by zero, one or many
consumers
 durable subscriptions exist for subscribers not
currently active
Publish/Subscribe Messaging
Domain
Message Consumption
 In JMS messages can be consumed in two ways:
 Synchronously
 a subscriber or receiver explicitly fetches a message
from the destination using the “receive” method
 the “receive” method can block until a message arrives
or can time out if a message does not arrive within a
specified time limit
 Asynchronously
 a client can register a message listener (like an event
listener) with a consumer
 whenever a message arrives at the destination the JMS
Provider delivers the message by calling the listener’s
“onMessage” method which acts on the contents of the
message
Programming Model
Administered Objects
 Administration is better done using vendor
supplied tools rather than programmatically due
to vendor implementation differences
 j2eeadmin - j2ee sdk administration tool
 Administered objects are configured in a JNDI
namespace
 Connection Factories
 Destinations
Connection Factories
 A connection factory object is used by a client to create
a connection with a provider.
 It encapsulates a set of connection configuration
parameters that have been defined by an administrator
 Two connection factories come preconfigured with the
J2EE SDK
 are accessible as soon as you start the service.
 Each connection factory is an instance of one of the
following interfaces
 QueueConnectionFactory
 TopicConnectionFactory
 To create new objects use j2eeadmin
 j2eeadmin -addJmsFactory jndi_name queue
 j2eeadmin -addJmsFactory jndi_name topic
Example
/* the administrator creates the objects by typing on the command line:
j2eeadmin -addJmsFactory MyQueueConnectionFactory queue
j2eeadmin -addJmsFactory MyTopicConnectionFactory topic */
In the client code:
/* search the classpath for jndi.properties (vendor specific file) */
Context ctx = new InitialContext();
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)ctx.lookup(“MyQueueConnectionFactory");
TopicConnectionFactory topicConnectionFactory =
TopicConnectionFactory) ctx.lookup(“MyTopicConnectionFactory");
/* now the client has references to the objects */
Destinations
 A destination is the object a client uses to specify
 the target of messages it produces
 and the source of messages it consumes.
 In the PTP messaging domain, destinations are called
queues, and you use the following J2EE SDK command to
create them:
 j2eeadmin -addJmsDestination queue_name queue
 In the pub/sub messaging domain, destinations are called
topics, and you use the following J2EE SDK command to
create them:
 j2eeadmin -addJmsDestination topic_name topic
Example
/* assume the administrator has created the the topic Mytopic by typing :
j2eeadmin -addJmsDestination MyTopic topic *.
/* in the client program to get a referance to it : */
Topic myTopic = (Topic) ctx.lookup("MyTopic");
/* assume the administrator has created the queue MyQueue by typing :
j2eeadmin -addJmsDestination MyQueue queue *.
/* in the client program to get a referance to it : */
Queue myQueue = (Queue) ctx.lookup("MyQueue");
Connections
 A connection encapsulates a virtual
connection with a JMS provider. A
connection could represent an open
TCP/IP socket between a client and a
provider service daemon. You use a
connection to create one or more
sessions.
 Like connection factories, connections
come in two forms:
 QueueConnection (interface)
 TopicConnection (interface)
Example
 For example, once you have a QueueConnectionFactory or a
TopicConnectionFactory object, you can use it to create a
connection
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection( );
TopicConnection topicConnection = topicConnectionFactory.createTopicConnection( );
/* when the application is complete, remember to close the connections: */
queueConnection.close( );
topicConnection.close( );
/* Before your application can consume messages, you must call the connection's start method */
queueConnection.start( );
topicConnection.start( );
/* To stop a connection temporarily use the stop( ) method */
queueConnection.stop( );
topicConnection.stop( );
Sessions
 A session is a single-threaded context for
producing and consuming messages.
 Use sessions to create message producers,
message consumers, and messages.
 Sessions serialize the execution of message
listeners
 Sessions, like connections, come in two forms:
 QueueSession (interface)
 TopicSession (interface)
Example
 For example, if you created a TopicConnection
object, you use it to create a TopicSession:
TopicSession topicSession =
topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
-or-
QueueSession queueSession =
queueConnection.createQueueSession(true, 0);
Message Producers
 A message producer is an object created by a
session and is used for sending messages to a
destination.
 The PTP form of a message producer implements
the QueueSender interface.
 The pub/sub form implements the TopicPublisher
interface.
Example
QueueSender queueSender = queueSession.createSender(myQueue);
queueSender.send(message); /* assuming that message is already created */
- or –
TopicPublisher topicPublisher = topicSession.createPublisher(myTopic);
topicPublisher.publish(message);
Message Consumers
 A message consumer is an object created by
a session and is used for receiving messages
sent to a destination.
 A message consumer allows a JMS client to register
interest in a destination with a JMS provider.
 The JMS provider manages the delivery of messages
from a destination to the registered consumers of
the destination.
 The PTP form of message consumer implements the
QueueReceiver interface.
 The pub/sub form implements the TopicSubscriber
interface.
Example
For example, you use a QueueSession to create a receiver for the queue myQueue, and
you use a TopicSession to create a subscriber for the topic myTopic:
QueueReceiver queueReceiver = queueSession.createReceiver(myQueue);
TopicSubscriber topicSubscriber = topicSession.createSubscriber(myTopic);
- or –
TopicSubscriber topicSubscriber = topicSession.createDurableSubscriber(myTopic);
/ * Once you have created a message consumer, it becomes active, and you can use it to
receive messages. */
Example
/* With either a QueueReceiver or a TopicSubscriber, you use the receive method to consume
a message synchronously. You can use this method at any time after you call the start
method: */
queueConnection.start(); Message m = queueReceiver.receive( );
- or -
topicConnection.start(); Message m = topicSubscriber.receive(1000); // time out after a sec.
/* To consume a message asynchronously, you use a message listener */
Message Listeners
 A message listener is an object that acts as an asynchronous
event handler for messages.
 This object implements the MessageListener interface,
 contains one method, onMessage.
 In the onMessage method, you define the actions to be taken
when a message arrives.
Example
/* You register the message listener with a specific QueueReceiver or TopicSubscriber by
using the setMessageListener method. For example, if you define a class named
TopicListener that implements the MessageListener interface, you can register the
message listener as follows: */
TopicListener topicListener = new TopicListener( );
topicSubscriber.setMessageListener(topicListener);
After you register the message listener, you call the start method on the QueueConnection
or the TopicConnection to begin message delivery. (If you call start before you register
the message listener, you are likely to miss messages.)
Once message delivery begins, the message consumer automatically calls the message
listener's onMessage method whenever a message is delivered. The onMessage method
takes one argument of type Message, which the method can cast to any of the other
message types
Messages
 A message consists of
 a header
 destination, timestamp...
 properties (optional)
 message properties allow message receivers to select
which types of messages they would like to receive.
 Message receivers use message selectors to filter out
messages (filtering is done at the server)
 a body (optional)
 information part of the message
Java Message Service
 The JMS API standardizes enterprise messaging
 APIs for point-to-point
 APIs for publish/subscribe
 JMS provides five types of messages
 BytesMessages
 MapMessages
 ObjectMessages
 StreamMessages
 TextMessages
JMS Availability
 The JMS Reference implementation is part of the J2EE SDK
 Allaire Corporation - JRun Server
 BEA Systems, Inc.
 Brokat Technologies (formerly GemStone)
 IBM
 iPlanet (formerly Sun Microsystems, Inc. Java Message Queue)
 Oracle Corporation
 Pramati
 SilverStream Software, Inc.
 Sonic Software
 SpiritSoft, Inc. (formerly Push Technologies Ltd.)
 Talarian Corp.
 TIBCO Software, Inc.

More Related Content

What's hot

Brokered Messaging in Windows Azure
Brokered Messaging in Windows AzureBrokered Messaging in Windows Azure
Brokered Messaging in Windows AzureNeil Mackenzie
 
Understanding JMS Integration Patterns
Understanding JMS Integration Patterns Understanding JMS Integration Patterns
Understanding JMS Integration Patterns WSO2
 
Java servlets
Java servletsJava servlets
Java servletslopjuan
 
Azure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistAzure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistSalim M Bhonhariya
 
Jsr120 sup
Jsr120 supJsr120 sup
Jsr120 supSMIJava
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technologyvikram singh
 

What's hot (13)

Spring JMS
Spring JMSSpring JMS
Spring JMS
 
Jms using j boss
Jms using j bossJms using j boss
Jms using j boss
 
Brokered Messaging in Windows Azure
Brokered Messaging in Windows AzureBrokered Messaging in Windows Azure
Brokered Messaging in Windows Azure
 
Understanding JMS Integration Patterns
Understanding JMS Integration Patterns Understanding JMS Integration Patterns
Understanding JMS Integration Patterns
 
Java servlets
Java servletsJava servlets
Java servlets
 
Azure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistAzure Service Bus Performance Checklist
Azure Service Bus Performance Checklist
 
Messaging in Java
Messaging in JavaMessaging in Java
Messaging in Java
 
Jsr120 sup
Jsr120 supJsr120 sup
Jsr120 sup
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
Servlets
ServletsServlets
Servlets
 

Similar to Java Messaging Services

Similar to Java Messaging Services (20)

test validation
test validationtest validation
test validation
 
Test DB user
Test DB userTest DB user
Test DB user
 
JMS
JMSJMS
JMS
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
Java Message Service
Java Message ServiceJava Message Service
Java Message Service
 
Jms
JmsJms
Jms
 
Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS
 
#8 (Java Message Service)
#8 (Java Message Service)#8 (Java Message Service)
#8 (Java Message Service)
 
Jms queues
Jms queuesJms queues
Jms queues
 
Message Driven Beans (6)
Message Driven Beans (6)Message Driven Beans (6)
Message Driven Beans (6)
 
#7 (Java Message Service)
#7 (Java Message Service)#7 (Java Message Service)
#7 (Java Message Service)
 
Jms topics
Jms topicsJms topics
Jms topics
 
Mule jms-topics
Mule jms-topicsMule jms-topics
Mule jms-topics
 
Apache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache CamelApache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache Camel
 

More from kumar gaurav

Need Of Enterprise Integration
Need Of Enterprise IntegrationNeed Of Enterprise Integration
Need Of Enterprise Integrationkumar gaurav
 
Mulesoft file connector
Mulesoft file connectorMulesoft file connector
Mulesoft file connectorkumar gaurav
 
Mulesoft http connector
Mulesoft http connectorMulesoft http connector
Mulesoft http connectorkumar gaurav
 
Reason to connect with Mulesoft
Reason to connect with MulesoftReason to connect with Mulesoft
Reason to connect with Mulesoftkumar gaurav
 
Mulesoft idempotent Message Filter
Mulesoft idempotent Message FilterMulesoft idempotent Message Filter
Mulesoft idempotent Message Filterkumar gaurav
 
Mulesoft Using Groovy Component
Mulesoft Using Groovy ComponentMulesoft Using Groovy Component
Mulesoft Using Groovy Componentkumar gaurav
 
Mulesoft vm transport reference
Mulesoft vm transport referenceMulesoft vm transport reference
Mulesoft vm transport referencekumar gaurav
 
Mulesoft Calling Flow of Other Applications
Mulesoft Calling Flow of Other ApplicationsMulesoft Calling Flow of Other Applications
Mulesoft Calling Flow of Other Applicationskumar gaurav
 
Mulesoft Solutions for Mobile
Mulesoft Solutions for MobileMulesoft Solutions for Mobile
Mulesoft Solutions for Mobilekumar gaurav
 
Mulesoft Solutions for SOA
Mulesoft Solutions for SOAMulesoft Solutions for SOA
Mulesoft Solutions for SOAkumar gaurav
 
Mulesoft Solutions for IoT
Mulesoft Solutions for IoTMulesoft Solutions for IoT
Mulesoft Solutions for IoTkumar gaurav
 
Mulesoft Anypoint platform for APIs
Mulesoft Anypoint platform for APIsMulesoft Anypoint platform for APIs
Mulesoft Anypoint platform for APIskumar gaurav
 
Oracle Managed Files Transfer- Key based authentication
Oracle Managed Files Transfer- Key based authenticationOracle Managed Files Transfer- Key based authentication
Oracle Managed Files Transfer- Key based authenticationkumar gaurav
 
Java collections concept
Java collections conceptJava collections concept
Java collections conceptkumar gaurav
 
Struggle that counts
Struggle that countsStruggle that counts
Struggle that countskumar gaurav
 
MySQL index optimization techniques
MySQL index optimization techniquesMySQL index optimization techniques
MySQL index optimization techniqueskumar gaurav
 
Security guidelines for web development
Security guidelines for web developmentSecurity guidelines for web development
Security guidelines for web developmentkumar gaurav
 
Oracle web center suit
Oracle web center suitOracle web center suit
Oracle web center suitkumar gaurav
 

More from kumar gaurav (20)

Need Of Enterprise Integration
Need Of Enterprise IntegrationNeed Of Enterprise Integration
Need Of Enterprise Integration
 
Mulesoft file connector
Mulesoft file connectorMulesoft file connector
Mulesoft file connector
 
Mulesoft http connector
Mulesoft http connectorMulesoft http connector
Mulesoft http connector
 
Reason to connect with Mulesoft
Reason to connect with MulesoftReason to connect with Mulesoft
Reason to connect with Mulesoft
 
Mulesoft idempotent Message Filter
Mulesoft idempotent Message FilterMulesoft idempotent Message Filter
Mulesoft idempotent Message Filter
 
Mulesoft Using Groovy Component
Mulesoft Using Groovy ComponentMulesoft Using Groovy Component
Mulesoft Using Groovy Component
 
Mulesoft vm transport reference
Mulesoft vm transport referenceMulesoft vm transport reference
Mulesoft vm transport reference
 
Mulesoft Calling Flow of Other Applications
Mulesoft Calling Flow of Other ApplicationsMulesoft Calling Flow of Other Applications
Mulesoft Calling Flow of Other Applications
 
Mulesoft Solutions for Mobile
Mulesoft Solutions for MobileMulesoft Solutions for Mobile
Mulesoft Solutions for Mobile
 
Mulesoft Solutions for SOA
Mulesoft Solutions for SOAMulesoft Solutions for SOA
Mulesoft Solutions for SOA
 
Mulesoft Solutions for IoT
Mulesoft Solutions for IoTMulesoft Solutions for IoT
Mulesoft Solutions for IoT
 
Mulesoft Anypoint platform for APIs
Mulesoft Anypoint platform for APIsMulesoft Anypoint platform for APIs
Mulesoft Anypoint platform for APIs
 
Oracle Managed Files Transfer- Key based authentication
Oracle Managed Files Transfer- Key based authenticationOracle Managed Files Transfer- Key based authentication
Oracle Managed Files Transfer- Key based authentication
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Struggle that counts
Struggle that countsStruggle that counts
Struggle that counts
 
Team Work
Team WorkTeam Work
Team Work
 
MySQL index optimization techniques
MySQL index optimization techniquesMySQL index optimization techniques
MySQL index optimization techniques
 
Security guidelines for web development
Security guidelines for web developmentSecurity guidelines for web development
Security guidelines for web development
 
Java web services
Java web servicesJava web services
Java web services
 
Oracle web center suit
Oracle web center suitOracle web center suit
Oracle web center suit
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Java Messaging Services

  • 2. Messaging Systems  A messaging System allows and promotes the loose coupling of components  allows components to post messages for other components  asynchronous rather than synchronous  also known as MOM (Message-Oriented Middleware  Two basic models  point-to-point  one component posts a message to a server  one component (and only one) will consume a posted message  publish/subscribe  allows a component to publish a message to a topic on a server  components interested in a particular topic can subscribe to that topic (messages can be consumed by a number of components)  when a component publishes a message, it subscribes to that topic and will receive the message
  • 3. What Does JMS Do  A Java API that allows applications to:  create  send  receive  read messages  in principle kind of like a news system, but doesn’t involve e-mail
  • 4. Architecture  A JMS Application consists of :  A JMS Provider  a messaging system that implements the JMS interfaces and provides administrative and control features  included in Java since JDK 1.3  JMS Clients  Java programs/components/objects that produce and consume messages  Administered Objects  preconfigured JMS objects created by an administrator for the use of clients  destinations  connection factories  Native Clients  a non-Java program that uses a products native API instead of the JMS API  a legacy application modified to use the JMS API
  • 6. Interaction  The administrator binds connection factories (CF) and destinations (D) into a JNDI namespace.  A JMS client can then lookup the administered objects and establish a logical connection to them via the JMS Provider
  • 7. Point-to-Point Messaging Domain  Applications are built around the concepts of message queues, senders and receivers  Queues retain all messages until they are either:  consumed  expire  Each message has only one consumer  There are no timing dependencies  The receiver acknowledges the successful processing of a message
  • 9. Publish/Subscribe Messaging Domain  Clients address messages to a topic  Publishers and Subscribers are generally anonymous and may dynamically publish or subscribe to the content hierarchy  Topics retain messages only long enough to distribute them to their current subscribers  Use publish/scribe messaging when each message can be processed by zero, one or many consumers  durable subscriptions exist for subscribers not currently active
  • 11. Message Consumption  In JMS messages can be consumed in two ways:  Synchronously  a subscriber or receiver explicitly fetches a message from the destination using the “receive” method  the “receive” method can block until a message arrives or can time out if a message does not arrive within a specified time limit  Asynchronously  a client can register a message listener (like an event listener) with a consumer  whenever a message arrives at the destination the JMS Provider delivers the message by calling the listener’s “onMessage” method which acts on the contents of the message
  • 13. Administered Objects  Administration is better done using vendor supplied tools rather than programmatically due to vendor implementation differences  j2eeadmin - j2ee sdk administration tool  Administered objects are configured in a JNDI namespace  Connection Factories  Destinations
  • 14. Connection Factories  A connection factory object is used by a client to create a connection with a provider.  It encapsulates a set of connection configuration parameters that have been defined by an administrator  Two connection factories come preconfigured with the J2EE SDK  are accessible as soon as you start the service.  Each connection factory is an instance of one of the following interfaces  QueueConnectionFactory  TopicConnectionFactory  To create new objects use j2eeadmin  j2eeadmin -addJmsFactory jndi_name queue  j2eeadmin -addJmsFactory jndi_name topic
  • 15. Example /* the administrator creates the objects by typing on the command line: j2eeadmin -addJmsFactory MyQueueConnectionFactory queue j2eeadmin -addJmsFactory MyTopicConnectionFactory topic */ In the client code: /* search the classpath for jndi.properties (vendor specific file) */ Context ctx = new InitialContext(); QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)ctx.lookup(“MyQueueConnectionFactory"); TopicConnectionFactory topicConnectionFactory = TopicConnectionFactory) ctx.lookup(“MyTopicConnectionFactory"); /* now the client has references to the objects */
  • 16. Destinations  A destination is the object a client uses to specify  the target of messages it produces  and the source of messages it consumes.  In the PTP messaging domain, destinations are called queues, and you use the following J2EE SDK command to create them:  j2eeadmin -addJmsDestination queue_name queue  In the pub/sub messaging domain, destinations are called topics, and you use the following J2EE SDK command to create them:  j2eeadmin -addJmsDestination topic_name topic
  • 17. Example /* assume the administrator has created the the topic Mytopic by typing : j2eeadmin -addJmsDestination MyTopic topic *. /* in the client program to get a referance to it : */ Topic myTopic = (Topic) ctx.lookup("MyTopic"); /* assume the administrator has created the queue MyQueue by typing : j2eeadmin -addJmsDestination MyQueue queue *. /* in the client program to get a referance to it : */ Queue myQueue = (Queue) ctx.lookup("MyQueue");
  • 18. Connections  A connection encapsulates a virtual connection with a JMS provider. A connection could represent an open TCP/IP socket between a client and a provider service daemon. You use a connection to create one or more sessions.  Like connection factories, connections come in two forms:  QueueConnection (interface)  TopicConnection (interface)
  • 19. Example  For example, once you have a QueueConnectionFactory or a TopicConnectionFactory object, you can use it to create a connection QueueConnection queueConnection = queueConnectionFactory.createQueueConnection( ); TopicConnection topicConnection = topicConnectionFactory.createTopicConnection( ); /* when the application is complete, remember to close the connections: */ queueConnection.close( ); topicConnection.close( ); /* Before your application can consume messages, you must call the connection's start method */ queueConnection.start( ); topicConnection.start( ); /* To stop a connection temporarily use the stop( ) method */ queueConnection.stop( ); topicConnection.stop( );
  • 20. Sessions  A session is a single-threaded context for producing and consuming messages.  Use sessions to create message producers, message consumers, and messages.  Sessions serialize the execution of message listeners  Sessions, like connections, come in two forms:  QueueSession (interface)  TopicSession (interface)
  • 21. Example  For example, if you created a TopicConnection object, you use it to create a TopicSession: TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); -or- QueueSession queueSession = queueConnection.createQueueSession(true, 0);
  • 22. Message Producers  A message producer is an object created by a session and is used for sending messages to a destination.  The PTP form of a message producer implements the QueueSender interface.  The pub/sub form implements the TopicPublisher interface.
  • 23. Example QueueSender queueSender = queueSession.createSender(myQueue); queueSender.send(message); /* assuming that message is already created */ - or – TopicPublisher topicPublisher = topicSession.createPublisher(myTopic); topicPublisher.publish(message);
  • 24. Message Consumers  A message consumer is an object created by a session and is used for receiving messages sent to a destination.  A message consumer allows a JMS client to register interest in a destination with a JMS provider.  The JMS provider manages the delivery of messages from a destination to the registered consumers of the destination.  The PTP form of message consumer implements the QueueReceiver interface.  The pub/sub form implements the TopicSubscriber interface.
  • 25. Example For example, you use a QueueSession to create a receiver for the queue myQueue, and you use a TopicSession to create a subscriber for the topic myTopic: QueueReceiver queueReceiver = queueSession.createReceiver(myQueue); TopicSubscriber topicSubscriber = topicSession.createSubscriber(myTopic); - or – TopicSubscriber topicSubscriber = topicSession.createDurableSubscriber(myTopic); / * Once you have created a message consumer, it becomes active, and you can use it to receive messages. */
  • 26. Example /* With either a QueueReceiver or a TopicSubscriber, you use the receive method to consume a message synchronously. You can use this method at any time after you call the start method: */ queueConnection.start(); Message m = queueReceiver.receive( ); - or - topicConnection.start(); Message m = topicSubscriber.receive(1000); // time out after a sec. /* To consume a message asynchronously, you use a message listener */
  • 27. Message Listeners  A message listener is an object that acts as an asynchronous event handler for messages.  This object implements the MessageListener interface,  contains one method, onMessage.  In the onMessage method, you define the actions to be taken when a message arrives.
  • 28. Example /* You register the message listener with a specific QueueReceiver or TopicSubscriber by using the setMessageListener method. For example, if you define a class named TopicListener that implements the MessageListener interface, you can register the message listener as follows: */ TopicListener topicListener = new TopicListener( ); topicSubscriber.setMessageListener(topicListener); After you register the message listener, you call the start method on the QueueConnection or the TopicConnection to begin message delivery. (If you call start before you register the message listener, you are likely to miss messages.) Once message delivery begins, the message consumer automatically calls the message listener's onMessage method whenever a message is delivered. The onMessage method takes one argument of type Message, which the method can cast to any of the other message types
  • 29. Messages  A message consists of  a header  destination, timestamp...  properties (optional)  message properties allow message receivers to select which types of messages they would like to receive.  Message receivers use message selectors to filter out messages (filtering is done at the server)  a body (optional)  information part of the message
  • 30. Java Message Service  The JMS API standardizes enterprise messaging  APIs for point-to-point  APIs for publish/subscribe  JMS provides five types of messages  BytesMessages  MapMessages  ObjectMessages  StreamMessages  TextMessages
  • 31. JMS Availability  The JMS Reference implementation is part of the J2EE SDK  Allaire Corporation - JRun Server  BEA Systems, Inc.  Brokat Technologies (formerly GemStone)  IBM  iPlanet (formerly Sun Microsystems, Inc. Java Message Queue)  Oracle Corporation  Pramati  SilverStream Software, Inc.  Sonic Software  SpiritSoft, Inc. (formerly Push Technologies Ltd.)  Talarian Corp.  TIBCO Software, Inc.