SlideShare a Scribd company logo
1 of 15
A Study in JMS
(Java Messaging
Service)
BY
Prabhat Gangwar
JMS OverviewJMS Overview
The Java Message Service is a Java API that
allows applications to create, send, receive,
and read messages
The JMS API minimizes the set of concepts a
programmer must learn to use messaging
products but provides enough features to
support sophisticated messaging applications
JMS Overview (cont)JMS Overview (cont)
The JMS API enables communication that is
not only loosely coupled but also:
Asynchronous. A JMS provider can deliver
messages to a client as they arrive; a client does
not have to request messages in order to receive
them.
Reliable. The JMS API can ensure that a
message is delivered once and only once. Lower
levels of reliability are available for applications
that can afford to miss messages or to receive
duplicate messages.
JMS Overview (cont)JMS Overview (cont)
Messages can be consumed in either of two ways:
Synchronously. A subscriber or a receiver explicitly fetches
the message from the destination by calling 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
with a consumer. A message listener is similar to an event
listener. 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.
JMS And JNDIJMS And JNDI
JMS does not not define a standard address syntax by which
clients communicate with each other. Instead JMS utilizes Java
Naming & Directory Interface(JNDI).
JNDI provides a mechanism by which clients can perform a
“lookup” to find the correct information to connect to each other.
Using JNDI provides the following advantages:
It hides provider-specific details from JMS clients.
It abstracts JMS administrative information into Java objects that
are easily organized and administrated from a common
management console.
Since there will be JNDI providers for all popular naming services,
this means JMS providers can deliver one implementation of
administered objects that will run everywhere. Thereby eliminating
deployment and configuration issues.
JMS Advantages over RPCJMS Advantages over RPC
RPC relies on the physical connection of the client
and server to the network; it is a synchronous
protocol.
What happens if the client is disconnected?
Network could go down
Client could be a laptop that is used on the road.
In this case, the end user might still want to carry on
working, but can't if an RPC model is being used—at
least not without a great deal of work by the
programmer.
Messaging BenefitsMessaging Benefits
JMS vs RPCJMS vs RPC
Messaging provides the ability to send data
asynchronously and in a disconnected manner.
Two messaging models
Point-to-point
Publish-and-Subscribe
In an email like model, these would be equivalent to
sending and receiving e-mails directly (point-to-point),
or subscribing to a list server and sending and
receiving e-mails through the list server (publish-and-
subscribe).
What is the cost?What is the cost?
JMS vs RPCJMS vs RPC
Applications become asynchronous by nature
What if we require a method to give us a return
value?
What if we require the data (the messages) to be
delivered in a specific order?
Using messaging, JMS, we have to deal with
these problems ourselves. RPC handled
these issues for the programmer.
Messages ExplainedMessages Explained
A message typically consists of a header and a body.
The message header contains vendor-specified
values, but could also contain application-specific
data as well.
Headers are typically name/value pairs.
The body contains data; the type of the data is
defined by the specification.
Text
A serialized Java object
One of a number of other types of data.
Publisher SamplePublisher Sample
See MyTopicPublisher.java for source.
1. Perform a JNDI API lookup of the TopicConnectionFactory and topic
topic = (Topic) jndiContext.lookup(topicName);
2. Create a connection and a session
topicConnection = topicConnectionFactory.createTopicConnection();
topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
3. Create a TopicPublisher
topicPublisher = topicSession.createPublisher(topic);
4. Create a TextMessage
Message = topicSession.createTextMessage();
message.setText("This is message " + (i + 1));
5. Publishe one or more messages to the topic
topicPublisher.publish(message);
6. Close the connection, which automatically closes the session and
TopicPublisher
Subscriber SampleSubscriber Sample
See MyTopicSubscriber.java for source.
1.Perform a JNDI API lookup of the TopicConnectionFactory and
topic (same as publisher)
2.Create a connection and a session (same as publisher)
3.Create a TopicSubscriber
topicSubscriber = topicSession.createSubscriber(topic);
4.Create an instance of the TextListener class and registers it as
the message listener for the TopicSubscriber
topicListener = new TextListener();
topicSubscriber.setMessageListener(topicListener);
5.Start the connection, causing message delivery to begin
topicConnection.start();
6.Close the connection, which automatically closes the session
and TopicSubscriber
topicConnection.close();
TextListener SampleTextListener Sample
1. public void onMessage(Message message) {
2. TextMessage msg = null;
3.
4. try {
5. if (message instanceof TextMessage) {
6. msg = (TextMessage) message;
7. System.out.println("Reading message: " + msg.getText());
8. } else {
9. System.out.println("Message of wrong type: " +
10. message.getClass().getName());
11. }
12. } catch (JMSException e) {
13. System.out.println("JMSException in onMessage(): " + e.toString());
14. } catch (Throwable t) {
15. System.out.println("Exception in onMessage():" + t.getMessage());
16. }
17.}
Running The SampleRunning The Sample
1. Start the JMS provider. In this case the J2EE SDK
From a command prompt run the following command:
j2ee –verbose
Wait until the server displays the message "J2EE server startup
complete
1. Create the Administered Object. This is the object to which
you will publish and subscribe.
From a second command prompt run the following command
j2eeadmin -addJmsDestination CS522Topic topic
To verify the topic was created, view the list of Administered
Objects by typing:
j2eeadmin –listJmsDestination
Running The Sample (cont)Running The Sample (cont)
3. Run the subscriber program
From a command prompt run the following command within the
directory that contains the MyTopicSubscriber.class:
java -Djms.properties=%J2EE_HOME
%configjms_client.properties MyTopicSubscriber
-topic=CS522Topic
3. Run the Publisher program
From a command prompt run the following command within the
directory that contains the MyTopicPublisher.class:
java -Djms.properties=%J2EE_HOME
%configjms_client.properties MyTopicPublisher
-topic=CS522Topic -count=500 -delay=500
5. You will see text output in both the Publisher and Subscriber
windows
ReferencesReferences
http://java.sun.com/products/jms/tutorial/1_3_1
http://java.sun.com/products/jndi/

