real life use of spring integration with rabbitmq

34
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. Real life use of Spring Integration with RabbitMQ By Durai Arasan, Director of Architecture, ETRADE Financial Monday, September 9, 13

Upload: spring-io

Post on 02-Dec-2014

1.599 views

Category:

Technology


1 download

DESCRIPTION

Speaker: Durai Arasan ETRADE has revamped their SOA platform with RabbitMQ as a core messaging system and Spring Integration as a light weight ESB layer with services written in Java, C and Python based languages. This new container show cases how legacy system can be migrated at the same time introducing more modern frameworks and languages without comprising on performance and scalability factor of new platform. Presentation will cover some history behind the requirements and how the platform was built. It will be followed by live demo with an example of running web services with RabbitMQ and Spring Integration. This platform highlights why RabbitMQ works best for such a need compare to other options.

TRANSCRIPT

Page 1: Real life use of Spring Integration with RabbitMQ

© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Real life use of Spring Integration with RabbitMQ

By Durai Arasan,

Director of Architecture, ETRADE Financial

Monday, September 9, 13

Page 2: Real life use of Spring Integration with RabbitMQ

About Me

2

Enterprise Java Technology Leader

Monday, September 9, 13

Page 3: Real life use of Spring Integration with RabbitMQ

Agenda

§Background§Things that matter§Our ways to solve§Demo§Q&A

Monday, September 9, 13

Page 4: Real life use of Spring Integration with RabbitMQ

Once upon a time ...

4Monday, September 9, 13

Page 5: Real life use of Spring Integration with RabbitMQ

In the beginning ...

• Early adopters of services• Large set of services

–Anything and everything is a service–Many granular services

• Payload formats–Mixed set of formats–Proprietary

5Monday, September 9, 13

Page 6: Real life use of Spring Integration with RabbitMQ

Things that matter

6

Top requirements for our need

Monday, September 9, 13

Page 7: Real life use of Spring Integration with RabbitMQ

Things that matter

§Performance–Slow performance makes users leave–Instant response is expected

LOADING ...

Monday, September 9, 13

Page 8: Real life use of Spring Integration with RabbitMQ

Things that matter

§Burst Load–Flood gates open–Zero to Sixty in no time

Source: mashable.com

Monday, September 9, 13

Page 9: Real life use of Spring Integration with RabbitMQ

Things that matter

§Service Chains–Granular services end up in service chains–Parallel processing of services–Need to meet SLA–Keeping it in same context

Monday, September 9, 13

Page 10: Real life use of Spring Integration with RabbitMQ

Things that matter

§Simple Services–Keep services strictly to do business logic–POJOs driven–Container to do the heavy lifting

• Routing, Filtering, Transforming, Splitting and aggregating handlers and many more

Client Service

Request

Response

Monday, September 9, 13

Page 11: Real life use of Spring Integration with RabbitMQ

Things that matter

§Separation of concerns–Request Isolation

• Bottleneck with all requests in one queue• Priority queues

–Process Isolation• Impacting other services

Monday, September 9, 13

Page 12: Real life use of Spring Integration with RabbitMQ

Things that matter

§Services in new Languages–New languages are adopted widely–Gone are the days of few languages–Choose a language specific to a task

•C, Java, Python, Ruby, Node.js and Perl

Monday, September 9, 13

Page 13: Real life use of Spring Integration with RabbitMQ

Summary: Things that matter

ServicesPlatform

Web, Mobile

Integration,Batch

Meets the demand for new

& old

Lean& Fast

13Monday, September 9, 13

Page 14: Real life use of Spring Integration with RabbitMQ

How did we solve?

14Monday, September 9, 13

Page 15: Real life use of Spring Integration with RabbitMQ

Enterprise Integration Pattern• Messaging is core to solve integration• Blueprint for solving

–Payload Transformation–Protocol Converters –Filters–Aggregation (scatter gather)–Claim check pattern–and others ...

15Monday, September 9, 13

