SlideShare ist ein Scribd-Unternehmen logo
Distributed Systems
Lecture -7-
Created by :
Eng. Ghadeer Al Hasan
JMS
Java Message Service
Intro 1
• JMS (Java MessageService) is an API that provides the facilityto create, send and read messages.
• It provides looselycoupled, reliable and asynchronous communication.
• JMS is also known as a messaging service
Understanding Messaging 2
• Messaging is a technique to communicateapplications or software components.
• JMS is mainly usedto sendand receive messagefromone applicationto another.
Advantage of JMS 3
• Asynchronous: To receive the message, client is not required to send request. Message will arrive
automatically to the client.
• Reliable: It provides assurance that messageis delivered.
Messaging Domains 4
There are two types of messaging domains in JMS :
• Point-to-PointMessaging Domain
• Publisher/Subscriber Messaging Domain
Point-to-Point (PTP) Messaging Domain 5
• In PTP model, one message is delivered to one receiver only. Here, Queue is used as a message
oriented middleware (MOM).
• The Queue is responsible to hold the message until receiver is ready.
• In PTP model, there is no timing dependencybetween sender and receiver.
Publisher/Subscriber (Pub/Sub) Messaging Domain 7
• In Pub/Sub model, one message is delivered to all the subscribers. It is like broadcasting.
• Topicis used as a messageorientedmiddleware that is responsible to hold and deliver messages.
• In PTP model, there is timing dependency between publisher and subscriber.
JMS Programming Model 8
JMS Queue Example
1st Create connection factory 9
2nd Create destination resource 10
3rd Create Sender application 11
InitialContext ctx = new InitialContext();
QueueConnectionFactory f = (QueueConnectionFactory) ctx.lookup("myQueueConnectionFactory");
QueueConnection con = f.createQueueConnection();
con.start();
QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup("myQueue");
QueueSender sender = session.createSender(queue);
TextMessage msg = session.createTextMessage();
3rd Create Sender application… 12
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while(true) {
log("Enter Msg, end to terminate:");
String line = reader.readLine();
if (line.equals("end"))
break;
msg.setText(line);
sender.send(msg);
log("Message successfully sent.");
}
4th Create Receiver application 13
public class MsgListener implements MessageListener {
@Override
public void onMessage(Message m) {
try {
TextMessage msg = (TextMessage) m;
log("following message is received:" + msg.getText());
} catch (JMSException e) {
log(e);
}
}
}
4th Create Receiver application… 14
InitialContext ctx = new InitialContext();
QueueConnectionFactory f = (QueueConnectionFactory) ctx.lookup("myQueueConnectionFactory");
QueueConnection con = f.createQueueConnection();
con.start();
QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup("myQueue");
QueueReceiver receiver=ses.createReceiver(queue);
MsgListener listener = new MsgListener();
receiver.setMessageListener(listener);
Log("Receiver is ready, waiting for messages...“);
while(true){
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
log(ex.getMessage());
}
}
References 15
- YouTube link
https://www.youtube.com/playlist?list=PLtDIUAtyP4lhV7CsYfLuIx26UeG4J-ujZ
- GitHub
https://github.com/Ghadeerof
End Lecture

Weitere ähnliche Inhalte

Was ist angesagt?

Message Queue (MQ) Testing
Message Queue (MQ) TestingMessage Queue (MQ) Testing
Message Queue (MQ) Testing
Ujjwal Gupta
 
Introduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOsIntroduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOs
Matt Stine
 
MOM - Message Oriented Middleware
MOM - Message Oriented MiddlewareMOM - Message Oriented Middleware
MOM - Message Oriented Middleware
Peter R. Egli
 
Module5 enterprise java beans
Module5 enterprise java beansModule5 enterprise java beans
Module5 enterprise java beans
pronab Kurmi
 
Chris Hokamp - ESR 9 DCU
Chris Hokamp - ESR 9 DCU Chris Hokamp - ESR 9 DCU
Chris Hokamp - ESR 9 DCU
RIILP
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
Adeel Rasheed
 
IPC
IPCIPC

Was ist angesagt? (7)

Message Queue (MQ) Testing
Message Queue (MQ) TestingMessage Queue (MQ) Testing
Message Queue (MQ) Testing
 
Introduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOsIntroduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOs
 
MOM - Message Oriented Middleware
MOM - Message Oriented MiddlewareMOM - Message Oriented Middleware
MOM - Message Oriented Middleware
 
Module5 enterprise java beans
Module5 enterprise java beansModule5 enterprise java beans
Module5 enterprise java beans
 
