5. Manage Streams

There are multiple ways to manage RabbitMQ streams. The recommended way to create or delete a RabbitMQ stream is to use RabbitMQ CLI tools or infrastructure automation software.

5.1. RabbitMQ CLI Tools

Use rabbitmqadmin and rabbitmqctl command-line RabbitMQ tools to create and delete streams.

To create a RabbitMQ stream, declare a queue with queue_type argument set to stream:

$ rabbitmqadmin declare queue name=yellow.carrot queue_type=stream \
    arguments='{"x-max-age": "24h"}'

To delete a stream use rabbitmqctl command-line tool:

$ rabbitmqctl delete_queue yellow.carrot

5.2. Automation Tools

RabbitMQ streams can be created using automation tools like Terraform or Ansible

As with RabbitMQ CLI tools, declare a RabbitMQ queue, and use x-queue-type argument set to stream. For example, for Ansible:

- name: Create a RabbitMQ stream
  become: yes
  community.rabbitmq.rabbitmq_queue:
    name: yellow.carrot
    arguments:
      x-queue-type: stream
      x-max-age: 1D

5.3. RbFly API

Note

This method of creating and deleting RabbitMQ streams is not recommended. It is used for tesing and in short examples only.

RbFly allows to create and delete streams programmatically with create_stream() and delete_stream() methods:

await client.create_stream('yellow.carrot')
await client.delete_stream('yellow.carrot')