More Related Content

What's hot (20)

Spring JMS
Spring JMSSpring JMS
Spring JMS
 
Jms intro
Jms introJms intro
Jms intro
 
Jms
JmsJms
Jms
 
Enterprise messaging with jms
Enterprise messaging with jmsEnterprise messaging with jms
Enterprise messaging with jms
 
Mom those things v1
Mom those things v1 Mom those things v1
Mom those things v1
 
Jms
JmsJms
Jms
 
Jms
JmsJms
Jms
 
Java message service
Java message serviceJava message service
Java message service
 
JMS Providers Overview
JMS Providers OverviewJMS Providers Overview
JMS Providers Overview
 
Jms
JmsJms
Jms
 
Jms deep dive [con4864]
Jms deep dive [con4864]Jms deep dive [con4864]
Jms deep dive [con4864]
 
Messaging in Java
Messaging in JavaMessaging in Java
Messaging in Java
 
Message Driven Beans (6)
Message Driven Beans (6)Message Driven Beans (6)
Message Driven Beans (6)
 
Mule jms-topics
Mule jms-topicsMule jms-topics
Mule jms-topics
 
19 08-22 introduction to activeMQ
19 08-22 introduction to activeMQ19 08-22 introduction to activeMQ
19 08-22 introduction to activeMQ
 
An Introduction to the Message Queuning Technology
An Introduction to the Message Queuning TechnologyAn Introduction to the Message Queuning Technology
An Introduction to the Message Queuning Technology
 
Wcf faq
Wcf faqWcf faq
Wcf faq
 
Jms session (1)
Jms session (1)Jms session (1)
Jms session (1)
 
Introduction tojms
Introduction tojmsIntroduction tojms
Introduction tojms
 
Weblogic - Introduction to configure JMS
Weblogic  - Introduction to configure JMSWeblogic  - Introduction to configure JMS
Weblogic - Introduction to configure JMS
 

Viewers also liked

JMS java messaging service
JMS java messaging serviceJMS java messaging service
JMS java messaging servicePROSKAR
 
WSO2Con US 2013 - Creating the API Centric Enterprise Towards a Connected Bus...
WSO2Con US 2013 - Creating the API Centric Enterprise Towards a Connected Bus...WSO2Con US 2013 - Creating the API Centric Enterprise Towards a Connected Bus...
WSO2Con US 2013 - Creating the API Centric Enterprise Towards a Connected Bus...WSO2
 
SnapLogic Adds Support for Kafka and HDInsight to Elastic Integration Platform
SnapLogic Adds Support for Kafka and HDInsight to Elastic Integration PlatformSnapLogic Adds Support for Kafka and HDInsight to Elastic Integration Platform
SnapLogic Adds Support for Kafka and HDInsight to Elastic Integration PlatformSnapLogic
 
IPAAS_information on your terms
IPAAS_information on your termsIPAAS_information on your terms
IPAAS_information on your termsMarket Engel SAS
 
Cloud-Con: Integration & Web APIs
Cloud-Con: Integration & Web APIsCloud-Con: Integration & Web APIs
Cloud-Con: Integration & Web APIsSnapLogic
 
Anypoint mq (mulesoft) introduction
Anypoint mq (mulesoft)  introductionAnypoint mq (mulesoft)  introduction
Anypoint mq (mulesoft) introductionKarthik Selvaraj
 
SnapLogic's Latest Elastic iPaaS Release Adds Hybrid Links for Spark, Cortana...
SnapLogic's Latest Elastic iPaaS Release Adds Hybrid Links for Spark, Cortana...SnapLogic's Latest Elastic iPaaS Release Adds Hybrid Links for Spark, Cortana...
SnapLogic's Latest Elastic iPaaS Release Adds Hybrid Links for Spark, Cortana...SnapLogic
 
Cloud fuse-apachecon eu-2012
Cloud fuse-apachecon eu-2012Cloud fuse-apachecon eu-2012
Cloud fuse-apachecon eu-2012Charles Moulliard
 
API Athens Meetup - API standards 22.03.2016
API Athens Meetup - API standards 22.03.2016API Athens Meetup - API standards 22.03.2016
API Athens Meetup - API standards 22.03.2016Ivan Goncharov
 
MQ Light for Bluemix - IBM Interconnect 2015 session AME4183
MQ Light for Bluemix - IBM Interconnect 2015 session AME4183MQ Light for Bluemix - IBM Interconnect 2015 session AME4183
MQ Light for Bluemix - IBM Interconnect 2015 session AME4183Robert Nicholson
 
MuleSoft CloudHub FAQ
MuleSoft CloudHub FAQMuleSoft CloudHub FAQ
MuleSoft CloudHub FAQShanky Gupta
 
Business Agility through Self-Service Messaging - InterConnect 2016
Business Agility through Self-Service Messaging - InterConnect 2016Business Agility through Self-Service Messaging - InterConnect 2016
Business Agility through Self-Service Messaging - InterConnect 2016Leif Davidsen
 
IPaaS: Cloud Integration Analysis
IPaaS: Cloud Integration AnalysisIPaaS: Cloud Integration Analysis
IPaaS: Cloud Integration AnalysisJesus Rodriguez
 

Viewers also liked (16)

FINAL
FINALFINAL
FINAL
 
Dr Deepak cv
Dr Deepak cvDr Deepak cv
Dr Deepak cv
 
JMS java messaging service
JMS java messaging serviceJMS java messaging service
JMS java messaging service
 
WSO2Con US 2013 - Creating the API Centric Enterprise Towards a Connected Bus...
WSO2Con US 2013 - Creating the API Centric Enterprise Towards a Connected Bus...WSO2Con US 2013 - Creating the API Centric Enterprise Towards a Connected Bus...
WSO2Con US 2013 - Creating the API Centric Enterprise Towards a Connected Bus...
 
SnapLogic Adds Support for Kafka and HDInsight to Elastic Integration Platform
SnapLogic Adds Support for Kafka and HDInsight to Elastic Integration PlatformSnapLogic Adds Support for Kafka and HDInsight to Elastic Integration Platform
SnapLogic Adds Support for Kafka and HDInsight to Elastic Integration Platform
 
IPAAS_information on your terms
IPAAS_information on your termsIPAAS_information on your terms
IPAAS_information on your terms
 
Cloud-Con: Integration & Web APIs
Cloud-Con: Integration & Web APIsCloud-Con: Integration & Web APIs
Cloud-Con: Integration & Web APIs
 
Anypoint mq (mulesoft) introduction
Anypoint mq (mulesoft)  introductionAnypoint mq (mulesoft)  introduction
Anypoint mq (mulesoft) introduction
 
IPaaS
IPaaSIPaaS
IPaaS
 
SnapLogic's Latest Elastic iPaaS Release Adds Hybrid Links for Spark, Cortana...
SnapLogic's Latest Elastic iPaaS Release Adds Hybrid Links for Spark, Cortana...SnapLogic's Latest Elastic iPaaS Release Adds Hybrid Links for Spark, Cortana...
SnapLogic's Latest Elastic iPaaS Release Adds Hybrid Links for Spark, Cortana...
 
