# RabbitMQ - Get started

## Deploy RabbitMQ <a href="#rabbitmqhowtos-commentprovisionnerunpaasrabbitmq" id="rabbitmqhowtos-commentprovisionnerunpaasrabbitmq"></a>

To get started, go to ITCare and search for your target global service where you'll create your new RabbitMQ cluster.

Search for your Global Service in the top search bar and click on it to display its information page.

Once in your Global Service, click on the **Create Resource** button, select **RabbitMQ** and the required version.

Fill in the form:

* Select a topology
* Define the name of the future cluster
* If Cluster topology : Select the number of brokers (3+)
* Sizing
* Storage required on each broker
* Target location
* Target network
* Management options (backup, monitoring, 24/7, remote site replication)

Click **Next** once all fields have been completed.

In the next step, enter the password for the super user account to be supplied, then click **Next**.

{% hint style="warning" %}
Passwords are not saved by cegedim.cloud. Be sure to save your password!
{% endhint %}

Review the summary before submitting the form.

{% hint style="info" %}
Provisioning can take up to 2 hours, depending on the current automation load.
{% endhint %}

Once the deployment is ready, you'll be notified by e-mail.

## Start a cluster

At the top of the cluster page, click on the **Manage** button, then on **Start** and confirm.

{% hint style="info" %}
Cluster startup starts all virtual machines attached to the cluster.
{% endhint %}

An e-mail notification will be sent when the service is activated.

## Stop a cluster

At the top of the cluster page, click on the **Manage** button, then on **Stop.**

Enter an RFC number for tracking (optional). Click on **Submit**.

{% hint style="warning" %}
Shutting down a cluster will stop all virtual machines attached to the cluster, and monitoring will be disabled.
{% endhint %}

An e-mail notification will be sent when the cluster is shut down.

## Resize nodes

At the top of the cluster page, click on the **Manage** button, then on **Resize.**

Select the nodes you wish to resize and select the new size (cpu/ram).

{% hint style="info" %}
Each node will be resized and restarted sequentially.
{% endhint %}

An e-mail notification will be sent when all nodes have been resized.

## Delete a cluster

At the top of the cluster page, click on the **Manage** button, then on **Delete**. This will stop and delete all virtual machines.

{% hint style="danger" %}
Please note that this action is not recoverable!
{% endhint %}

Enter an RFC number for tracking (optional), then click **Submit**.

An e-mail notification will be sent when the cluster is deleted.

## How to manage RabbitMQ ?

### Management UI <a href="#rabbitmqhowtos-managementui" id="rabbitmqhowtos-managementui"></a>

Once your deployment is ready, you can access the management UI for your deployment from ITCare.

The link is available in the **Configuration** panel of your deployment.

### HTTP API <a href="#rabbitmqhowtos-httpapi" id="rabbitmqhowtos-httpapi"></a>

RabbitMQ can also be managed through API.

Once you get the link to your Management UI, the API is available by just adding /api at the end of the URL.

To get more information about using the API, click here :

{% embed url="<https://www.rabbitmq.com/management.html#http-api>" %}

## How to produce messages in Python ?

This section will provide examples of Python code to produce messages to a simple queue or a quorum queue.

Of course, you can use the coding langage of your choice or any middleware that support AMQP.

Also, if AMQPS is enabled (TLS/SSL), extra configuration is needed. There is also an example for that.

### Simple queue <a href="#rabbitmqhowtos-simplequeue" id="rabbitmqhowtos-simplequeue"></a>

{% code overflow="wrap" lineNumbers="true" %}

```python
#!/usr/bin/python3
import pika
 
credentials = pika.PlainCredentials('user','password')
connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='hostname', credentials=credentials))
channel = connection.channel()
 
channel.queue_declare(queue='simple-queue')
 
channel.basic_publish(exchange="", routing_key='simple-queue', body='Hello World!')
print(" [x] Sent 'Hello World!'")
 
connection.close()
```

{% endcode %}

### Quorum queue <a href="#rabbitmqhowtos-quorumqueue" id="rabbitmqhowtos-quorumqueue"></a>

{% hint style="success" %}
Highly recommended in a cluster setup for maximum resiliency !
{% endhint %}

{% code overflow="wrap" lineNumbers="true" %}

```python
#!/usr/bin/python3
import pika
 
credentials = pika.PlainCredentials('user','password')
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='hostname', credentials=credentials))
channel = connection.channel()
 
channel.queue_declare(queue="quorum-queue",durable=True,arguments={"x-queue-type": "quorum"})
 
channel.basic_publish(exchange="", routing_key='quorum-queue', body='Hello World!')
print(" [x] Sent 'Hello World!'")
 
connection.close()
```

{% endcode %}

### AMQPS <a href="#rabbitmqhowtos-amqps" id="rabbitmqhowtos-amqps"></a>

When TLS/SSL is enabled for the AMQP protocol, the certificate must be handled by either declaring it or adding it to your certificate store.

{% code overflow="wrap" lineNumbers="true" %}

```python
#!/usr/bin/python3
import pika
import ssl
import logging

logging.basicConfig(level=logging.INFO)
context = ssl.create_default_context(cafile="/path/to/certificate/my-certificate.pem")
ssl_options = pika.SSLOptions(context, "hostname")
credentials = pika.PlainCredentials('user','password')
conn_params = pika.ConnectionParameters(host='hostname', port=5671, ssl_options=ssl_options, credentials=credentials)

with pika.BlockingConnection(conn_params) as conn:
    ch = conn.channel()
    ch.queue_declare(queue="quorum-queue",durable=True,arguments={"x-queue-type": "quorum"})
    ch.basic_publish(exchange="", routing_key='quorum-queue', body='Hello World!')
    print(" [x] Sent 'Hello World!'")
```

{% endcode %}

## How to consume messages in Python ?

This section will provide examples of Python code to consume messages.

{% code overflow="wrap" lineNumbers="true" %}

```python
#!/usr/bin/python3
import pika, sys, os
 
def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)
 
def main():
    credentials = pika.PlainCredentials('user','password')
    connection = pika.BlockingConnection(pika.ConnectionParameters(host='hostname', credentials=credentials))
 
    channel = connection.channel()
 
    # Simple queue
    # channel.queue_declare(queue='hello')
    # channel.basic_consume(queue="hello", on_message_callback=callback, auto_ack=True)
 
    # Quorum queue
    channel.queue_declare(queue="quorum-queue",durable=True,arguments={"x-queue-type": "quorum"})
    channel.basic_consume(queue="quorum-queue", on_message_callback=callback, auto_ack=True)
 
    print(' [*] Waiting for messages. To exit press CTRL+C')
    channel.start_consuming()
 
if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print('Interrupted')
        try:
            sys.exit(0)
        except SystemExit:
            os._exit(0)
```

{% endcode %}
