RabbitMQ - Create dynamic shovel using Terraform

A shovel is used to move a message from a queue or exchange to a different queue or exchage. The queues or exchanges can reside on the same RabbitMQ node or on different RabbitMQ nodes.

 

AVOID TROUBLE

Before you can create a shovel, the rabbitmq_shovel plugin will need to be enabled, and you may want to also enable the rabbitmq_shovel_management plugin so that you can use Shovel Status and Shovel Management in the RabbitMQ web browser console and the RabbitMQ REST API to list/create/delete dynamic shovels. The rabbitmq-plugins list command can be used to determine if the plugins are enabled. If not, the rabbitmq-plugins enable command can be used to enable the plugins.

If the RabbitMQ node is not using SSL, the src-uri or dest-uri should start with amqp://. If SSL is being used, the src-uri or dest-uri should start with amqps://.

 

There are two types of shovels.

 

This assumes you have setup Terraform as described in RabbitMQ - Getting Started with Terraform. Let's say you have the following files on your Terraform server.

/usr/local/terraform/main.tf
/usr/local/terraform/foo/required_provider.tf
/usr/local/terraform/foo/bindings.tf
/usr/local/terraform/foo/exchanges.tf
/usr/local/terraform/foo/policies.tf
/usr/local/terraform/foo/queues.tf
/usr/local/terraform/foo/shovels.tf
/usr/local/terraform/foo/vhosts.tf

 

Add the following to your shovels.tf file. In this example, a dynamic shovel named shovel001 is created that will move messages from foo.queue to bar.queue.

resource "rabbitmq_shovel" "shovel1" {
  name = "shovel001"
  vhost = "foo"
  info {
    ack_mode = "on-confirm"
    source_protocol = "amqp091"
    source_uri = "amqp://john.doe:itsasecret@rabbit001.example.com:5672/foo"
    source_queue = "foo.queue"
    destination_protocol = "amqp091"
    destination_uri = "amqps://john.doe:itsasecret@rabbit002.example.com:5672/bar"
    destination_queue = "bar.queue"
    reconnect_delay = 1
  }
}

 

Issue the following command to create the queue. 

terraform apply

 

Something like this should be displayed, and you will be prompted to enter yes.

Terraform will perform the following actions:

  # rabbitmq_shovel.shovel1 will be created
  + resource "rabbitmq_shovel" "shovel1" {
      + id    = (known after apply)
      + name  = "shovel001"
      + vhost = "foo"

      +   info {
        + ack_mode = "on-confirm"
        + source_protocol = "amqp091"
        + source_uri = "amqp://john.doe:itsasecret@rabbit001.example.com:5672/foo"
        + source_queue = "foo.queue"
        + destination_protocol = "amqp091"
        + destination_uri = "amqps://john.doe:itsasecret@rabbit002.example.com:5672/bar"
        + destination_queue = "bar.queue"
        + reconnect_delay = 1
      }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

 

After entering yes, the following should be displayed.

rabbitmq_shovel.shovel1: Creating...
rabbitmq_shovel.shovel1: Creation complete after 0s [id=shovel001@foo]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 2bc67 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |