13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)
Post on 28-Nov-2014
763 Views
Preview:
DESCRIPTION
TRANSCRIPT
JMS
Asynchronous communication in Java
Michał Szynkiewicz
Examples: https://github.com/michalszynkiewicz/jms-examples
Email: michal.l.szynkiewicz@gmail.com
What's the point?Why do we need asynchronicity?
@POST public Response addCustomer(CustomerDto customer) {
validateCustomer(customer); storeCustomer(customer); return status(CREATED).build();
}
@POST public Response addCustomer(CustomerDto customer) { validateCustomer(customer); storeCustomer(customer); sendConfirmationLink(customer.getEmail()); return status(CREATED).build(); }
Solution: send email asynchronously
+ A standard+ Multiple implementations+ Loose coupling-/+ intermediary server- one way communication- Java API
What's JMS
● Queue
● Topic
Communication schemes
Queue
Usage in our case
Usage in our case
Usage in our case
● Queue
● Topic
Communication schemes
Topic
When to use topic?
Topic use case: Error logging
Topic use case: Error logging
Topic use case: Error logging
Topic use case: Error logging
●Headers: ● e.g. JMSCorrelationID, JMSPriority
●Properties● application-specific headers
●Body● e.g. a String, Map, Object
Message
● Choosing a subset of all messages● SQL-like syntax● Can only use properties and headers
E.g. “JMSPriority = 6 and myProperty='someValue'”
Message selectors
Message selectors
Reliability
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
● 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
Message persistence
● When JMS server goes down — messages are still kept ● May be disabled
Common issue: Request-response
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
Available at github: https://github.com/michalszynkiewicz/jms-examples
Spring code examples
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
●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
Questions?
Дякую
email:michal.l.szynkiewicz@gmail.com
top related