AMQP/RabbitMQ in Java

Making Code 39 Extended in Java AMQP/RabbitMQ
8 AMQP/RabbitMQ
Code 3 Of 9 Drawer In Java
Using Barcode printer for Java Control to generate, create Code39 image in Java applications.
Message 1
Barcode Maker In Java
Using Barcode maker for Java Control to generate, create barcode image in Java applications.
Message 2
Barcode Reader In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
Message 3
Code 39 Full ASCII Creation In C#.NET
Using Barcode generation for Visual Studio .NET Control to generate, create Code 3/9 image in VS .NET applications.
Fanout: Foo
Make USS Code 39 In .NET
Using Barcode creator for ASP.NET Control to generate, create USS Code 39 image in ASP.NET applications.
Queue: Foo (1) Message 1
Code 39 Creation In .NET Framework
Using Barcode maker for Visual Studio .NET Control to generate, create Code39 image in .NET framework applications.
Queue: Foo (2) Message 1
Making Code 3 Of 9 In Visual Basic .NET
Using Barcode printer for VS .NET Control to generate, create ANSI/AIM Code 39 image in VS .NET applications.
Queue: Foo (3) Message 1
Drawing Code 128A In Java
Using Barcode generation for Java Control to generate, create Code-128 image in Java applications.
Message 2
Encode GS1 - 12 In Java
Using Barcode generation for Java Control to generate, create Universal Product Code version A image in Java applications.
Message 2
Barcode Drawer In Java
Using Barcode creation for Java Control to generate, create barcode image in Java applications.
Message 2
Code 3 Of 9 Creation In Java
Using Barcode generator for Java Control to generate, create Code 3 of 9 image in Java applications.
Message 3
EAN13 Generator In Java
Using Barcode encoder for Java Control to generate, create EAN13 image in Java applications.
Message 3
MSI Plessey Maker In Java
Using Barcode creator for Java Control to generate, create MSI Plessey image in Java applications.
Message 3
Code 39 Extended Maker In .NET
Using Barcode creator for ASP.NET Control to generate, create Code-39 image in ASP.NET applications.
Figure 8-3 A fanout queue places a copy of each message into each queues that is bound to the queue
Code128 Creator In VB.NET
Using Barcode encoder for .NET Control to generate, create ANSI/AIM Code 128 image in .NET applications.
Building our publisher code to write to a fanout queue is not that different from some of our other queues:
Paint Bar Code In VS .NET
Using Barcode creation for Visual Studio .NET Control to generate, create bar code image in .NET applications.
require 'rubygems' require 'mq' AMQPstart do logger = MQfanout('logger') loggerpublish('log message #1') loggerpublish('log message #2') loggerpublish('log message #3') end
Bar Code Printer In .NET
Using Barcode creation for Visual Studio .NET Control to generate, create bar code image in .NET applications.
Fanout Queues
UPC Symbol Encoder In VS .NET
Using Barcode printer for VS .NET Control to generate, create UPC-A Supplement 2 image in .NET framework applications.
In our publisher code, where we would normally call the queue method on MQ, we instead call the fanout method, giving it a name for the fanout queue We then publish a few messages to it as normal On the consumer side of things, handling fanout queues is not much different from topics:
Make Code 128 In Visual C#.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create USS Code 128 image in .NET framework applications.
require 'rubygems' require 'mq' AMQPstart do log_server_1 = MQqueue('log server #1') log_server_1bind(MQfanout('logger'))subscribe do |msg| puts "Log Server #1: #{msg}" end log_server_2 = MQqueue('log server #2') log_server_2bind(MQfanout('logger'))subscribe do |msg| puts "Log Server #2: #{msg}" end log_server_3 = MQqueue('log server #3') log_server_3bind(MQfanout('logger'))subscribe do |msg| puts "Log Server #3: #{msg}" end end
Painting Bar Code In .NET
Using Barcode generation for ASP.NET Control to generate, create bar code image in ASP.NET applications.
This code should not look too different from our earlier topic examples First we create a new queue to allow us to get a copy of the messages:
log_server_1 = MQqueue('log server #1')
We then bind that queue to the fanout queue and subscribe to the resulting queue:
log_server_1bind(MQfanout('logger'))subscribe
After we have bound the new queue and the fanout queue, the subscribe method, as mentioned earlier, takes a block that yields a message for us to manipulate as we please
8 AMQP/RabbitMQ
Unbinding
When we talked about topics and fanout queues, we discussed binding a queue to either a topic or fanout queue But what happens if we want to remove that binding Why would we want to remove the binding between a queue and, let s say, a topic Perhaps you just want to dip into the queue to do some debugging, or you want to take a pulse point, or perhaps you want to add extra horsepower during a heavy load time and decrease the number of consumers you have when the server load diminishes Whatever your reason for wanting to remove that binding, it is nice to know that this is very easy to do:
my_queueunbind(MQtopic("some_topic"))
The unbind method takes the same input that the bind method does the queue you originally bound the current queue to
Conclusion
The AMQP gem, protocol, and RabbitMQ are a powerful combination This chapter has only touched on what they can do These systems have proven to be stable, fast, and, as you ve seen, easy to use Because of these traits, AMQP and RabbitMQ have quickly risen to the top of the list when it comes to distributed message queuing systems I have mentioned several times in this chapter that the documentation that comes bundled with the AMQP gem is superb, but it deserves another mention here Although I have outlined and given you brief examples of each of the highlights of this gem, it is important to know all the different options that are available for each of the methods and queues Please take a good look at the documentation It will definitely save you time and make your systems more stable, secure, and reliable
Endnotes
Endnotes
1 http://wwwrabbitmqcom/ 2 http://wwwamqporg 3 http://githubcom/tmm1/amqp/tree/master 4 http://rubyeventmachinecom 5 http://enwikipediaorg/wiki/Reactor_pattern
This page intentionally left blank
PART IV
Distributed Programming with Ruby on Rails
When I came up with the idea for this book, I intended to make it strictly about pure Ruby I had no intention of including any chapters that were specific to Ruby on Rails However, after thinking about it, I realized it would be hard not to include the next couple of chapters They focus on tools that work only within a Ruby on Rails environment, but they are so helpful that I would be remiss if I did not include them They also demonstrate a few interesting architectural points worth discussing If you use Ruby on Rails, there is no reason for you not to read this part of the book The tools in this part can help your Ruby on Rails applications scale and be more efficient and easier to code You might already know about these tools, but I am convinced that I have written about aspects of the tool you probably don t know about Or perhaps you thought the tool was doing something one way, when in fact it does it the opposite way Understanding your tools better can help you write better code, which, in turn, makes for a better and more stable system
Even if you don t use Ruby on Rails daily (some people who use Ruby don t use Ruby on Rails at all), I still recommend that you read this part of the book You might find inspiration to write a pure Ruby port of these tools Or you might contribute to them so that they can be used with your favorite Ruby framework Or you might find a good reason buried in there to start using Ruby on Rails