SlideShare a Scribd company logo
1 of 17
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

More Related Content

What's hot

Message Queue (MQ) Testing
Message Queue (MQ) TestingMessage Queue (MQ) Testing
Message Queue (MQ) TestingUjjwal 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 POJOsMatt Stine
 
MOM - Message Oriented Middleware
MOM - Message Oriented MiddlewareMOM - Message Oriented Middleware
MOM - Message Oriented MiddlewarePeter R. Egli
 
Module5 enterprise java beans
Module5 enterprise java beansModule5 enterprise java beans
Module5 enterprise java beanspronab 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 CommunicationAdeel Rasheed
 

What's hot (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
 

Similar to #7 (Java Message Service)

Similar to #7 (Java Message Service) (20)

Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS
 
test validation
test validationtest validation
test validation
 
Test DB user
Test DB userTest DB user
Test DB user
 
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
 

More from Ghadeer AlHasan

[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 ClassesGhadeer AlHasan
 
[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked ListGhadeer AlHasan
 
[Java] #8 String and Inner Class
[Java] #8 String and Inner Class[Java] #8 String and Inner Class
[Java] #8 String and Inner ClassGhadeer 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 StreamGhadeer AlHasan
 
#6- Arrays and Collections Framework
#6- Arrays and Collections Framework#6- Arrays and Collections Framework
#6- Arrays and Collections FrameworkGhadeer AlHasan
 
5- Overriding and Abstraction In Java
5- Overriding and Abstraction In Java5- Overriding and Abstraction In Java
5- Overriding and Abstraction In JavaGhadeer AlHasan
 
4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and OverloadingGhadeer AlHasan
 
2- Introduction to java II
2-  Introduction to java II2-  Introduction to java II
2- Introduction to java IIGhadeer 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
 

More from 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)
 

Recently uploaded

Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 

Recently uploaded (20)

Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 

#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