Saturday, August 12, 2017

How to use RabbitMQ


What is RabbitMQ?

RabbitMQ is an Erlang-based message broker that natively speaks AMQP 0.9.1. It implements all the AMQP 0.9.1 concepts of messages, queues, exchanges, bindings, virtual hosts, producers and consumers within the broker application.

In the diagram below, "P" is our producer and "C" is our consumer. The box in the middle is a queue - a message buffer that RabbitMQ keeps on behalf of the consumer.

In short, a broker can be divided up into virtual hosts (mainly for administrative simplicity). Each one of these virtual hosts can have some queues and exchanges associated with it and bindings can be used to attach a transfer to a queue or queues. Those transactions can be direct exchanges (passing a message on to a bound queue determined by a routing key), fanout exchanges (sending all messages onto all bound queues) or header exchanges (sending messages onwards based on matching fields in the header).

The developers have added their own set of extensions to the RabbitMQ mix though. Exchanges can be bound to other trades to create richer routing, improved mechanisms for tracking message delivery, time-to-live settings for queues and messages and more, with a focus on being an efficient, balanced messaging platform. Add to that the RabbitMQ implementation which gives you control of the performance/reliability ratio, clustering with high availability queues, a web-based Admin UI and a plugin extension system for protocols and other functionality.

What is Compose RabbitMQ?

We've taken RabbitMQ and created a Compose deployment of it which delivers the best of RabbitMQ for most users. Using three nodes, clustered together and operating in a high availability mode as a single logical broker; each node mirrors the cluster's configuration. Access to the cluster is, as with all Compose offerings, managed through a pair of haproxy TCP portals which are whitelisting and SSL supported. With Compose RabbitMQ you can move your interapplication connection infrastructure to the cloud where your applications live without having to add it to the services you directly manage and maintain.


If you want to check it out now and don't have a Compose account just sign up for a Compose account and select RabbitMQ as your first service. If you already have a Compose account, go to the Compose Console and choose "Create Deployment" and RabbitMQ to get your RabbitMQ on Compose.

Connecting to Compose for RabbitMQ

You can connect to your service using the credentials that are created along with the service, or with the connection strings and command line that are provided in the Overview tab of your service dashboard.

Connecting a Docker application to Compose for RabbitMQ

To connect a Docker container application to your service, use the credentials that are created along with the service. You can find information on how to connect a Docker container application to a Compose for RabbitMQ service in Connecting to Docker Application.

Connecting to Compose for RabbitMQ from outside the container

If you want to connect to Compose for RabbitMQ from outside of the container, you can use the provided connection strings or command line. You can find information on how to connect in Connecting an external application.

Example of Docker compose for RabbitMQ:
frontend:
  build: ./example-docker-services-frontend
  ports:
    - "4321:4321"
  links:
    - rabbitmq
    - postgres
  environment:
    - AMPQ_ADDRESS=amqp://rabbitmq:4561
    - DATABASE_URL=postgres://postgres:mysecretpassword@postgres:4321
  volumes:
    - ./example-docker-services-frontend/:/app
grader:
  build: ./example-docker-services-grader
  links:
    - rabbitmq
  environment:
    - AMPQ_ADDRESS=amqp://rabbitmq:4561
  volumes:
    - ./example-docker-services-grader/:/app

postgres:
image: postgres:latest
ports:
- 4321

rabbitmq:
  image: rabbitmq
  ports:
    - 4561

  environment:
    - POSTGRES_PASSWORD=mysecretpassword
    - POSTGRES_USER=postgres




I hope this helps and Happy coding,

Thiago Leoncio.

No comments:

Post a Comment