Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java Messaging with AMQP and RabbitMQ

Обзор возможностей RabbitMQ и AMQP как альтернативы JMS для обмена сообщениями в Java Middleware.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to comment

Java Messaging with AMQP and RabbitMQ

  1. 1. Java Messaging with AMQP and RabbitMQ или “JMS, давай до-свидания” 1
  2. 2. The big picture 2
  3. 3. 3
  4. 4. Async Java World Servlets 3.0 - async requests Servlets 3.1 - nio Netty ReactiveX (RxJava) Vert.xJAX-RSSpring MVC Play Framework Akka 4
  5. 5. Messaging Protocols AMQP MQTT STOMP 0-9-1 1-0 JMS SMTP, POP3, IMAP XMPP DDS 5
  6. 6. Protocols comparison 6
  7. 7. AMQP facts Wire Protocol Родился в 2006 in J.P.Morgan (миллиарды сообщений в день) Миссия: интеграция сообщений между платформами Поддерживается в Apache Camel, Spring Integration, Mule,.. 7
  8. 8. AMQP is the Internet Protocol for Business Messaging versions: 1.0 - Now International standard: ISO/IEC 19464:2014, OASIS (2014) RabbitMQ supports version 1.0 via plugin 0-10, 0-9-1, 0-9, 0-8 1.0: Not declaring broker architecture, broker management commands. Symmetric. 8
  9. 9. 9
  10. 10. Frames Frame structure: Sending content: Content Header: 10
  11. 11. One Million Messages Per Second on Google 31 nodes, 8 virtual CPUs on each, 248 cores total (2014, https://blog.pivotal.io/pivotal/products/rabbitmq-hits-one-million-messages-per-second-on-google- compute-engine 11
  12. 12. JMS AMQP 12
  13. 13. Exchange Direct Fanout Topic Headers Types: Features: • Durability (survive broker restart) • Auto-delete (deleted when all queues have finished using it) Default Exchange 13
  14. 14. 14
  15. 15. 15
  16. 16. Topic Exchange * (star) can substitute for exactly one word. # (hash) can substitute for zero or more words. 16
  17. 17. More Exchange Types • Headers - по заголовкам сообщения “x- match”=“any”/“all” • Dead Letter Exchange (для недоставленных сообщений) • Constant-Hash (plugin) • Delayed Exchange ( задержки перед отправкой) • more … 17
  18. 18. Queues • FIFO (soft) • Durable / in-memory • Exclusive • Auto-delete • Arguments (TTL,…) 18
  19. 19. Consumers • Rule: One message goes to one consumer, unless redelivery happens • Serial per Channel (thread) • Pull / Subscribe API • Send acknowledgements (ack) • can do “auto-ack” ( hits reliability ) • round robin with optional priorities 19
  20. 20. 20
  21. 21. 21
  22. 22. Что у кролика внутри Erlang • создан в Ericsson для телеком-железа • functional • lightweight processes • good scaling over CPU • deadlocks-aware design • communication between network-distributed processes • Live code upgrade • Built in Process Monitoring and Control 22
  23. 23. Concurrency 23
  24. 24. Spring @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory cf = new CachingConnectionFactory("localhost"); cf.setUsername("guest"); cf.setPassword("guest"); return cf; } @Bean public AmqpAdmin amqpAdmin() { return new RabbitAdmin(connectionFactory()); } @Bean public RabbitTemplate rabbitTemplate() { RabbitTemplate template = new RabbitTemplate(connectionFactory()); // Отправлять сюда template.setRoutingKey(this.helloWorldQueueName); // Чиать отсюда template.setQueue(this.helloWorldQueueName); return template; } 24
  25. 25. Spring async consume @Bean public SimpleMessageListenerContainer listenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory()); container.setQueueNames(this.helloWorldQueueName); container.setMessageListener(new MessageListenerAdapter(new HelloWorldHandler())); return container; } Sync: AmqpTemplate amqpTemplate = context.getBean(AmqpTemplate.class); System.out.println("Received: " + amqpTemplate.receiveAndConvert()); 25
  26. 26. Spring: ListenerContainer AbstractMessageListenerContainer private volatile Object messageListener; private volatile AcknowledgeMode acknowledgeMode = AcknowledgeMode.AUTO; private MessageConverter messageConverter; private ErrorHandler errorHandler = new ConditionalRejectingErrorHandler(); … SimpleMessageListenerContainer private volatile Executor taskExecutor = new SimpleAsyncTaskExecutor(); private volatile int concurrentConsumers = 1; private volatile Integer maxConcurrentConsumers; private volatile boolean exclusive; private volatile int prefetchCount = DEFAULT_PREFETCH_COUNT; // 1 … 26
  27. 27. RabbitTemplate currently, the only implementation of AMQPTemplate Methods: send(Message m, …), convertAndSend(Object o , …) … recieve(): Message, recieveAndConvert(…), recieveAndReply(…) … sendAndRecieve(…), convertSendAndRecieve(), … Features: • Retry and recovery (spring-retry) • Publisher confirms and returns (ReturnCallback, ConfirmCallback) • Message PostProcessors - after receive and before publish (zip/unzip, …) 27
  28. 28. Finally, AMQP vs JMS JMS Standard API Native to Java world Enterprizzy AMQP Truly Cross - platform Comprehensive Topology More Tuning (?)
  29. 29. Some Readings: “Understanding the differences between AMQP and JMS” http://www.wmrichards.com/amqp.pdf Why Erlang is good for AMQP implementation https://pubs.vmware.com/vfabric5/index.jsp#com.vmware.vfabric.rabbitmq.2.4/erlang.html Alvaro Videla’s presentation “RabbitMQ Internal Architecture” http://www.slideshare.net/old_sound/dissecting-the-rabbit All About Messaging Protocols. What Are the Differences? by Bryon Moyer http://www.eejournal.com/archives/articles/20150420-protocols/ Whats wrong with AMQP and how to fix it http://www.imatix.com/articles:whats-wrong-with-amqp/ Messaging Products performance comparison https://softwaremill.com/mqperf/
  30. 30. Thanks Sincerely Yours, Maxim Konovalov BPC Banking Technologies, Runet Business Systems https://www.facebook.com/maxim.konovalov.1

×