itevent: jms. asynchronous communication in java
DESCRIPTION
TRANSCRIPT
![Page 1: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/1.jpg)
JMS
Asynchronous communication in Java
Michał Szynkiewicz
Examples: https://github.com/michalszynkiewicz/jms-examples
Email: [email protected]
![Page 2: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/2.jpg)
What's the point?Why do we need asynchronicity?
![Page 3: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/3.jpg)
![Page 4: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/4.jpg)
@POST public Response addCustomer(CustomerDto customer) {
validateCustomer(customer); storeCustomer(customer); return status(CREATED).build();
}
![Page 5: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/5.jpg)
@POST public Response addCustomer(CustomerDto customer) { validateCustomer(customer); storeCustomer(customer); sendConfirmationLink(customer.getEmail()); return status(CREATED).build(); }
![Page 6: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/6.jpg)
![Page 7: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/7.jpg)
![Page 8: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/8.jpg)
![Page 9: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/9.jpg)
![Page 10: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/10.jpg)
![Page 11: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/11.jpg)
Solution: send email asynchronously
![Page 12: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/12.jpg)
+ A standard+ Multiple implementations+ Loose coupling-/+ intermediary server- one way communication- Java API
What's JMS
![Page 13: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/13.jpg)
● Queue
● Topic
Communication schemes
![Page 14: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/14.jpg)
Queue
![Page 15: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/15.jpg)
Usage in our case
![Page 16: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/16.jpg)
Usage in our case
![Page 17: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/17.jpg)
Usage in our case
![Page 18: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/18.jpg)
● Queue
● Topic
Communication schemes
![Page 19: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/19.jpg)
Topic
![Page 20: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/20.jpg)
When to use topic?
![Page 21: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/21.jpg)
Topic use case: Error logging
![Page 22: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/22.jpg)
Topic use case: Error logging
![Page 23: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/23.jpg)
Topic use case: Error logging
![Page 24: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/24.jpg)
Topic use case: Error logging
![Page 25: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/25.jpg)
●Headers: ● e.g. JMSCorrelationID, JMSPriority
●Properties● application-specific headers
●Body● e.g. a String, Map, Object
Message
![Page 26: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/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: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/27.jpg)
Message selectors
![Page 28: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/28.jpg)
Reliability
![Page 29: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/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: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/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: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/31.jpg)
Message persistence
● When JMS server goes down — messages are still kept ● May be disabled
![Page 32: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/32.jpg)
Common issue: Request-response
![Page 33: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/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: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/34.jpg)
Available at github: https://github.com/michalszynkiewicz/jms-examples
Spring code examples
![Page 35: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/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: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/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: ITEvent: JMS. Asynchronous communication in Java](https://reader033.vdocuments.us/reader033/viewer/2022051609/5462e286b1af9f92238b51c3/html5/thumbnails/37.jpg)
Questions?