diff --git a/assets/images/activemq/activemq-admin.jpg b/assets/images/activemq/activemq-admin.jpg new file mode 100644 index 00000000..21b3e2c2 Binary files /dev/null and b/assets/images/activemq/activemq-admin.jpg differ diff --git a/assets/images/activemq/activemq-queue.jpg b/assets/images/activemq/activemq-queue.jpg new file mode 100644 index 00000000..3192ee5a Binary files /dev/null and b/assets/images/activemq/activemq-queue.jpg differ diff --git a/assets/images/activemq/activemq-topic.jpg b/assets/images/activemq/activemq-topic.jpg new file mode 100644 index 00000000..503e9b8a Binary files /dev/null and b/assets/images/activemq/activemq-topic.jpg differ diff --git a/assets/images/activemq/amazon-mq.jpg b/assets/images/activemq/amazon-mq.jpg new file mode 100644 index 00000000..aae95f3a Binary files /dev/null and b/assets/images/activemq/amazon-mq.jpg differ diff --git a/assets/images/activemq/queue-used.jpg b/assets/images/activemq/queue-used.jpg new file mode 100644 index 00000000..a118d14a Binary files /dev/null and b/assets/images/activemq/queue-used.jpg differ diff --git a/assets/images/activemq/queue.png b/assets/images/activemq/queue.png new file mode 100644 index 00000000..b0e5a3a8 Binary files /dev/null and b/assets/images/activemq/queue.png differ diff --git a/assets/images/activemq/topics.png b/assets/images/activemq/topics.png new file mode 100644 index 00000000..37d46fa3 Binary files /dev/null and b/assets/images/activemq/topics.png differ diff --git a/assets/images/activemq/virtual-topics.png b/assets/images/activemq/virtual-topics.png new file mode 100644 index 00000000..0581068b Binary files /dev/null and b/assets/images/activemq/virtual-topics.png differ diff --git a/slides/activemq.markdown b/slides/activemq.markdown new file mode 100644 index 00000000..d0438ff1 --- /dev/null +++ b/slides/activemq.markdown @@ -0,0 +1,436 @@ +--- +layout: slide +title: ActiveMQ +--- + +# ActiveMQ + +Open source multi-protocol Messaging Broker. + +-- + +# Advantages + +* Supports many [Cross Language Clients and Protocols](http://activemq.apache.org/cross-language-clients) +* High availability using shared storage (master/slave) +* KahaDB & JDBC options for persistence + +--- + +# Installing + +ActiveMQ requires Java 7 to run and to build. + +## Brew (on MacOS) + +```bash +brew install apache-activemq +activemq start +``` + + +## Unix Binary Installation + +Download latest version [here](http://activemq.apache.org/components/classic/download/) + +And follow up the [documentation](http://activemq.apache.org/version-5-getting-started.html) + +-- + +## Docker + +[https://hub.docker.com/r/rmohr/activemq/](https://hub.docker.com/r/rmohr/activemq/) + +```bash +docker pull rmohr/activemq +docker run -p 61616:61616 -p 8161:8161 rmohr/activemq +``` + +-- + +# CLI commands + +`activemq start` - Creates and starts a broker using a configuration file. + +`activemq stop` - Stops a running broker + +`activemq restart` - Restarts a running broker + +-- + +# Start ActiveMQ + +```bash +activemq start + +INFO: Loading '/usr/local/Cellar/activemq/5.15.9/libexec//bin/env' +INFO: Using java '/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/bin/java' +INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details +INFO: pidfile created : '/usr/local/Cellar/activemq/5.15.9/libexec//data/activemq.pid' (pid '61388') +``` + + +-- + +# Monitoring ActiveMQ + +You can monitor ActiveMQ using the Web Console by pointing your browser at + +``` +http://localhost:8161/admin +``` + +Default credentials +``` +login: admin +pass: admin +``` + +-- + +![](/assets/images/activemq/activemq-admin.jpg) + + +--- + +# Messaging Patterns + +-- + +# Queue + +Queues are the most obvious messaging pattern implemented by ActiveMQ. They provide a direct channel between a producer and a consumer. The producer creates messages, while the consumer reads one after another. After a message was read, it’s gone. If multiple consumers are registered for a queue, only one of them will get the message. + +![](/assets/images/activemq/queue.png) + +-- + +# Topic + +Topics implement an one-to-many channel between a producer and multiple consumers. Unlike an queue, every consumer will receive a message send by the producer. + +![](/assets/images/activemq/topics.png) + +-- + +# Virtual Topics + +Virtual topics combine both approaches. While the producer sends messages to a topic, consumers will receive a copy of the message on their own dedicated queue. + +![](/assets/images/activemq/virtual-topics.png) + +--- + +# Protocols + +### AMQP, AUTO, MQTT, OpenWire, REST, RSS and Atom, Stomp, WSIF, WS Notification, XMPP +[https://activemq.apache.org/protocols.html](https://activemq.apache.org/protocols.html) + +-- + +# REST + +ActiveMQ implements a RESTful API to messaging which allows any web capable device to publish messages using a regular HTTP POST or GET. + +-- + +# Publish to Queue + +```sh +curl -u admin:admin -d "body=order_id" http://localhost:8161/api/message/shop?type=queue +``` + + +-- + +![](/assets/images/activemq/activemq-queue.jpg) + +-- + +# Publish to Topic + +```sh +curl -u admin:admin -d "body=order_id" http://localhost:8161/api/message/shop?type=topic +``` + + +-- + +![](/assets/images/activemq/activemq-topic.jpg) + +--- + +# Integration with Ruby + +-- + +# STOMP + +The Simple Text Oriented Messaging Protocol + +STOMP provides an interoperable wire format so that STOMP clients can communicate with any STOMP message broker to provide easy and widespread messaging interoperability among many languages, platforms and brokers. + +-- + +## STOMP + +A ruby gem for sending and receiving messages from a Stomp protocol compliant message queue. Includes: failover logic, ssl support. + +Gemfile + +```ruby +gem 'stomp' +``` + +```bash +bundle install +``` + + +-- + +## Initialize Connection + +```ruby +def config_hash + { + hosts: [ + { + login: 'admin', + passcode: 'admin', + host: '0.0.0.0', + port: 61613, + ssl: false + } + ] + } +end + +client = Stomp::Client.new(config_hash) +``` + +-- + +# Send a Message to Queue + +```ruby +client = Stomp::Client.new(config_hash) + +data = { order_id: 1, command: :paid } + +client.publish('/queue/user-notifications', data.to_json) + +client.close +``` + +-- + +# Receive a Message from Queue + +```ruby +client = Stomp::Client.new(config_hash) + +Thread.new do + client.subscribe('/queue/user-notifications') do |msg| + begin + msg = JSON.parse(msg.body) + + # message processing... + rescue StandardError => e + Raven.capture_exception(e) + end + end +end +``` + +-- + +![](/assets/images/activemq/queue-used.jpg) + +--- + +# Topics + +-- + +# Send a Message to Topic + +```ruby +client = Stomp::Client.new(config_hash) + +data = { order_id: 1, command: :paid } + +client.publish('/topic/user-notifications', data.to_json) + +client.close +``` + +-- + +# Receive a Message from Topic + +```ruby +client = Stomp::Client.new(config_hash) + +Thread.new do + client.subscribe('/topic/user-notifications') do |msg| + begin + msg = JSON.parse(msg.body) + + # message processing... + rescue StandardError => e + Raven.capture_exception(e) + end + end +end +``` + +--- + +# Integration with Rails + +-- + +# ActiveMessaging +Attempt to bring the simplicity and elegance of rails development to the world of messaging. + +Gemfile + +```ruby +gem 'activemessaging', github: 'kookster/activemessaging', branch: 'feat/rails5' +gem 'stomp' +``` + +```bash +bundle install +``` + +-- + +# Initializing + +```bash +rails g active_messaging:install +``` + +```bash + create app/processors/application_processor.rb + create script/poller + chmod script/poller + create script/threaded_poller + chmod script/threaded_poller + create lib/poller.rb + create config/broker.yml + gemfile daemons +``` + +-- + +# Generate a listener + +```bash +rails g active_messaging:processor RailsQueue +``` + +```bash + create app/processors/rails_queue_processor.rb + create config/messaging.rb + invoke rspec + create spec/functional/rails_queue_processor_spec.rb +``` + +-- + +# Destination config + +```ruby +ActiveMessaging::Gateway.define do |s| + s.destination :rails_queue, '/queue/RailsQueue' +end +``` + +-- + +# Processor + +```ruby +class RailsQueueProcessor < ApplicationProcessor + subscribes_to :rails_queue + + def on_message(message) + logger.debug 'RailsQueueProcessor received: ' + message + end +end +``` + +-- + +# Run Application + +```bash +script/poller run +``` + + +--- + +# Production + +-- + +# AmazonMQ +[https://aws.amazon.com/amazon-mq](https://aws.amazon.com/amazon-mq/) + +* Managed message broker service for Apache ActiveMQ +* Uses Apache KahaDB as its data store. Other data stores, such as JDBC and LevelDB, aren't supported. +* Offers low latency messaging, often as low as single digit milliseconds. +* Persistence out of the box + +-- + +# Endpoints + +![](/assets/images/activemq/amazon-mq.jpg) + +-- + +# FIFO + +[http://activemq.apache.org/total-ordering.html](http://activemq.apache.org/total-ordering.html) + +```xml + + + + + + + + + + + + +``` + +--- + +# The End + + + + + + + + + + + +