13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

38
JMS Asynchronous communication in Java Michał Szynkiewicz Examples: https://github.com/michalszynkiewicz/jms-examples Email: [email protected]

Upload: igor-bronovskyy

Post on 28-Nov-2014

763 views

Category:

Education


0 download

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-java

TRANSCRIPT

Page 1: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

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)

What's the point?Why do we need asynchronicity?

Page 3: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)
Page 4: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

@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)

@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)
Page 7: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)
Page 8: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)
Page 9: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)
Page 10: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)
Page 11: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Solution: send email asynchronously

Page 12: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

+ 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)

● Queue

● Topic

Communication schemes

Page 14: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Queue

Page 15: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Usage in our case

Page 16: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Usage in our case

Page 17: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Usage in our case

Page 18: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

● Queue

● Topic

Communication schemes

Page 19: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Topic

Page 20: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

When to use topic?

Page 21: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Topic use case: Error logging

Page 22: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Topic use case: Error logging

Page 23: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Topic use case: Error logging

Page 24: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Topic use case: Error logging

Page 25: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

●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)

● 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)

Message selectors

Page 28: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Reliability

Page 29: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

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)

● 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)

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)

Common issue: Request-response

Page 33: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

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)

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)

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)

●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)

Questions?

Page 38: 13 - jms. asynchronous communication in java - michal szynkiewicz - it event 2013 (5)

Дякую

email:[email protected]