Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleInfo

I love it...

After years of working with CORBA and not really seeing anything much on the market to replace it, I was forced to look at an alternative in the form of WebServices using a ReSTful api called Jersey - absolute nightmare to work with it.  It turns a simple task of marshalling complex objects across the wire in into an Eaton Mess.  It's a mishmash of code that just doesn't work properly, is and it's hard to debug and test.

I've been familiar with MOM based technologies since the 1990s (DDE, JMS, MS-MQ, MQ-Series etc).  I had heard about RabbitMQ some time ago but never actually used.  So when I decided to get my teeth into it, I was shocked how easy it was to deploy and work.  It's elegant and easy to work with.

I'm working with the pub/sub model.  The examples given in the RabbitMQ documentation are pretty much outline outlined in the code as that follows

Code Block
languagejava
titlePublisher
linenumberstrue
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;

public class RabbitMqLogsSender
{
    private static String EXCHANGE_NAME = "logs"; // specify as ReSTful URI param
    private static final String HOST_ID = "192.168.99.100"; // put in a config file

    public static void main(String[] argv) throws Exception
    {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(HOST_ID);   // put this in a config file
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);

        String message = argv[0];

        channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes("UTF-8"));
        System.out.println(" [x] Sent '" + message + "'");

        channel.close();
        connection.close();
    }

...

Calls to declare Queues or Exchanges in RabbitMQ are idempotent.  Each time the api call exchangeDeclare() is called with the same Exchange name, the same exchange is returned after that the first call would have returned.  If you attempt to perform an operation on an exchange that hasn't has not been created yet, RabbitMQ will throw an exception.  

...