Page 16: Real life use of Spring Integration with RabbitMQ

Goal: Lean Services Platform• Build with Messaging• Assemble components that work best• Meet all things matter• Build to support

–Legacy Services–New Services

16Monday, September 9, 13

Page 17: Real life use of Spring Integration with RabbitMQ

RabbitMQ• Popular AMQP implementation• High Performance• Robust Messaging• Large number of connections • Runs on many operating systems• Clients for many languages• Open Source Support• AMQP Extensions (DLX, AE etc)

17Monday, September 9, 13

Page 18: Real life use of Spring Integration with RabbitMQ

Spring Integration• Based on EIP: Lightweight ESB & Service Host• Out of the box support for RabbitMQ• POJOs driven services• Gateways

–Configuration driven–Extendable for other impls

• Handlers for all use cases• Built-in JMX support

18Monday, September 9, 13

Page 19: Real life use of Spring Integration with RabbitMQ

Architecture

19Monday, September 9, 13

Page 20: Real life use of Spring Integration with RabbitMQ

Integrating Web Services

20Monday, September 9, 13

Page 21: Real life use of Spring Integration with RabbitMQ

Spring Integration + Web Services• Used as an IDL rather than full-fledged container• Web Services Endpoints

–jax-ws–jax-rs

• No need to re-invent• Support for multiple transport• Messages are routed from broker to SI

21Monday, September 9, 13

Page 22: Real life use of Spring Integration with RabbitMQ

Example JAX-WS Service Interface

@WebService(name="Payment")public interface PaymentService

{   @WebResult(partName="AccountRequest") @WebMethod(operationName="getAccount")

public AccountRequest getAccount(@WebParam(partName="AccountId")int id) throws AccountRequestException;

}

22Monday, September 9, 13

Page 23: Real life use of Spring Integration with RabbitMQ

Example JAX-RS Service Interface@WebService(name="REST/Payment")public interface PaymentService { @GET @Path("/account/{id}") @WebMethod(operationName="account") public AccountRequest getAccount (@PathParam("id") int id);

@POST @Path("/pay/{accountId}") @Consumes({"application/json", "text/xml"}) @WebMethod(operationName="payWithId") public PaymentResultResponse payWithAccountId (@PathParam("accountId") int accountId,

ItemRequest paramItemRequest);}

23Monday, September 9, 13

Page 24: Real life use of Spring Integration with RabbitMQ

Why DSL?• Custom name space support in SI• Simple things simple

–Avoid repetitive patterns –Enables standard patterns

• Complex things possible–Add additional on demand

24Monday, September 9, 13

Page 25: Real life use of Spring Integration with RabbitMQ

Example w/o DSL<!-- INBOUND GATEWAY -->

<int-amqp:inbound-gateway request-channel="echoInputChannel" queue-names="svc_echoQueue" concurrent-consumers="10" connection-factory="rabbitConnection"/>

<!-- UNMARSHALLER --><!-- the handler that processes the request from the inbound gateway --><int:chain id="unmarshaller" input-channel="echoInputChannel" output-channel="echoServicesChannel" ><int-xml:unmarshalling-transformer unmarshaller="jaxb" /><int:service-activator expression="payload.getValue()"></int:service-activator></int:chain>

<!-- ROUTER --><!-- a router based on payload that dispatches the requests on it's input channel to the appropriate service activator --><int:payload-type-router input-channel="echoServicesChannel"> <!-- based on the unmarshalled object type route to different channels --> <int:mapping type="com.etrade.schemas.etsvc.EchoSleepT" channel="echoSleepChannel" /> <int:mapping type="com.etrade.schemas.etsvc.EchoIncrementT" channel="echoIncrementChannel" /> <int:mapping type="com.etrade.schemas.etsvc.EchoPayloadT" channel="echoPayloadChannel" /></int:payload-type-router>

