stream-style messaging development with rabbit, active, zeromq & apache kafka by vyacheslav...

46
1 Stream-style messaging development in Java The NoJMS way October 1, 2015

Upload: javadayua

Post on 14-Apr-2017

429 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

1

Stream-style messaging development in JavaThe NoJMS way

October 1, 2015

Page 2: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

2

Problems of traditional way

Integration system working is…

Page 3: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

3

Problems of traditional way

Integration system working is…

Page 4: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

4

Problems of traditional way

Integration system working is…

Page 5: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

5

Problems of traditional way

Integration system working is…

Page 6: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

6

Problems of traditional way

«There's no such thing as problems, Mr. Green, only situations...»

Avi, «Revolver»

Page 7: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

7

Problems of traditional way - Architecture

Internet/Intranet

Application ServerCluster

Database Cluster

Page 8: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

8

Problems of traditional way - Architecture

Internet/Intranet

Application ServerCluster

Database Cluster

First another application Server Cluster

Page 9: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

9

Problems of traditional way - Architecture

Internet/Intranet

Application ServerCluster

Database Cluster

First another application Server Cluster …

Second another application ServerCluster

Page 10: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

10

Problems of traditional way - Architecture

Internet/Intranet

Application ServerCluster

Database Cluster

First another application Server Cluster …

Second another application ServerCluster

Page 11: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

11

Problems of traditional way - Architecture

Internet/Intranet

Application ServerCluster

Database Cluster

First another application Server Cluster …

Second another application ServerCluster

Page 12: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

12

Internet/Intranet

Application ServerCluster

Database Cluster

First another application Server Cluster …

Second another application ServerCluster

Problems of traditional way - Architecture

Page 13: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

13

Internet/Intranet

Application ServerCluster

Database Cluster

First another application Server Cluster …

Second another application ServerCluster

Problems of traditional way - Architecture

Page 14: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

14

Problems of traditional way

«Actually, the cause of computer revolution is not that calculator become faster and get a lot of memory, get

possibility to show as advanced graphics, and so on; but that cause is that computer can connect to another computer. So, computer is not, as usually described, the result of calculator

