Finally, we stop the Event Machine event loop and exit.
Blabbr is pretty unlikely to secure hundreds of millions of dollars in funding, but it does a pretty good job of demonstrating how one can use AMQP fanout exchanges to do broadcasting.
The primary reason for supporting usage without a callback for server-µnamed queues is backwards compatibility with earlier versions of the gem. You have learned quite a bit about both AMQP 0.9.1 and the amqp gem. AMQP has many more features built into the protocol: and so on.
Since Ruby is a genuine object-oriented language, it is important to demonstrate how the Ruby amqp gem can be integrated into rich object-oriented code. Other guides explain these features in depth, as well as use cases for them.
Note: The Rabbit MQ package that ships with some popular Ubuntu versions (for example, 10.04 and 10.10) is outdated and *will not work with amqp gem 0.8.0 and later versions* (you will need at least Rabbit MQ v2.0 for use with this guide). We will not go into what the term 'reactor' means here, but suffice it to say that the amqp gem is asynchronous and is based on an asynchronous network I/O library called on the channel that we have just opened. We declared this queue with the "auto-delete" parameter.
Basically, this means that the queue will be deleted when there are no more processes consuming messages from it. The default exchange will route the message to a queue that has the same name as the message's routing key.
Three Blabbr members, Joe, Aaron and Bob, follow the official NBA account on Blabbr to get updates about what is happening in the world of basketball. It sets up a binding between the queue and the exchange that you pass to it.
We need to do this to make sure that our fanout exchange routes messages to the queues of any subscribed followers. Blabbr members use a fanout exchange for publishing, so there is no need to specify a message routing key because every queue that is bound to the exchange will get its own copy of all messages, regardless of the queue name and routing key used. https://github.com/ruby-amqp/amqp/raw/master/docs/diagrams/002_blabbr_example_routing.png! Next we use Event Machine's add_timer method to run a piece of code in 1 second from now: .
A (very simplistic) diagram to demonstrate topic exchange in action: !
https://github.com/ruby-amqp/amqp/raw/master/docs/diagrams/003_weathr_example_routing.png! One more thing that is different from previous examples is that the block we pass to For this example the publishing of messages is no different from that of previous examples.
People who live in Portland usually do not care about the weather in Hong Kong (unless they are visiting soon).
They are much more interested in weather conditions around Portland, possibly all of Oregon and sometimes a few neighbouring states.
The previous example demonstrated how a connection to a broker is made and how to do 1:1 communication using the default exchange.