<!-- REQ/REPLY SERVICES --><!-- messaging endpoints that are request and reply producing, and put all their outputs to the output channel that is then received by the marshaller--><int:service-activator id="echoSleepService" input-channel="echoSleepChannel" ref="echoImpl" method="sleep" output-channel="echoOutChannel" /><int:service-activator id="echoIncrementService" input-channel="echoIncrementChannel" ref="echoImpl" method="increment" output-channel="echoOutChannel"/><int:service-activator id="echoPayloadService" input-channel="echoPayloadChannel" ref="echoImpl" method="echoPayload" output-channel="echoOutChannel"/>

<!-- MARSHALLER --><!-- the handler that processes the response from the services, the anonymous replyChannel of the outbound gateway creates the bridge --><int:chain input-channel="echoOutChannel"> <int-xml:marshalling-transformer marshaller="jaxb" id="marshaller" result-type="StringResult"/> <int:object-to-string-transformer /></int:chain>

<!-- BEAN DECLARATION --><bean id="echoImpl" class="com.etrade.service.echo.impl.EchoServiceImpl"/>

<!-- ADMINISTRATION, RABBIT CONFIGS --><rabbit:admin connection-factory="rabbitConnection"/><rabbit:connection-factory id="rabbitConnection" /><rabbit:template id="amqpTemplate" connection-factory="rabbitConnection" /><!-- sets up the exchange --><rabbit:queue name="svc_echoQueue" auto-delete="false" durable="true" exclusive="false"></rabbit:queue><rabbit:direct-exchange name="etsvc_exchange"> <rabbit:bindings> <rabbit:binding queue="svc_echoQueue" key="svc_echoSleep"/> <rabbit:binding queue="svc_echoQueue" key="svc_echoPayLoad"/> <rabbit:binding queue="svc_echoQueue" key="svc_echoIncrement"/> </rabbit:bindings></rabbit:direct-exchange>

25Monday, September 9, 13

Page 26: Real life use of Spring Integration with RabbitMQ

Example w/ DSL<!-- transformers, routers, channels, service-activators are now assimilated!! :) -->

<beans> <!-- gateway declaration --> <etrade:inbound-gateway service-interface="com.etrade.service.echo.Echo" ref="echoService" concurrent-consumers="5"/> <!-- bean declaration --> <bean id="echoService" class="com.etrade.service.echo.impl.EchoServiceImpl" /></beans>

26Monday, September 9, 13

Page 27: Real life use of Spring Integration with RabbitMQ

Use of standard WSDL Tools • Wsdl2java to produce java interfaces • Java2wsdl to produce wsdl• Bindings for wsdl (jaxb, et al)• Transport in wsdl (http, amqp)• Use of standard wsdl extensions

27Monday, September 9, 13

Page 28: Real life use of Spring Integration with RabbitMQ

Payloads over AMQP• Standard service development

–Using well known annotations (jax-ws & jax-rs)–Deployed under AMQP container

• JAX-RS–All media types (text/xml, application/octet-stream etc)

• JAX-WS–SOAP–XML/POX

28Monday, September 9, 13

Page 29: Real life use of Spring Integration with RabbitMQ

SI + Web Services Flow

29Monday, September 9, 13

Page 30: Real life use of Spring Integration with RabbitMQ

Demo

30

Generic Sample Service

Monday, September 9, 13

Page 31: Real life use of Spring Integration with RabbitMQ

Next Steps

31

Spring IO:

Monday, September 9, 13

Page 32: Real life use of Spring Integration with RabbitMQ

Summary• This model works for us• Performance meets our needs• Async Services help manage load• Decoupling of clients & endpoints• Platform that can run legacy and new services• Heterogeneous deployments in to single container

32Monday, September 9, 13

Page 33: Real life use of Spring Integration with RabbitMQ

Learn More. Stay Connected.

We are Hiring!career.etrade.com

Twitter: twitter.com/duraiarasanLinkedIn: linkedin.com/in/duraiarasan Facebook: facebook.com/duraiarasan

Monday, September 9, 13

Page 34: Real life use of Spring Integration with RabbitMQ

Q&A

Monday, September 9, 13