| layout | slide |
|---|---|
| title | ActiveMQ |
Open source multi-protocol Messaging Broker.
--
- Supports many Cross Language Clients and Protocols
- High availability using shared storage (master/slave)
- KahaDB & JDBC options for persistence
ActiveMQ requires Java 7 to run and to build.
brew install apache-activemq
activemq startDownload latest version here
And follow up the documentation
--
https://hub.docker.com/r/rmohr/activemq/
docker pull rmohr/activemq
docker run -p 61616:61616 -p 8161:8161 rmohr/activemq--
activemq start - Creates and starts a broker using a configuration file.
activemq stop - Stops a running broker
activemq restart - Restarts a running broker
--
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')--
You can monitor ActiveMQ using the Web Console by pointing your browser at
http://localhost:8161/admin
Default credentials
login: admin
pass: admin
--
--
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.
--
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.
--
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.
https://activemq.apache.org/protocols.html
--
ActiveMQ implements a RESTful API to messaging which allows any web capable device to publish messages using a regular HTTP POST or GET.
--
curl -u admin:admin -d "body=order_id" http://localhost:8161/api/message/shop?type=queue--
--
curl -u admin:admin -d "body=order_id" http://localhost:8161/api/message/shop?type=topic--
--
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.
--
A ruby gem for sending and receiving messages from a Stomp protocol compliant message queue. Includes: failover logic, ssl support.
Gemfile
gem 'stomp'bundle install--
def config_hash
{
hosts: [
{
login: 'admin',
passcode: 'admin',
host: '0.0.0.0',
port: 61613,
ssl: false
}
]
}
end
client = Stomp::Client.new(config_hash)--
client = Stomp::Client.new(config_hash)
data = { order_id: 1, command: :paid }
client.publish('/queue/user-notifications', data.to_json)
client.close--
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--
--
client = Stomp::Client.new(config_hash)
data = { order_id: 1, command: :paid }
client.publish('/topic/user-notifications', data.to_json)
client.close--
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--
Attempt to bring the simplicity and elegance of rails development to the world of messaging.
Gemfile
gem 'activemessaging', github: 'kookster/activemessaging', branch: 'feat/rails5'
gem 'stomp'bundle install--
rails g active_messaging:install 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--
rails g active_messaging:processor RailsQueue create app/processors/rails_queue_processor.rb
create config/messaging.rb
invoke rspec
create spec/functional/rails_queue_processor_spec.rb--
ActiveMessaging::Gateway.define do |s|
s.destination :rails_queue, '/queue/RailsQueue'
end--
class RailsQueueProcessor < ApplicationProcessor
subscribes_to :rails_queue
def on_message(message)
logger.debug 'RailsQueueProcessor received: ' + message
end
end--
script/poller run--
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
--
--
http://activemq.apache.org/total-ordering.html
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">">
<!--
The constantPendingMessageLimitStrategy is used to prevent
slow topic consumers to block producers and affect other consumers
by limiting the number of messages that are retained
For more information, see: http://activemq.apache.org/slow-consumer-handling.html
-->
<dispatchPolicy>
<strictOrderDispatchPolicy/>
</dispatchPolicy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>