Cloud fuse-apachecon eu-2012
Cloud fuse-apachecon eu-2012Cloud fuse-apachecon eu-2012
Cloud fuse-apachecon eu-2012
 
API Athens Meetup - API standards 22.03.2016
API Athens Meetup - API standards 22.03.2016API Athens Meetup - API standards 22.03.2016
API Athens Meetup - API standards 22.03.2016
 
MQ Light for Bluemix - IBM Interconnect 2015 session AME4183
MQ Light for Bluemix - IBM Interconnect 2015 session AME4183MQ Light for Bluemix - IBM Interconnect 2015 session AME4183
MQ Light for Bluemix - IBM Interconnect 2015 session AME4183
 
MuleSoft CloudHub FAQ
MuleSoft CloudHub FAQMuleSoft CloudHub FAQ
MuleSoft CloudHub FAQ
 
Business Agility through Self-Service Messaging - InterConnect 2016
Business Agility through Self-Service Messaging - InterConnect 2016Business Agility through Self-Service Messaging - InterConnect 2016
Business Agility through Self-Service Messaging - InterConnect 2016
 
IPaaS: Cloud Integration Analysis
IPaaS: Cloud Integration AnalysisIPaaS: Cloud Integration Analysis
IPaaS: Cloud Integration Analysis
 

Similar to Study JMS (Java Messaging Service) API for asynchronous messaging

test validation
test validationtest validation
test validationtechweb08
 
Test DB user
Test DB userTest DB user
Test DB usertechweb08
 
Apache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache CamelApache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache CamelOmi Om
 
What's new in JMS 2.0 - OTN Bangalore 2013
What's new in JMS 2.0 - OTN Bangalore 2013What's new in JMS 2.0 - OTN Bangalore 2013
What's new in JMS 2.0 - OTN Bangalore 2013Jagadish Prasath
 
#7 (Java Message Service)
#7 (Java Message Service)#7 (Java Message Service)
#7 (Java Message Service)Ghadeer AlHasan
 
WebLogic JMS System Best Practices
WebLogic JMS System Best PracticesWebLogic JMS System Best Practices
WebLogic JMS System Best PracticesTrivadis
 
ActiveMQ Configuration
ActiveMQ ConfigurationActiveMQ Configuration
ActiveMQ ConfigurationAshish Mishra
 
Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS Arvind Kumar G.S
 
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021StreamNative
 
ActiveMQ interview Questions and Answers
ActiveMQ interview Questions and AnswersActiveMQ interview Questions and Answers
ActiveMQ interview Questions and Answersjeetendra mandal
 
Jms слайды
Jms слайдыJms слайды
Jms слайдыSergey D
 
Indianapolis mule soft_meetup_12_june_2021
Indianapolis mule soft_meetup_12_june_2021Indianapolis mule soft_meetup_12_june_2021
Indianapolis mule soft_meetup_12_june_2021ikram_ahamed
 
Java Messaging Services
Java Messaging ServicesJava Messaging Services
Java Messaging Serviceskumar gaurav
 
High powered messaging with RabbitMQ
High powered messaging with RabbitMQHigh powered messaging with RabbitMQ
High powered messaging with RabbitMQJames Carr
 

Similar to Study JMS (Java Messaging Service) API for asynchronous messaging (20)

Jms
JmsJms
Jms
 
test validation
test validationtest validation
test validation
 
Test DB user
Test DB userTest DB user
Test DB user
 
Apache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache CamelApache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache Camel
 
What's new in JMS 2.0 - OTN Bangalore 2013
What's new in JMS 2.0 - OTN Bangalore 2013What's new in JMS 2.0 - OTN Bangalore 2013
What's new in JMS 2.0 - OTN Bangalore 2013
 
About jms
About jmsAbout jms
About jms
 
#7 (Java Message Service)
#7 (Java Message Service)#7 (Java Message Service)
#7 (Java Message Service)
 
Mule jms
Mule   jmsMule   jms
Mule jms
 
WebLogic JMS System Best Practices
WebLogic JMS System Best PracticesWebLogic JMS System Best Practices
WebLogic JMS System Best Practices
 
Mule with jms
Mule with jmsMule with jms
Mule with jms
 
ActiveMQ Configuration
ActiveMQ ConfigurationActiveMQ Configuration
ActiveMQ Configuration
 
Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS
 
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
 
