Archive | RabbitMQ RSS for this section

RabbitMQ Library for Prolog

Recently I’ve started working on a new project that involves Prolog, C and Ruby. The objective is to implement a Prolog library to work with RabbitMQ. RabbitMQ is a message broker that implements the AMQP protocol, thats, Advance Message Queueing Protocol.

AMQP and RabbitMQ

Without going into much detail, RabbitMQ is a message broker that implements the AMQP protocol. RabbitMQ receives messages from producers and sends them to, possibly, predefined consumers. To do this, RabbitMQ uses two things, exchanges and queues.

Exchanges and queues are binded together. The exchanges are the parts of RabbitMQ that receive messages from producers has input and decide what to do with them. They may decide to simply ignore the message, store them in every queue binded to them, store them in some particular queue, etc. The type of exchange, and some added arguments in their declaration, determine their behavior. Consumers are programs that will look into specific queues and will read the messages in them.

To know more about the different types of exchanges read this article in Buny’s site.

Prolog Library

There are many libraries for RabbitMQ in many languages. Just the tutorial in RabbitMQ’s site is written for five different languages, which are Python, Java, Ruby, PHP, and C#. I myself have looked into Python’s Pika library, Ruby’s Bunny library, and also RabbitMQ-C for the C programming language. The project in here is the development of a similar thing but for Prolog.

The library in Prolog will work with a set of predicates. A predicate is, for example the following:

amqp_new_connection(Conn, localhost:5672).

In this example, the predicate will actually create a new connection using localhost on port 5672. Conn will be a term, which in this context works like the connection descriptor for the newly created connection. Most of the predicates in the library work/will work using this descriptor notion.

The library is being developed to work with YAP, (Yet Another Prolog). To achieve this implementation, the predicates are implemented in Prolog with some low level parts implemented in C using RabbitMQ-C. The predicates are being made to resemble the Bunny library, meaning that most predicates are actually mimicking Bunny’s API. For example, in Ruby, to declare a direct exchange you do:

ex ="myex")

Where ch is a channel, “myex” is the name of the exchange, and ex will be the new exchange. The Prolog equivalent is:

amqp_direct_exchange(Chn, "myex", [], Ex).

Where, Chn is the channel, “myex” is the name of the exchange, the third argument is an empty list of arguments, and Ex is the descriptor for the newly created exchange.

So, this project involves using Prolog and C to implement a Prolog Library based on a Ruby library for a message broker. Ruby and RabbitMQ are actually new to me, the other things are old news. This is actually being very interesting.

What Is Currently Done

Currently, it is already possible to implement a basic producer and a basic consumer in Prolog. There aren’t many options that can be used yet, such as different arguments for the various objects that get used around. Also, some underlining code is missing some error handling, like for example, there may be errors while connecting to a server, while sending a message, etc. The current implementation always assumes everything goes just fine. This obviously needs to be solved.

On my GitHub are examples of the basic producer and consumer in Prolog. Also on GitHub are the Ruby’s equivalent for a producer and a consumer using Bunny. Note that the Ruby example should execute if you have Buny installed. But the Prolog example shouldn’t run because the implementation isn’t released nor finished.