32
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. REST Services with RabbitMQ, Spring Integration and Node.JS Durai Arasan & Monish Unni

REST Services with RabbitMQ, Spring Integration and Node.JS

Embed Size (px)

DESCRIPTION

Speakers: Durai Arasan, ETrade Monish Unni, Etrade Data / Integration Track Extending from last year's conversation in SpringOne2GX on real world use of RabbitMQ and Spring Integration, this talk will be centered around REST service as first class citizen in Spring Integration with RabbitMQ. How do you build REST services and integrate with Spring Integration and RabbitMQ? What kind of role Node.JS can play in your architecture to simplify complex problems? We will address all of these questions and provide insight into design and architecture challenges to bring enterprise services to support modern client applications that expect REST Services.

Citation preview

Page 1: REST Services with RabbitMQ, Spring Integration and Node.JS

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

REST Services with RabbitMQ, Spring Integration and Node.JS

Durai Arasan & Monish Unni

Page 2: REST Services with RabbitMQ, Spring Integration and Node.JS

About Us

2

Durai Arasan, Director, Architecture Monish Unni, Sr. Principal, Architecture

Page 3: REST Services with RabbitMQ, Spring Integration and Node.JS

Contents

• Background • Why Queues? • Why RabbitMQ? • Spring Integration + Services • Why JAX-RS or REST? • Demo

3

• What do web clients need? • Why Node.js? • Handling routes • Node transformations • Node aggregation • Demo

Page 4: REST Services with RabbitMQ, Spring Integration and Node.JS

Background

• Speed • Multiple languages • Platform for legacy Services • Large number of Services • Mixed payload formats • Mixed protocols • Fault isolations • Logging • Usage reporting

4

Page 5: REST Services with RabbitMQ, Spring Integration and Node.JS

5

Architecture

DLX + AEProcess Python ProcessSI + CXF

Java ProcessC Process

Rabbit MQMessage Bus

SIJava Process Python Process

Client

AMQP

X

CP

C Process

Proc

ess

Man

ager

PC PCPCDLX + AEConsumer Process

Adm

in &

M

onito

rs

Security

Page 6: REST Services with RabbitMQ, Spring Integration and Node.JS

Why Queues?

• Single queue makes every request at the mercy of previous requests.

• Traffic shaping or Quality of Service (QoS) • Valid response when server can’t handle requests

• Avoid “503 - Server too busy” • Monitoring pending requests • Administration of consumers based on load • Requests, response & fault isolation

6

Page 7: REST Services with RabbitMQ, Spring Integration and Node.JS

Why RabbitMQ?

• AMQP Compliant • RabbitMQ Extensions for enterprise

• Alternate exchange (AE) • Dead letter exchange (DLX) • Extended properties for Queues & Messages

• Built-in monitoring • Security (amqps) • Large number of connections • Binding for many languages • Built-in Spring support

7

Page 8: REST Services with RabbitMQ, Spring Integration and Node.JS

Spring Integration + Services

• Many great things in Spring Integration

• Custom service activators for • First class support of JAX-WS/RS services • Exception handling

• Custom namespace for • Simplified spring integration configuration • Gateways & Transformers • CXF Bridge

8

Page 9: REST Services with RabbitMQ, Spring Integration and Node.JS

Custom Service Activators

• IntegrationConversionService for CXF message • Inbound gateways lazy bind CXF Service Activators • CXF destination instead of local conduit • Provides JAX-WS and JAX-RS endpoints • Error handlers

9

Page 10: REST Services with RabbitMQ, Spring Integration and Node.JS

What is REST on AMQP?

basic.get and basic.publish

10

Page 11: REST Services with RabbitMQ, Spring Integration and Node.JS

Why JAX-RS on AMQP?

• Is JAX-RS about building HTTP based Restful services? • Is Transport Independence a bug or a feature?

• REST is not about using HTTP • Allows to leverage JAX-RS eco-system for AMQP

11

Page 12: REST Services with RabbitMQ, Spring Integration and Node.JS

JAX-RS Interfaces

12

Page 13: REST Services with RabbitMQ, Spring Integration and Node.JS

