Add a queue in RabbitMQ

The Devprime platform’s ‘AddQueueRabbitMQ’ method is used to create a new queue in RabbitMQ. This method allows you to set custom properties for the queue, giving you flexibility in configuration.

Parameters

  • alias (string, optional): Optional parameter with the name of the Stream Alias as defined in the Stream Adapter configuration. The default value is “Stream1”.

  • queueName (string): Name of the queue. This is the unique identifier of the queue in RabbitMQ.

  • customProperties (CustomQueueProperties, optional): Custom properties for the queue, such as Time-to-Live (TTL) settings, persistence, and other queue-specific characteristics.

Return

  • bool: Returns true if the queue is successfully created; otherwise, returns false.

Here’s an example of how to use the AddQueueRabbitMQ method in your application:

Creating a queue without using the properties

The CustomQueueProperties parameter is optional and used only for customization

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// The CustomQueueProperties parameter is optional and used only for customization
var queueName = "myQueueName";
bool success = Dp.Stream.AddQueueRabbitMQ(queueName, null);
if (success)
    {
    Console.WriteLine("Fila criada com sucesso.");
    }
    else
    {
    Console.WriteLine("Falha ao criar a fila.");
    }

Creating a queue with the proprities and null argument

1
2
3
4
5
6
7
8
var customProperties = new CustomQueueProperties
{
    Durable = true,
    Exclusive = false,
    AutoDelete = false,
    Arguments = null
};
Dp.Stream.AddQueueRabbitMQ("queue-with-properties", customProperties);

Creating a queue with the properties and argument setting TTL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// This parameter is optional and used only for customization
// Creation of a queue with custom properties
var customProperties = new CustomQueueProperties
{
    Durable = true,
    Exclusive = false,
    AutoDelete = false,
    Arguments = new Dictionary<string, object>
    {
        { "x-message-ttl", 600000 } // TTL
    }
};
Dp.Stream.AddQueueRabbitMQ("queue-with-properties", customProperties);

Considerations

  • Make sure that the queueName is unique within RabbitMQ to avoid conflicts.
  • Use custom properties to configure the queue according to the specific needs of your application.
  • Native implementations of RabbitMQ are specific to this platform and cater to particular use cases. If you migrate to another streaming platform, you’ll need to adjust your code to use Devprime’s standard methods or the new platform’s specific methods.
Last modified September 10, 2024 (6166aa4f)