evolution – it`s result of telephone evolution!»

Andrey Verbitsky,«SoftwarePeople 2009»

Page 15: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

15

Problems of traditional way

Page 16: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

16

Problems of traditional way

WSDL/SOAP web-services (XML)1

Page 17: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

17

Problems of traditional way

WSDL/SOAP web-services (XML)1

RESTful web-services (JSON)2

Page 18: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

18

Problems of traditional way

WSDL/SOAP web-services (XML)1

RESTful web-services (JSON)2

JMS (Java standard Serialization)3

Page 19: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

19

1. Messages size

Problems of traditional way - WSDL/SOAP web-services

Page 20: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

20

1. Messages size

2. Validation via schema

Problems of traditional way - WSDL/SOAP web-services

Page 21: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

21

1. Messages size

2. Validation via schema

3. Synchronous model

Problems of traditional way - WSDL/SOAP web-services

Page 22: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

22

1. Messages size

2. Validation via schema

3. Synchronous model

4. HTTP(S)

Problems of traditional way - WSDL/SOAP web-services

Page 23: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

23

1. Messages Size

Problems of traditional way – RESTful/JSON web-services

Page 24: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

24

1. Messages Size

2. Validation?

Problems of traditional way – RESTful/JSON web-services

Page 25: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

25

1. Messages Size

2. Validation?

3. Synchronous model

Problems of traditional way – RESTful/JSON web-services

Page 26: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

26

1. Messages Size

2. Validation?

3. Synchronous model

4. HTTP(S)

Problems of traditional way – RESTful/JSON web-services

Page 27: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

27

1. Java only!

Problems of traditional way – JMS

Page 28: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

28

1. Java only!

2. Messages Size

Problems of traditional way – JMS

Page 29: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

29

1. Java only!

2. Messages Size

3. Lots of code (except JMS 2.0 in JEE7)

Problems of traditional way – JMS

Page 30: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

30

1. Java only!

2. Messages Size

3. Lots of code (except JMS 2.0 in JEE7)

4. Lost messages

Problems of traditional way – JMS

Page 31: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

31

1. Java only!

2. Messages Size

3. Lots of code (except JMS 2.0 in JEE7)

4. Lost messages

5. Duplicates

Problems of traditional way – JMS

Page 32: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

32

1. Enterprise Integration Patterns

2. Apache Camel

3. Spring Integration

Modern alternatives

Page 33: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

33

Modern alternatives – Apache Camel

@Override public void configure() throws Exception { from("direct:start") .split().method("sectionRequestSplitterBean", "split") .aggregationStrategy(new ReportAggregationStrategy()) .transform().method("sectionRequestToXMLBean", "transform") .to(serviceURL) .transform().method("sectionResponseXMLToSectionBean", "transform"); }

public void setServiceURL(String serviceURL) { this.serviceURL = serviceURL; }

Page 34: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

34

Modern alternatives

Page 35: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

35

1. File Transfer

2. Shared Database

3. Remote Procedure Call

4. Messaging

Modern alternatives

Page 36: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

36

Problems of coding

1. Synchronous vs Asynchronous

2. Systems Integration or Distributed System?

3. Do we really need a Bus (Mediator)?

4. Back pressure (Reactive Streams – Erlang, Scala, Java)

Modern alternatives

Page 37: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

37

1. http://queues.io (~26 decisions)

2. Local BlockingQueue (“seda” in Apache Camel, JdbcChannelMessageStore in Spring Integration)

3. ZooKeeper

4. JCache (Hazelcast)

5. In-memory NoSQL DB (Redis, DertyDB,…)

6. AMQP (ActiveMQ, RabbitMQ)

7. ZeroMQ

8. Amazon SQS

9. Apache Kafka (ZooKeeper inside!)

Modern alternatives

Page 38: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

38

Modern alternatives - AMQP (ActiveMQ, RabbitMQ)

Page 39: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

39

Modern alternatives – Apache Kafka

Page 40: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

40

Modern alternatives – Apache Kafka

1. Shared write-ahead log• partitions

Page 41: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

41

Modern alternatives – Apache Kafka

Page 42: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

42

Stream-style code

Page 43: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

43

Stream-style code

@Autowired ParametrizedConsumer<OneFieldBean> simpleAmqpReceiver;

@Test public void priyomSoobshcheniy() throws Exception { simpleAmqpReceiver.objectStream(OneFieldBean.class) .forEach(object -> out.println(object.getS())); }

Page 44: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

44

Stream-style code

private static int ITERATIONS_NUMBER = 1_000;

@Autowired private Sender<OneFieldBean> sender; private Benchmark benchmark = new Benchmark(out::println);

@Test public void prostaiaPosilkaSoobshcheniy() throws Exception { benchmark.benchmarkOperation(() -> { for (int i = 1; i < ITERATIONS_NUMBER; ) sender.sendMessage(new SimpleOneFieldBean().setS("тест " + i++)); return "done!"; }, "Послано за (сек.): "); }

Page 45: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

45

Stream-style code

private static int ITERATIONS_NUMBER = 1_000;

@Test public void posilkaSoobshcheniyCherezStream() { benchmark.benchmarkOperation(() -> { sender.streamSending( new Iterator<OneFieldBean>() { AtomicInteger i = new AtomicInteger(0); @Override public boolean hasNext() { return i.get() < ITERATIONS_NUMBER; } @Override public OneFieldBean next() { return new SimpleOneFieldBean().setS("тест " + i.getAndIncrement()); } } ); return "done!"; }, "Послано за (сек.): "); }

Page 46: Stream-style messaging development with Rabbit, Active, ZeroMQ & Apache Kafka by Vyacheslav Lapin

46

Stream-style code

@POST@Produces({“application/x-msgpack; qs=1”, “application/json; qs=0.75”}) public Order getOrder() { // … }