JAX-RS Configuration for AMQP

13

Page 14: REST Services with RabbitMQ, Spring Integration and Node.JS

Custom Spring Integration Gateway and namespace

14

Page 15: REST Services with RabbitMQ, Spring Integration and Node.JS

Demo

15

Page 16: REST Services with RabbitMQ, Spring Integration and Node.JS

What do web clients need?

16

http:// webservices

Page 17: REST Services with RabbitMQ, Spring Integration and Node.JS

Our Choice

17

Page 18: REST Services with RabbitMQ, Spring Integration and Node.JS

Why Node.js?

• Shines in I/O • Networking

• Naturally asynchronous • Javascript callback support

• Transformations • Choose your batteries

18

Page 19: REST Services with RabbitMQ, Spring Integration and Node.JS

19

Architecture

DLX + AEProcess Python ProcessSI + CXF

Java ProcessC Process

Rabbit MQMessage Bus

SIJava Process Python Process

Client

AMQP

X

CP

C Process

Proc

ess

Man

ager

PC PCPCDLX + AEConsumer Process

Adm

in &

M

onito

rs

Security

Node.js

AMQP

HTTPWeb

Page 20: REST Services with RabbitMQ, Spring Integration and Node.JS

Handling routes

• RabbitMQ • Routes with exchange name and routing key • Backed by queues with binding key

• Node.js • Uses binding key list from RabbitMQ • url-template library matches incoming requests • Routes matching requests to RabbitMQ with headers

20

Page 21: REST Services with RabbitMQ, Spring Integration and Node.JS

Handling Routes

21

Node.js RabbitMQ

GET/account/{id}

GET /account/120001

AMQP Headers - Routing Key - CXF Request URI - HTTP Method

AccountService

Page 22: REST Services with RabbitMQ, Spring Integration and Node.JS

Route alias & Vanity URLs

• Advertising public APIs • Protecting internal service routes • HTTP attributes based methods need special mapping

22

Page 23: REST Services with RabbitMQ, Spring Integration and Node.JS

Node transformations

• Protocol conversion • Payload conversion • Declarative routes • Aggregation • Avoids boilerplate code

23

Page 24: REST Services with RabbitMQ, Spring Integration and Node.JS

Aggregation w/ async

• Composing control flow • series • parallel

24

Page 25: REST Services with RabbitMQ, Spring Integration and Node.JS

Other usage

• APIs • Expose services as APIs

• Testers • Can be used as test clients to different endpoints

• Mock Services • Virtualize any service without much effort

• Benchmarks • Built-in support for reporting

25

Page 26: REST Services with RabbitMQ, Spring Integration and Node.JS

Demo

26

Calling legacy services API Routes Aggregation

Page 27: REST Services with RabbitMQ, Spring Integration and Node.JS

Node - Things to watch out

• Primitive stack trace • vague errors “EADDRINFO”

• EventLoop • 2 line stack-trace : debug

• Debug with strace, dtrace • V8 Engine

• Generational GC • may need a deep dive

27

Page 28: REST Services with RabbitMQ, Spring Integration and Node.JS

Node - New and Good parts

• V8 native support for generators and yield! • looks very promising (no pun) • can remove crustified callback code

• function (err, callback) • forced to think about error and what to do

28

Page 29: REST Services with RabbitMQ, Spring Integration and Node.JS

Node libraries

• amqp • async • elementtree • soap • loopback • swagger

29

Page 30: REST Services with RabbitMQ, Spring Integration and Node.JS

Summary

• RabbitMQ • Scales to large number of connections • Fast & Secure • Binding for many languages

• Spring Integration • Easy to extend • Plugin service activators • In JVM orchestration

• Node.JS • Async I/O • Javascript support 30

Page 31: REST Services with RabbitMQ, Spring Integration and Node.JS

Learn More. Stay Connected

We are Hiring! career.etrade.com

twitter.com/duraiarasan

linkedin.com/in/duraiarasan, linkedin.com/in/monishunni

31

Page 32: REST Services with RabbitMQ, Spring Integration and Node.JS

Q & A

32