Saturday, April 20, 2019

I saw Jason Rowe speak on RabbitMQ at the Twin Cities Code Camp one week ago today.

I should warn upfront that this was the last of the five talks I saw that day as my focus started to fade, that I don't know RabbitMQ to begin with, and that this was not a beginner's talk at all. In looking back at my notes the first thing I have written down is that Martin Fowler suggests having dumb pipes and smart endpoints. RabbitMQ has been around since 2008. AMQP or Advanced Message Queue Protocol is described in one of Jason's slides as a "network protocol to enable client apps to communicate with compatible messaging systems" and was designed by John O'Hara at JPMorgan. The slide shown here specifically is one of two by Jason Rowe where he had a tortoise versus the hare thing going on and while the rabbit here, yes, represents the fast side of RabbitMQ the turtle does not represent slowness. It represents the safety that comes from a performance hit to speed in a tradeoff. As a tortoise I have a shell and that makes me safe, get it? The scale here from hare to tortoise (left to right) contains: No guarantees, Notification on failure, Publisher confirms, Alternate exchanges, HA Queues, Transactions, HA Queues w/ Transactions, Persisted Messages ...and HA herein stands for high availability. Alright, the second slide like this has from hare to tortoise: Consuming with Acknowledgement and QoS > 1, Consuming with "No Ack Mode" enabled, Consume with Acknowledgements, Consuming and using Transactions, Getting Messages ...and QoS herein stands for quality of service. Durable means saved to disk. This means that a queue can be recovered if it stops instead of lost and, yep, herein is another performance squeeze if you want to go there. Don't worry so much about queues failing as, more likely, administrators will reboot queues when they sense they are sick. In the sidecar pattern we take in all of the stuff we can, queue it up, and write it when we can. Alternatively, in a lazy queue approach one writes records to disk real quick and then only brings them into memory when needed. What are some other terms to mention? HiPE or High performance Erlang will have RabbitMQ compile itself before startup making it snappier. EasyNetQ may wrap RabbitMQ and allow .NET to talk to it easily. Jason said that Bunny was the similar thing for Java's Spring Framework, but I kinda see the word Ruby instead of the word Java when I go Google for Bunny. CPT is a term I can't find at all in Googling which Jason suggested stood for contract-based test or consumer-based test. Azure Event Hub and Azure Service Bus are rivals to RabbitMQ I suppose. CloudAMQP is a good play place to figure out RabbitMQ. RabbitMQ does round robin out of the box, processing things in a circular order. RabbitMQ doesn't look at your messages at all and you could put a gigabyte of stuff in a message but it is not recommended. Some of Jason's C# code that I don't really understand:

public class BusFactory : IDisposable
{
   private static IBus busInstance;
   
   public IBus GetBus()
   {
      if (busInstance == null)
      {
         busInstance = RabbitHutch.CreateBus(Configuration.Host);
         busInstance.Advanced.MessageReturned += Advanced_MessageReturned;
      }
      return busInstance;
   }
   
   private void Advanced_MessageReturned(object sender,
         MessageReturnedEventArgs e)
   {

 
 

More yet follows.

var busFactory = new BusFactory();
using (var bus = busFactory.GetBus())
{
   var queueName = Configuration.HelloWorldQueueName;
   var exchangeName = Configuration.HelloWorldExchangeName;
   var routingKey = Configuration.HelloWorldRoutingKey;
   
   
// Declare exchange/queue and setup consumer for hello world message
   var queue = bus.Advanced.QueueDeclare(queueName);
   var exchange = bus.Advanced.ExchangeDeclare(exchangeName, "topic");
   bus.Advanced.Bind(exhange, queue, routingKey);
   
   
// Setup consumer and onMessage handler.
   bus.Advanced.Consume(queue, (body, properties, info) =>
   {
      var json = Encoding.UTF8.GetString(body);
      
// JSON would normally be deserialized via shared Nuget package.
      Console.WriteLine(json);
   });
   
   while (true)
   {
      Console.WriteLine($"Consumer running and commerical status = {bus.
...

No comments:

Post a Comment