ActiveMQ interview Questions and Answers
ActiveMQ interview Questions and AnswersActiveMQ interview Questions and Answers
ActiveMQ interview Questions and Answers
 
Jms слайды
Jms слайдыJms слайды
Jms слайды
 
Jms topics
Jms topicsJms topics
Jms topics
 
Indianapolis mule soft_meetup_12_june_2021
Indianapolis mule soft_meetup_12_june_2021Indianapolis mule soft_meetup_12_june_2021
Indianapolis mule soft_meetup_12_june_2021
 
Java Messaging Services
Java Messaging ServicesJava Messaging Services
Java Messaging Services
 
High powered messaging with RabbitMQ
High powered messaging with RabbitMQHigh powered messaging with RabbitMQ
High powered messaging with RabbitMQ
 
Bpminto
BpmintoBpminto
Bpminto
 

More from Prabhat gangwar

More from Prabhat gangwar (20)

Middleware
MiddlewareMiddleware
Middleware
 
Pseudolocalization
PseudolocalizationPseudolocalization
Pseudolocalization
 
Mule anypoint studio
Mule anypoint studioMule anypoint studio
Mule anypoint studio
 
Mule anypoint platform
Mule anypoint platformMule anypoint platform
Mule anypoint platform
 
What is cluster analysis
What is cluster analysisWhat is cluster analysis
What is cluster analysis
 
clustering and load balancing
clustering and load balancingclustering and load balancing
clustering and load balancing
 
Middleware systems overview and introduction
Middleware systems overview and introductionMiddleware systems overview and introduction
Middleware systems overview and introduction
 
Restful api modeling language
Restful api modeling languageRestful api modeling language
Restful api modeling language
 
Mule esb
Mule esbMule esb
Mule esb
 
Mule fundamentals
Mule fundamentalsMule fundamentals
Mule fundamentals
 
Gsm architecture
Gsm architectureGsm architecture
Gsm architecture
 
Oracle vs-mulesoft-api-manager-features
Oracle vs-mulesoft-api-manager-featuresOracle vs-mulesoft-api-manager-features
Oracle vs-mulesoft-api-manager-features
 
Oracle real application_cluster
Oracle real application_clusterOracle real application_cluster
Oracle real application_cluster
 
Introducing adf business components
Introducing adf business componentsIntroducing adf business components
Introducing adf business components
 
File transfer methods
File transfer methodsFile transfer methods
File transfer methods
 
Ftp tftp
Ftp tftpFtp tftp
Ftp tftp
 
Bpm
BpmBpm
Bpm
 
Global warming
Global warmingGlobal warming
Global warming
 
Seo
SeoSeo
Seo
 
