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

Post on 28-Nov-2014

763 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

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

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