13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)
DESCRIPTION
13 - JMS. Asynchronous communication in Java - Michal Szynkiewicz - IT Event 2013 (5) This talk will give an introduction to Java Message Service. It will describe communication schemes supported by the JMS, give examples of JMS use cases, show how to use JMS with Spring Framework. It will mention key features incoming in JMS 2.0 and give a brief overview of some alternatives to JMS protocol. Michał Szynkiewicz http://itevent.if.ua/lecture/jms-asynchronous-communication-javaTRANSCRIPT
![Page 1: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/1.jpg)
JMS
Asynchronous communication in Java
Michał Szynkiewicz
Examples: https://github.com/michalszynkiewicz/jms-examples
Email: [email protected]
![Page 2: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/2.jpg)
What's the point?Why do we need asynchronicity?
![Page 3: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/3.jpg)
![Page 4: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/4.jpg)
@POST public Response addCustomer(CustomerDto customer) {
validateCustomer(customer); storeCustomer(customer); return status(CREATED).build();
}
![Page 5: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/5.jpg)
@POST public Response addCustomer(CustomerDto customer) { validateCustomer(customer); storeCustomer(customer); sendConfirmationLink(customer.getEmail()); return status(CREATED).build(); }
![Page 6: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/6.jpg)
![Page 7: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/7.jpg)
![Page 8: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/8.jpg)
![Page 9: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/9.jpg)
![Page 10: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/10.jpg)
![Page 11: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/11.jpg)
Solution: send email asynchronously
![Page 12: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/12.jpg)
+ A standard+ Multiple implementations+ Loose coupling-/+ intermediary server- one way communication- Java API
What's JMS
![Page 13: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/13.jpg)
● Queue
● Topic
Communication schemes
![Page 14: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/14.jpg)
Queue
![Page 15: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/15.jpg)
Usage in our case
![Page 16: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/16.jpg)
Usage in our case
![Page 17: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/17.jpg)
Usage in our case
![Page 18: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/18.jpg)
● Queue
● Topic
Communication schemes
![Page 19: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/19.jpg)
Topic
![Page 20: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/20.jpg)
When to use topic?
![Page 21: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/21.jpg)
Topic use case: Error logging
![Page 22: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/22.jpg)
Topic use case: Error logging
![Page 23: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/23.jpg)
Topic use case: Error logging
![Page 24: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/24.jpg)
Topic use case: Error logging
![Page 25: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/25.jpg)
●Headers: ● e.g. JMSCorrelationID, JMSPriority
●Properties● application-specific headers
●Body● e.g. a String, Map, Object
Message
![Page 26: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/26.jpg)
● Choosing a subset of all messages● SQL-like syntax● Can only use properties and headers
E.g. “JMSPriority = 6 and myProperty='someValue'”
Message selectors
![Page 27: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/27.jpg)
Message selectors
![Page 28: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/28.jpg)
Reliability
![Page 29: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/29.jpg)
Message acknowledgement
● Message are kept on server until message acknowledgment comes ●Acknowledgement modes:
● AUTO — automatic● CLIENT — manual (message.acknowledge())● DUPS_OK — batch, may result in duplicates
![Page 30: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/30.jpg)
● Messages that failed to be processed, can be redelivered● Can be immediate or delayed● After maximum number of redeliveries message ends up in DLQ
Message redelivery
![Page 31: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/31.jpg)
Message persistence
● When JMS server goes down — messages are still kept ● May be disabled
![Page 32: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/32.jpg)
Common issue: Request-response
![Page 33: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/33.jpg)
On specJMS test it was able to handle 8M per second.
It uses disk storage for persistence.
Source: http://planet.jboss.org/post/8_2_million_messages_second_with_specjms
How fast can it be?On example of HornetQ
![Page 34: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/34.jpg)
Available at github: https://github.com/michalszynkiewicz/jms-examples
Spring code examples
![Page 35: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/35.jpg)
Not much :)
● Simplified API● Asynchronous sending (your code doesn't have to wait for JMS provider)● Delivery delay
What's new in JMS 2.0
![Page 36: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/36.jpg)
●AMQP+ cross-platform, full-feature, widely used- protocol still evolving, not backward compatible. Only few providers implement current version.
●STOMP+ via HTTP, widely implemented, lightweight- protocol doesn't describe destination types, etc
●MQTT+ extremely lightweight, used on mobile devices- no queue (topic only), no message properties (only
headers)
(Some) other messaging standards
![Page 37: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)](https://reader031.vdocuments.mx/reader031/viewer/2022020217/5480bd00b4af9fc3158b5ea6/html5/thumbnails/37.jpg)
Questions?