Chris Hokamp - ESR 9 DCU
Chris Hokamp - ESR 9 DCU Chris Hokamp - ESR 9 DCU
Chris Hokamp - ESR 9 DCU
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
IPC
IPCIPC
IPC
 

Ähnlich wie #7 (Java Message Service)

Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS
Arvind Kumar G.S
 
Test DB user
Test DB userTest DB user
Test DB user
techweb08
 
test validation
test validationtest validation
test validation
techweb08
 
test
testtest
test
techweb08
 
test
testtest
test
techweb08
 
test
testtest
test
techweb08
 
test
testtest
test
techweb08
 
test
testtest
test
techweb08
 
test
testtest
test
techweb08
 
test
testtest
test
techweb08
 
test
testtest
test
techweb08
 
JMS
JMSJMS
Apache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache CamelApache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache Camel
Omi Om
 
Java Messaging Services
Java Messaging ServicesJava Messaging Services
Java Messaging Services
kumar gaurav
 
Jms
JmsJms
Java message service
Java message serviceJava message service
Java message service
Veeramani S
 
Jms
JmsJms
Apache ActiveMQ
Apache ActiveMQ Apache ActiveMQ
Apache ActiveMQ
Srushti Patel
 
Jms intro
Jms introJms intro
Jms intro
Manav Prasad
 
JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging Service
Peter R. Egli
 

Ähnlich wie #7 (Java Message Service) (20)

Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS
 
Test DB user
Test DB userTest DB user
Test DB user
 
test validation
test validationtest validation
test validation
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
JMS
JMSJMS
JMS
 
Apache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache CamelApache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache Camel
 
Java Messaging Services
Java Messaging ServicesJava Messaging Services
Java Messaging Services
 
Jms
JmsJms
Jms
 
Java message service
Java message serviceJava message service
Java message service
 
Jms
JmsJms
Jms
 
Apache ActiveMQ
Apache ActiveMQ Apache ActiveMQ
Apache ActiveMQ
 
Jms intro
Jms introJms intro
Jms intro
 
JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging Service
 

Mehr von Ghadeer AlHasan

