SlideShare ist ein Scribd-Unternehmen logo
1 von 37
JMS


Prepared by: Andrey Stelmashenko
What is JMS?

●   A specification that describes a common way for Java
    programs to create, send, receive and read distributed
    enterprise messages;
●   loosely coupled communication;
●   Asynchronous messaging;
●   Reliable delivery;
         – A message is guaranteed to be delivered once
             and only once.
●   Outside the specification
         – Security services
         – Management services
Goals


●   Provide a single, unified message API
●   Minimize knowledge needed for programmers
    needed to write clients
●   Utilize concepts of message exchange
    applications
●   Simplify portability of JMS clients
JMS Application
JMS Concepts

●   Connection factory
●   Connection
●   Session
●   Message producer
●   Destination
●   Message consumer
●   Message
Responsibilities


    Client side:
                            JMS Provider:
●   Message producer
                        ●   Connection factory
●   Message consumer
                        ●   Connection
●   Message
                        ●   Destination
●   Session
Example
Message producer
@Resource(name = "jmsPool1")
private ConnectionFactory connectionFactory;
@Resource(name = "jndiJmsDest1")
private Destination dest;

@Override
  protected void doGet(...) {
    Connection connection = null;
    MessageProducer producer = null;
    try {
      connection = connectionFactory.createConnection();
      Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
      producer = session.createProducer(dest);
      TextMessage message = session.createTextMessage();
      message.setText("Hello, JMS!!!");
      producer.send(message);
    } catch (JMSException e) {...}

   try {
      connection.close();
   } catch (JMSException e) {...}
  ...
@Resource(name = "jmsPool1")
private ConnectionFactory connectionFactory;
@Resource(name = "jmsPool1")
private ConnectionFactory connectionFactory;

@Resource(name = "jndiJmsDest1")
private Destination dest;
@Resource(name = "jmsPool1")
private ConnectionFactory connectionFactory;

@Resource(name = "jndiJmsDest1")
private Destination dest;

@Override protected void doGet(...) {
    Connection connection = null;
    MessageProducer producer = null;
    try {
1      connection = connectionFactory.createConnection();
2      Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
3      producer = session.createProducer(dest);
4      TextMessage message = session.createTextMessage();
5      message.setText("Hello, JMS!!!");
6      producer.send(message);
    } catch (JMSException e) {...}

    try {
       connection.close();
    } catch (JMSException e) {...}
   ...
Message consumer
@Resource(name = "jmsPool2")
private ConnectionFactory connectionFactory;
@Resource(name = "jndiJmsDest1")
private Destination dest;
@Resource(name = "jmsPool2")
private ConnectionFactory connectionFactory;
@Resource(name = "jndiJmsDest1")
private Destination dest;

@Override protected void doGet(...) {
    Connection connection = null;
    Session session = null;
    MessageConsumer consumer = null;
    TextMessage message = null;
    try {
1       connection = connectionFactory.createConnection();
2       session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
3       consumer = session.createConsumer(dest);
4       connection.start();
5       Message m = consumer.receive();
6       message = (TextMessage) m;
7       LOG.info("Msg: " + message.getText());
    } catch (JMSException e) {…}
    finally {
       connection.close();
    }
   ...
Where are Connection Factory and
          Destination?
JMS Application
A JMS application is composed of the following parts:


• JMS Clients - These are the Java language programs that send
and receive messages.
• Non-JMS Clients.
• Messages - Each application defines a set of messages that are
used to communicate information between its clients.
• JMS Provider - This is a messaging system that implements
JMS in addition to the other administrative and control
functionality required of a full-featured messaging product.
• Administered Objects - Administered objects are preconfigured
JMS objects created by an administrator for the use of clients.
Administered objects

Two types of JMS administered objects:


• ConnectionFactory - This is the object a client
uses to create a connection with a provider.
• Destination - This is the object a client uses to
specify the destination of messages it is sending
and the source of messages it receives.
JMS Administration
Domains

There are two models of interaction:

●   In the point-to-point (or PTP) messaging
    model, each message is delivered from a
    message producer to a single message
    consumer.
●   In the publish/subscribe (or pub/sub) model, a
    single message can be delivered from a
    producer to any number of consumers.
PTP
Pub / Sub
PTP and Pub/Sub Interfaces
Session
●   A session is a single-threaded context for
    producing and consuming messages.

●   Sessions are the JMS entity that supports
    transactions.
        –   A JMS client may use JTA to delimit distributed
              transactions; however, this is a function of the transaction
              environment the client is running in. It is not a feature of
              JMS.
Messages

    Composed of:
●   Header
    used by both clients and providers to identify and route messages

●   Properties
          –   Application-specific properties
          –   Standard properties
          –   Provider-specific properties
●   Body
Message Header Properties
Message Selection



●   By headers and properties
    not delivered differ a bit depending on the MessageConsumer

●   Based on SQL92 conditional expression
    syntax
    "JMSType = ’car’ AND color = ’blue’ AND weight > 2500"
Message Types


 ●   StreamMessage
 ●   MapMessage
 ●   TextMessage
 ●   ObjectMessage
 ●   BytesMessage
Message Acknowledgmnent


    Acknowledgment handled automatically if session is transacted.

    Other way three types:
●   DUPS_OK_ACKNOWLEDGE
●   AUTO_ACKNOWLEDGE
●   CLIENT_ACKNOWLEDGE
Delivery Mode



●   NON_PERSISTENT
    delivers at-most-once. Msg may be losed.
●   PERSISTENT
    once-and-only-once. Msg must not delivered twice.
Message Scheduling
Message Scheduling




●   No message scheduling in specification!
Apache ActiveMQ
ActiveMQ from version 5.4 has an optional persistent scheduler built into the ActiveMQ
message broker. It is enabled by setting the broker schedulerSupport attribute to true in
the Xml Configuration.
An ActiveMQ client can take advantage of a delayed delivery by using the following
message properties.
 Property name                       type       description


 AMQ_SCHEDULED_DELAY                 long       The time in milliseconds that a message
                                                will wait before being scheduled to be
                                                delivered by the broker

 AMQ_SCHEDULED_PERIOD                long       The time in milliseconds to wait after the
                                                start time to wait before scheduling the
                                                message again

 AMQ_SCHEDULED_REPEAT                int        The number of times to repeat
                                                scheduling a message for delivery

 AMQ_SCHEDULED_CRON                  String     Use a Cron entry to set the schedule
ActiveMQ Example


MessageProducer producer = session.createProducer(destination);

TextMessage message = session.createTextMessage("test msg");

long time = 60 * 1000;

message.setLongProperty(
      ScheduledMessage.AMQ_SCHEDULED_DELAY, time);

producer.send(message);
Questions

Weitere ähnliche Inhalte

Was ist angesagt?

JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging ServicePeter R. Egli
 
Java Message Service
Java Message ServiceJava Message Service
Java Message ServiceAMIT YADAV
 
JMS Providers Overview
JMS Providers OverviewJMS Providers Overview
JMS Providers OverviewVadym Lotar
 
Mom those things v1
Mom those things v1 Mom those things v1
Mom those things v1 von gosling
 
Enterprise messaging with jms
Enterprise messaging with jmsEnterprise messaging with jms
Enterprise messaging with jmsSridhar Reddy
 
Jms deep dive [con4864]
Jms deep dive [con4864]Jms deep dive [con4864]
Jms deep dive [con4864]Ryan Cuprak
 
Swetha-IBMCertifiedWMQ_WMB
Swetha-IBMCertifiedWMQ_WMBSwetha-IBMCertifiedWMQ_WMB
Swetha-IBMCertifiedWMQ_WMBshwetha mukka
 
Message Driven Beans (6)
Message Driven Beans (6)Message Driven Beans (6)
Message Driven Beans (6)Abdalla Mahmoud
 
ActiveMQ Configuration
ActiveMQ ConfigurationActiveMQ Configuration
ActiveMQ ConfigurationAshish Mishra
 
2012 07-jvm-summit-batches
2012 07-jvm-summit-batches2012 07-jvm-summit-batches
2012 07-jvm-summit-batchesWill Cook
 
Nagios Conference 2012 - John Murphy - Rational Configuration Design
Nagios Conference 2012 - John Murphy - Rational Configuration DesignNagios Conference 2012 - John Murphy - Rational Configuration Design
Nagios Conference 2012 - John Murphy - Rational Configuration DesignNagios
 

Was ist angesagt? (17)

JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging Service
 
Weblogic - Introduction to configure JMS
Weblogic  - Introduction to configure JMSWeblogic  - Introduction to configure JMS
Weblogic - Introduction to configure JMS
 
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
 
Mom those things v1
Mom those things v1 Mom those things v1
Mom those things v1
 
Enterprise messaging with jms
Enterprise messaging with jmsEnterprise messaging with jms
Enterprise messaging with jms
 
Jms deep dive [con4864]
Jms deep dive [con4864]Jms deep dive [con4864]
Jms deep dive [con4864]
 
Swetha-IBMCertifiedWMQ_WMB
Swetha-IBMCertifiedWMQ_WMBSwetha-IBMCertifiedWMQ_WMB
Swetha-IBMCertifiedWMQ_WMB
 
Message Driven Beans (6)
Message Driven Beans (6)Message Driven Beans (6)
Message Driven Beans (6)
 
jms-integration
jms-integrationjms-integration
jms-integration
 
ActiveMQ Configuration
ActiveMQ ConfigurationActiveMQ Configuration
ActiveMQ Configuration
 
2012 07-jvm-summit-batches
2012 07-jvm-summit-batches2012 07-jvm-summit-batches
2012 07-jvm-summit-batches
 
Differences between JMS and AMQP
Differences between JMS and AMQPDifferences between JMS and AMQP
Differences between JMS and AMQP
 
Nagios Conference 2012 - John Murphy - Rational Configuration Design
Nagios Conference 2012 - John Murphy - Rational Configuration DesignNagios Conference 2012 - John Murphy - Rational Configuration Design
Nagios Conference 2012 - John Murphy - Rational Configuration Design
 
Messaging in Java
Messaging in JavaMessaging in Java
Messaging in Java
 

Andere mochten auch

Membase Meetup 2010
Membase Meetup 2010Membase Meetup 2010
Membase Meetup 2010Membase
 
Market Opportunity Profile
Market Opportunity ProfileMarket Opportunity Profile
Market Opportunity ProfileWendy Colby
 
Cold war start
Cold war startCold war start
Cold war startsimkar7
 
Better Living Through Messaging - Leveraging the HornetQ Message Broker at Sh...
Better Living Through Messaging - Leveraging the HornetQ Message Broker at Sh...Better Living Through Messaging - Leveraging the HornetQ Message Broker at Sh...
Better Living Through Messaging - Leveraging the HornetQ Message Broker at Sh...Joshua Long
 
Membase Meetup - San Diego
Membase Meetup - San DiegoMembase Meetup - San Diego
Membase Meetup - San DiegoMembase
 

Andere mochten auch (7)

Membase Meetup 2010
Membase Meetup 2010Membase Meetup 2010
Membase Meetup 2010
 
Market Opportunity Profile
Market Opportunity ProfileMarket Opportunity Profile
Market Opportunity Profile
 
Cmm Presentation
Cmm PresentationCmm Presentation
Cmm Presentation
 
F radar
F radarF radar
F radar
 
Cold war start
Cold war startCold war start
Cold war start
 
Better Living Through Messaging - Leveraging the HornetQ Message Broker at Sh...
Better Living Through Messaging - Leveraging the HornetQ Message Broker at Sh...Better Living Through Messaging - Leveraging the HornetQ Message Broker at Sh...
Better Living Through Messaging - Leveraging the HornetQ Message Broker at Sh...
 
Membase Meetup - San Diego
Membase Meetup - San DiegoMembase Meetup - San Diego
Membase Meetup - San Diego
 

Ähnlich wie Jms

Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS Arvind Kumar G.S
 
#7 (Java Message Service)
#7 (Java Message Service)#7 (Java Message Service)
#7 (Java Message Service)Ghadeer AlHasan
 
Ranker jms implementation
Ranker jms implementationRanker jms implementation
Ranker jms implementationEosSoftware
 
Using Apache Pulsar as a Modern, Scalable, High Performing JMS Platform - Pus...
Using Apache Pulsar as a Modern, Scalable, High Performing JMS Platform - Pus...Using Apache Pulsar as a Modern, Scalable, High Performing JMS Platform - Pus...
Using Apache Pulsar as a Modern, Scalable, High Performing JMS Platform - Pus...StreamNative
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message BrokersPROIDEA
 
Test DB user
Test DB userTest DB user
Test DB usertechweb08
 
test validation
test validationtest validation
test validationtechweb08
 
Inter-Sling communication with message queue
Inter-Sling communication with message queueInter-Sling communication with message queue
Inter-Sling communication with message queueTomasz Rękawek
 
What's new in Java Message Service 2?
What's new in Java Message Service 2?What's new in Java Message Service 2?
What's new in Java Message Service 2?Sivakumar Thyagarajan
 

Ähnlich wie Jms (20)

Messaging Frameworks using JMS
Messaging Frameworks using JMS Messaging Frameworks using JMS
Messaging Frameworks using JMS
 
#7 (Java Message Service)
#7 (Java Message Service)#7 (Java Message Service)
#7 (Java Message Service)
 
Jms
JmsJms
Jms
 
Ranker jms implementation
Ranker jms implementationRanker jms implementation
Ranker jms implementation
 
Using Apache Pulsar as a Modern, Scalable, High Performing JMS Platform - Pus...
Using Apache Pulsar as a Modern, Scalable, High Performing JMS Platform - Pus...Using Apache Pulsar as a Modern, Scalable, High Performing JMS Platform - Pus...
Using Apache Pulsar as a Modern, Scalable, High Performing JMS Platform - Pus...
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers
 
Apache ActiveMQ
Apache ActiveMQ Apache ActiveMQ
Apache ActiveMQ
 
Test DB user
Test DB userTest DB user
Test DB user
 
test validation
test validationtest validation
test validation
 
Inter-Sling communication with message queue
Inter-Sling communication with message queueInter-Sling communication with message queue
Inter-Sling communication with message queue
 
Jms intro
Jms introJms intro
Jms intro
 
IBM MQ V8 annd JMS 2.0
IBM MQ V8 annd JMS 2.0IBM MQ V8 annd JMS 2.0
IBM MQ V8 annd JMS 2.0
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
What's new in Java Message Service 2?
What's new in Java Message Service 2?What's new in Java Message Service 2?
What's new in Java Message Service 2?
 

Kürzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Jms

  • 1. JMS Prepared by: Andrey Stelmashenko
  • 2. What is JMS? ● A specification that describes a common way for Java programs to create, send, receive and read distributed enterprise messages; ● loosely coupled communication; ● Asynchronous messaging; ● Reliable delivery; – A message is guaranteed to be delivered once and only once. ● Outside the specification – Security services – Management services
  • 3. Goals ● Provide a single, unified message API ● Minimize knowledge needed for programmers needed to write clients ● Utilize concepts of message exchange applications ● Simplify portability of JMS clients
  • 5. JMS Concepts ● Connection factory ● Connection ● Session ● Message producer ● Destination ● Message consumer ● Message
  • 6. Responsibilities Client side: JMS Provider: ● Message producer ● Connection factory ● Message consumer ● Connection ● Message ● Destination ● Session
  • 9. @Resource(name = "jmsPool1") private ConnectionFactory connectionFactory; @Resource(name = "jndiJmsDest1") private Destination dest; @Override protected void doGet(...) { Connection connection = null; MessageProducer producer = null; try { connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(dest); TextMessage message = session.createTextMessage(); message.setText("Hello, JMS!!!"); producer.send(message); } catch (JMSException e) {...} try { connection.close(); } catch (JMSException e) {...} ...
  • 10. @Resource(name = "jmsPool1") private ConnectionFactory connectionFactory;
  • 11. @Resource(name = "jmsPool1") private ConnectionFactory connectionFactory; @Resource(name = "jndiJmsDest1") private Destination dest;
  • 12. @Resource(name = "jmsPool1") private ConnectionFactory connectionFactory; @Resource(name = "jndiJmsDest1") private Destination dest; @Override protected void doGet(...) { Connection connection = null; MessageProducer producer = null; try { 1 connection = connectionFactory.createConnection(); 2 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 3 producer = session.createProducer(dest); 4 TextMessage message = session.createTextMessage(); 5 message.setText("Hello, JMS!!!"); 6 producer.send(message); } catch (JMSException e) {...} try { connection.close(); } catch (JMSException e) {...} ...
  • 14. @Resource(name = "jmsPool2") private ConnectionFactory connectionFactory; @Resource(name = "jndiJmsDest1") private Destination dest;
  • 15. @Resource(name = "jmsPool2") private ConnectionFactory connectionFactory; @Resource(name = "jndiJmsDest1") private Destination dest; @Override protected void doGet(...) { Connection connection = null; Session session = null; MessageConsumer consumer = null; TextMessage message = null; try { 1 connection = connectionFactory.createConnection(); 2 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 3 consumer = session.createConsumer(dest); 4 connection.start(); 5 Message m = consumer.receive(); 6 message = (TextMessage) m; 7 LOG.info("Msg: " + message.getText()); } catch (JMSException e) {…} finally { connection.close(); } ...
  • 16. Where are Connection Factory and Destination?
  • 17. JMS Application A JMS application is composed of the following parts: • JMS Clients - These are the Java language programs that send and receive messages. • Non-JMS Clients. • Messages - Each application defines a set of messages that are used to communicate information between its clients. • JMS Provider - This is a messaging system that implements JMS in addition to the other administrative and control functionality required of a full-featured messaging product. • Administered Objects - Administered objects are preconfigured JMS objects created by an administrator for the use of clients.
  • 18. Administered objects Two types of JMS administered objects: • ConnectionFactory - This is the object a client uses to create a connection with a provider. • Destination - This is the object a client uses to specify the destination of messages it is sending and the source of messages it receives.
  • 20.
  • 21.
  • 22. Domains There are two models of interaction: ● In the point-to-point (or PTP) messaging model, each message is delivered from a message producer to a single message consumer. ● In the publish/subscribe (or pub/sub) model, a single message can be delivered from a producer to any number of consumers.
  • 23. PTP
  • 25. PTP and Pub/Sub Interfaces
  • 26. Session ● A session is a single-threaded context for producing and consuming messages. ● Sessions are the JMS entity that supports transactions. – A JMS client may use JTA to delimit distributed transactions; however, this is a function of the transaction environment the client is running in. It is not a feature of JMS.
  • 27. Messages Composed of: ● Header used by both clients and providers to identify and route messages ● Properties – Application-specific properties – Standard properties – Provider-specific properties ● Body
  • 29. Message Selection ● By headers and properties not delivered differ a bit depending on the MessageConsumer ● Based on SQL92 conditional expression syntax "JMSType = ’car’ AND color = ’blue’ AND weight > 2500"
  • 30. Message Types ● StreamMessage ● MapMessage ● TextMessage ● ObjectMessage ● BytesMessage
  • 31. Message Acknowledgmnent Acknowledgment handled automatically if session is transacted. Other way three types: ● DUPS_OK_ACKNOWLEDGE ● AUTO_ACKNOWLEDGE ● CLIENT_ACKNOWLEDGE
  • 32. Delivery Mode ● NON_PERSISTENT delivers at-most-once. Msg may be losed. ● PERSISTENT once-and-only-once. Msg must not delivered twice.
  • 34. Message Scheduling ● No message scheduling in specification!
  • 35. Apache ActiveMQ ActiveMQ from version 5.4 has an optional persistent scheduler built into the ActiveMQ message broker. It is enabled by setting the broker schedulerSupport attribute to true in the Xml Configuration. An ActiveMQ client can take advantage of a delayed delivery by using the following message properties. Property name type description AMQ_SCHEDULED_DELAY long The time in milliseconds that a message will wait before being scheduled to be delivered by the broker AMQ_SCHEDULED_PERIOD long The time in milliseconds to wait after the start time to wait before scheduling the message again AMQ_SCHEDULED_REPEAT int The number of times to repeat scheduling a message for delivery AMQ_SCHEDULED_CRON String Use a Cron entry to set the schedule
  • 36. ActiveMQ Example MessageProducer producer = session.createProducer(destination); TextMessage message = session.createTextMessage("test msg"); long time = 60 * 1000; message.setLongProperty( ScheduledMessage.AMQ_SCHEDULED_DELAY, time); producer.send(message);