Autobahn is a transport system abstraction for RabbitMQ. To get maximum performance for raw data transport you need to use multiple queues, more than one node, connect to the node that hosts the queue, batch your messages, encode your messages using an efficient serialization mechanism, and many more things depending on your exact use case. Autobahn abstracts and automates most of these things, letting you focus on the rest of your application.
The following example configures transport system that will transport messages JSON encoded over an existing transport system. It will look for the named exchange and discover queues and bindings using the RabbitMQ API. You only need to tell it about one node that runs the management plugin, which provides the REST API, and it will discover the topology of the cluster.
# use this setup code on both the publisher and consumer sides
rmq_api_uri = 'http://rmqhost:55672/api'
exchange_name = 'stuff'
options = {:encoder => Autobahn::JsonEncoder.new}
transport_system = Autobahn.transport_system(rmq_api_uri, exchange_name, options)
# do this on the publisher side
publisher = transport_system.publisher
loop do
# create_next_message is whatever code you need to create the next message to publish
publisher.publish(create_next_message)
end
# do this on the consumer side
consumer = transport_system.consumer
# the block passed to subscribe will be called asynchronously when new messages arrive
consumer.subscribe do |headers, message|
# process_message is whatever code you need to process a new message
process_message(message)
headers.ack
end
Autobahn has a number of optional dependencies:
- If you want to use the MessagePack encoders you need to install msgpack
- To use the LZF encoders you need ning-compress-jars
- The LZ4 encoders require lz4-ruby
© 2012-2015 Burt AB, see LICENSE.txt (BSD 3-Clause).