[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes
Ghadeer AlHasan
 
[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files
Ghadeer AlHasan
 
[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List
Ghadeer AlHasan
 
[Java] #8 String and Inner Class
[Java] #8 String and Inner Class[Java] #8 String and Inner Class
[Java] #8 String and Inner Class
Ghadeer AlHasan
 
[C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers [C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers
Ghadeer AlHasan
 
[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream
Ghadeer AlHasan
 
[C++] #5 - Structures
[C++] #5 - Structures[C++] #5 - Structures
[C++] #5 - Structures
Ghadeer AlHasan
 
#6- Arrays and Collections Framework
#6- Arrays and Collections Framework#6- Arrays and Collections Framework
#6- Arrays and Collections Framework
Ghadeer AlHasan
 
5- Overriding and Abstraction In Java
5- Overriding and Abstraction In Java5- Overriding and Abstraction In Java
5- Overriding and Abstraction In Java
Ghadeer AlHasan
 
4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading
Ghadeer AlHasan
 
3- Operators in Java
3- Operators in Java3- Operators in Java
3- Operators in Java
Ghadeer AlHasan
 
2- Introduction to java II
2-  Introduction to java II2-  Introduction to java II
2- Introduction to java II
Ghadeer AlHasan
 
1- Introduction to java
1- Introduction to java1- Introduction to java
1- Introduction to java
Ghadeer AlHasan
 
0- Overview
0- Overview0- Overview
0- Overview
Ghadeer AlHasan
 
4- Arrays
4-  Arrays4-  Arrays
4- Arrays
Ghadeer AlHasan
 
3- Functions
3-  Functions3-  Functions
3- Functions
Ghadeer AlHasan
 
2- Control Structures
2-  Control Structures2-  Control Structures
2- Control Structures
Ghadeer AlHasan
 
1- Languages Basics
1- Languages Basics1- Languages Basics
1- Languages Basics
Ghadeer AlHasan
 
#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)
Ghadeer AlHasan
 
#5 (Remote Method Invocation)
#5 (Remote Method Invocation)#5 (Remote Method Invocation)
#5 (Remote Method Invocation)
Ghadeer AlHasan
 

Mehr von Ghadeer AlHasan (20)

[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes
 
[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files
 
[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List
 
[Java] #8 String and Inner Class
[Java] #8 String and Inner Class[Java] #8 String and Inner Class
[Java] #8 String and Inner Class
 
[C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers [C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers
 
[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream
 
[C++] #5 - Structures
[C++] #5 - Structures[C++] #5 - Structures
[C++] #5 - Structures
 
#6- Arrays and Collections Framework
#6- Arrays and Collections Framework#6- Arrays and Collections Framework
#6- Arrays and Collections Framework
 
5- Overriding and Abstraction In Java
5- Overriding and Abstraction In Java5- Overriding and Abstraction In Java
5- Overriding and Abstraction In Java
 
4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading
 
3- Operators in Java
3- Operators in Java3- Operators in Java
3- Operators in Java
 
2- Introduction to java II
2-  Introduction to java II2-  Introduction to java II
2- Introduction to java II
 
1- Introduction to java
1- Introduction to java1- Introduction to java
1- Introduction to java
 
0- Overview
0- Overview0- Overview
0- Overview
 
4- Arrays
4-  Arrays4-  Arrays
4- Arrays
 
3- Functions
3-  Functions3-  Functions
3- Functions
 
2- Control Structures
2-  Control Structures2-  Control Structures
2- Control Structures
 
1- Languages Basics
1- Languages Basics1- Languages Basics
1- Languages Basics
 
#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)
 
#5 (Remote Method Invocation)
#5 (Remote Method Invocation)#5 (Remote Method Invocation)
#5 (Remote Method Invocation)
 

Kürzlich hochgeladen

学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 

Kürzlich hochgeladen (20)

学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 

#7 (Java Message Service)

  • 1. Distributed Systems Lecture -7- Created by : Eng. Ghadeer Al Hasan JMS Java Message Service
  • 2. Intro 1 • JMS (Java MessageService) is an API that provides the facilityto create, send and read messages. • It provides looselycoupled, reliable and asynchronous communication. • JMS is also known as a messaging service
  • 3. Understanding Messaging 2 • Messaging is a technique to communicateapplications or software components. • JMS is mainly usedto sendand receive messagefromone applicationto another.
  • 4. Advantage of JMS 3 • Asynchronous: To receive the message, client is not required to send request. Message will arrive automatically to the client. • Reliable: It provides assurance that messageis delivered.
  • 5. Messaging Domains 4 There are two types of messaging domains in JMS : • Point-to-PointMessaging Domain • Publisher/Subscriber Messaging Domain
  • 6. Point-to-Point (PTP) Messaging Domain 5 • In PTP model, one message is delivered to one receiver only. Here, Queue is used as a message oriented middleware (MOM). • The Queue is responsible to hold the message until receiver is ready. • In PTP model, there is no timing dependencybetween sender and receiver.
  • 7. Publisher/Subscriber (Pub/Sub) Messaging Domain 7 • In Pub/Sub model, one message is delivered to all the subscribers. It is like broadcasting. • Topicis used as a messageorientedmiddleware that is responsible to hold and deliver messages. • In PTP model, there is timing dependency between publisher and subscriber.
  • 11. 2nd Create destination resource 10
  • 12. 3rd Create Sender application 11 InitialContext ctx = new InitialContext(); QueueConnectionFactory f = (QueueConnectionFactory) ctx.lookup("myQueueConnectionFactory"); QueueConnection con = f.createQueueConnection(); con.start(); QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = (Queue) ctx.lookup("myQueue"); QueueSender sender = session.createSender(queue); TextMessage msg = session.createTextMessage();
  • 13. 3rd Create Sender application… 12 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while(true) { log("Enter Msg, end to terminate:"); String line = reader.readLine(); if (line.equals("end")) break; msg.setText(line); sender.send(msg); log("Message successfully sent."); }
  • 14. 4th Create Receiver application 13 public class MsgListener implements MessageListener { @Override public void onMessage(Message m) { try { TextMessage msg = (TextMessage) m; log("following message is received:" + msg.getText()); } catch (JMSException e) { log(e); } } }
  • 15. 4th Create Receiver application… 14 InitialContext ctx = new InitialContext(); QueueConnectionFactory f = (QueueConnectionFactory) ctx.lookup("myQueueConnectionFactory"); QueueConnection con = f.createQueueConnection(); con.start(); QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = (Queue) ctx.lookup("myQueue"); QueueReceiver receiver=ses.createReceiver(queue); MsgListener listener = new MsgListener(); receiver.setMessageListener(listener); Log("Receiver is ready, waiting for messages...“); while(true){ try { Thread.sleep(1000); } catch (InterruptedException ex) { log(ex.getMessage()); } }
  • 16. References 15 - YouTube link https://www.youtube.com/playlist?list=PLtDIUAtyP4lhV7CsYfLuIx26UeG4J-ujZ - GitHub https://github.com/Ghadeerof