Vedic mathmetics
Vedic mathmeticsVedic mathmetics
Vedic mathmetics
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Study JMS (Java Messaging Service) API for asynchronous messaging

  • 1. A Study in JMS (Java Messaging Service) BY Prabhat Gangwar
  • 2. JMS OverviewJMS Overview The Java Message Service is a Java API that allows applications to create, send, receive, and read messages The JMS API minimizes the set of concepts a programmer must learn to use messaging products but provides enough features to support sophisticated messaging applications
  • 3. JMS Overview (cont)JMS Overview (cont) The JMS API enables communication that is not only loosely coupled but also: Asynchronous. A JMS provider can deliver messages to a client as they arrive; a client does not have to request messages in order to receive them. Reliable. The JMS API can ensure that a message is delivered once and only once. Lower levels of reliability are available for applications that can afford to miss messages or to receive duplicate messages.
  • 4. JMS Overview (cont)JMS Overview (cont) Messages can be consumed in either of two ways: Synchronously. A subscriber or a receiver explicitly fetches the message from the destination by calling 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 with a consumer. A message listener is similar to an event listener. 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.
  • 5. JMS And JNDIJMS And JNDI JMS does not not define a standard address syntax by which clients communicate with each other. Instead JMS utilizes Java Naming & Directory Interface(JNDI). JNDI provides a mechanism by which clients can perform a “lookup” to find the correct information to connect to each other. Using JNDI provides the following advantages: It hides provider-specific details from JMS clients. It abstracts JMS administrative information into Java objects that are easily organized and administrated from a common management console. Since there will be JNDI providers for all popular naming services, this means JMS providers can deliver one implementation of administered objects that will run everywhere. Thereby eliminating deployment and configuration issues.
  • 6. JMS Advantages over RPCJMS Advantages over RPC RPC relies on the physical connection of the client and server to the network; it is a synchronous protocol. What happens if the client is disconnected? Network could go down Client could be a laptop that is used on the road. In this case, the end user might still want to carry on working, but can't if an RPC model is being used—at least not without a great deal of work by the programmer.
  • 7. Messaging BenefitsMessaging Benefits JMS vs RPCJMS vs RPC Messaging provides the ability to send data asynchronously and in a disconnected manner. Two messaging models Point-to-point Publish-and-Subscribe In an email like model, these would be equivalent to sending and receiving e-mails directly (point-to-point), or subscribing to a list server and sending and receiving e-mails through the list server (publish-and- subscribe).
  • 8. What is the cost?What is the cost? JMS vs RPCJMS vs RPC Applications become asynchronous by nature What if we require a method to give us a return value? What if we require the data (the messages) to be delivered in a specific order? Using messaging, JMS, we have to deal with these problems ourselves. RPC handled these issues for the programmer.
  • 9. Messages ExplainedMessages Explained A message typically consists of a header and a body. The message header contains vendor-specified values, but could also contain application-specific data as well. Headers are typically name/value pairs. The body contains data; the type of the data is defined by the specification. Text A serialized Java object One of a number of other types of data.
  • 10. Publisher SamplePublisher Sample See MyTopicPublisher.java for source. 1. Perform a JNDI API lookup of the TopicConnectionFactory and topic topic = (Topic) jndiContext.lookup(topicName); 2. Create a connection and a session topicConnection = topicConnectionFactory.createTopicConnection(); topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); 3. Create a TopicPublisher topicPublisher = topicSession.createPublisher(topic); 4. Create a TextMessage Message = topicSession.createTextMessage(); message.setText("This is message " + (i + 1)); 5. Publishe one or more messages to the topic topicPublisher.publish(message); 6. Close the connection, which automatically closes the session and TopicPublisher
  • 11. Subscriber SampleSubscriber Sample See MyTopicSubscriber.java for source. 1.Perform a JNDI API lookup of the TopicConnectionFactory and topic (same as publisher) 2.Create a connection and a session (same as publisher) 3.Create a TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic); 4.Create an instance of the TextListener class and registers it as the message listener for the TopicSubscriber topicListener = new TextListener(); topicSubscriber.setMessageListener(topicListener); 5.Start the connection, causing message delivery to begin topicConnection.start(); 6.Close the connection, which automatically closes the session and TopicSubscriber topicConnection.close();
  • 12. TextListener SampleTextListener Sample 1. public void onMessage(Message message) { 2. TextMessage msg = null; 3. 4. try { 5. if (message instanceof TextMessage) { 6. msg = (TextMessage) message; 7. System.out.println("Reading message: " + msg.getText()); 8. } else { 9. System.out.println("Message of wrong type: " + 10. message.getClass().getName()); 11. } 12. } catch (JMSException e) { 13. System.out.println("JMSException in onMessage(): " + e.toString()); 14. } catch (Throwable t) { 15. System.out.println("Exception in onMessage():" + t.getMessage()); 16. } 17.}
  • 13. Running The SampleRunning The Sample 1. Start the JMS provider. In this case the J2EE SDK From a command prompt run the following command: j2ee –verbose Wait until the server displays the message "J2EE server startup complete 1. Create the Administered Object. This is the object to which you will publish and subscribe. From a second command prompt run the following command j2eeadmin -addJmsDestination CS522Topic topic To verify the topic was created, view the list of Administered Objects by typing: j2eeadmin –listJmsDestination
  • 14. Running The Sample (cont)Running The Sample (cont) 3. Run the subscriber program From a command prompt run the following command within the directory that contains the MyTopicSubscriber.class: java -Djms.properties=%J2EE_HOME %configjms_client.properties MyTopicSubscriber -topic=CS522Topic 3. Run the Publisher program From a command prompt run the following command within the directory that contains the MyTopicPublisher.class: java -Djms.properties=%J2EE_HOME %configjms_client.properties MyTopicPublisher -topic=CS522Topic -count=500 -delay=500 5. You will see text output in both the Publisher and Subscriber windows

Editor's Notes

  1. Although a standard address syntax was considered, it was decided that the differences in address semantics between existing MOM products was too wide to bridge with a single syntax.