Skip to main content

Managing Plugins

1. Listing Available Plugins

Command Description Notes
rabbitmq-plugins list List all installed plugins Shows plugin name, status (enabled/disabled), and version
rabbitmq-plugins list -E List only enabled plugins Useful for checking active configuration
rabbitmq-plugins list -D List only disabled plugins Helps identify plugins that can be enabled

Example: Listing Plugins

rabbitmq-plugins list

Example: Output Format

[  ] rabbitmq_management   3.12.12
[ E] rabbitmq_web_stomp    3.12.12
Note: The [ E] indicates an enabled plugin, while [ ] shows a disabled one.

2. Enabling Plugin

Command Description Notes
rabbitmq-plugins enable <plugin-name> Enables a specific plugin Plugin must be installed and available
rabbitmq-plugins enable --offline <plugin-name> Enables plugin without restarting the broker Requires RabbitMQ 3.10+

Example: Enabling a Plugin

rabbitmq-plugins enable rabbitmq_management
Note: After enabling a plugin, you may need to restart the RabbitMQ service for changes to take effect.

3. Disabling Plugin

Command Description Notes
rabbitmq-plugins disable Disables a specific plugin Plugin must be installed and currently enabled

Example: Disabling a Plugin

rabbitmq-plugins disable rabbitmq_management
Note: Disabling a plugin does not remove it from the installation. It only prevents the plugin from being loaded at startup.

4. Understanding Plugin Dependencies

Dependency Type Description Example
Erlang Application Core Erlang modules required for plugin functionality ranch, ssl
RabbitMQ Core Feature Features provided by RabbitMQ core that plugins may rely on amqp_client, rabbit_common
External Library Third-party libraries used by plugins (e.g., for parsing or encoding) jiffy (JSON parser), cowboy (HTTP server)
Note: Plugin dependencies are declared in the plugin's app.src file using the applications or included_applications attributes.

Example: Plugin app.src dependency declaration

{application, rabbitmq_management,
 [
  {description, "RabbitMQ Management Plugin"},
  {vsn, "3.12.0"},
  {registered, []},
  {applications, [
   kernel,
   stdlib,
   ranch,
   ssl,
   amqp_client
  ]},
  {included_applications, [rabbit_common]},
  {mod, {rabbit_management_app, []}},
  {env, [{http_port, 15672}]}
 ]}.

Dependency Resolution Process

  • RabbitMQ loads plugins in dependency order
  • Plugins with missing dependencies will not start
  • Dependencies are resolved at runtime, not compile time
  • Use rabbitmq-plugins list to inspect loaded plugins and their dependencies

5. Using Management Plugin

Command Description Notes
rabbitmq-plugins enable rabbitmq_management Enables the management plugin Required for web UI access
rabbitmq-plugins disable rabbitmq_management Disables the management plugin Stops web UI access

Example: Enabling Management Plugin

rabbitmq-plugins enable rabbitmq_management

Example: Accessing Management UI

http://localhost:15672
Note: Default credentials are guest/guest
Warning: Disable or change default credentials in production
Feature Status Description
Web UI NEW Provides real-time monitoring and management
API Access NEW REST API for plugin management

6. Using Federation Plugin

The Federation plugin in RabbitMQ allows you to create federated exchanges and queues that span multiple nodes or clusters. It enables the creation of a distributed messaging topology by replicating messages across different RabbitMQ instances.

Configuration Property Description Default Value Notes
federation.plugin Enables or disables the federation plugin true Must be enabled to use federation features
federation.max-hops Maximum number of hops for federated messages 1 Prevents infinite loops in federation chains

Example: Configuring Federation Exchange

{
  "federation": {
    "exchanges": [
      {
        "name": "federated-exchange",
        "upstream": {
          "uri": "amqp://user:pass@remote-server:5672/vhost",
          "exchange": "source-exchange"
        }
      }
    ]
  }
}

Example: Federating a Queue

{
  "federation": {
    "queues": [
      {
        "name": "federated-queue",
        "upstream": {
          "uri": "amqp://user:pass@remote-server:5672/vhost",
          "queue": "source-queue"
        }
      }
    ]
  }
}
Note: The federation plugin requires the rabbitmq_federation and rabbitmq_federation_management modules to be enabled on both source and target RabbitMQ nodes.
Warning: Federation can introduce latency and complexity in distributed systems. Ensure proper monitoring and error handling for federated exchanges and queues.

7. Using Shovel Plugin

The Shovel plugin in RabbitMQ is a powerful tool for transferring messages between different RabbitMQ brokers or between a broker and a non-RabbitMQ message broker. It is particularly useful for scenarios such as:

  • Replicating messages across different RabbitMQ clusters
  • Migrating from one broker to another
  • Integrating with systems that do not use RabbitMQ

Example: Configuring a Shovel

{
  "shovel": {
    "source": {
      "uri": "amqp://source-broker",
      "queue": "source-queue"
    },
    "destination": {
      "uri": "amqp://destination-broker",
      "queue": "destination-queue"
    },
    "ack-mode": "on-confirm"
  }
}
Property Description Default Value
source.uri URI of the source broker None
source.queue Queue name to consume from None
destination.uri URI of the destination broker None
destination.queue Queue name to publish to None
ack-mode Message acknowledgment mode on-confirm
Note: The Shovel plugin must be enabled on both source and destination brokers to function correctly.
Warning: Ensure that the URIs and queue names are correctly configured to avoid message loss or duplication.

8. Using Delayed Message Plugin

The rabbitmq_delayed_message_exchange plugin enables the use of delayed message delivery in RabbitMQ, allowing messages to be delivered at a specific time in the future.

Property Description Default Value Notes
delayed_message_exchange Exchange type for delayed messages x-delayed-message Must be used when declaring exchanges for delayed messages

Example: Declaring a Delayed Exchange

const amqp = require('amqplib');

async function declareDelayedExchange() {
  const connection = await amqp.connect('amqp://localhost');
  const channel = await connection.createChannel();

  const exchangeName = 'delayed_exchange';
  const exchangeType = 'x-delayed-message';
  const options = {
    durable: true,
    arguments: {
      'x-delayed-type': 'direct'
    }
  };

  await channel.assertExchange(exchangeName, exchangeType, options);
  console.log('Delayed exchange declared successfully');
  
  await channel.close();
  await connection.close();
}

declareDelayedExchange().catch(console.error);

Example: Publishing a Delayed Message

const amqp = require('amqplib');

async function publishDelayedMessage() {
  const connection = await amqp.connect('amqp://localhost');
  const channel = await connection.createChannel();

  const exchangeName = 'delayed_exchange';
  const routingKey = 'delayed.routing.key';
  const message = 'Hello, delayed world!';
  const delayInMs = 5000; // 5 seconds

  const messageOptions = {
    headers: {
      'x-delay': delayInMs
    }
  };

  channel.publish(exchangeName, routingKey, Buffer.from(message), messageOptions);
  console.log(`Message published with delay of ${delayInMs}ms`);

  await channel.close();
  await connection.close();
}

publishDelayedMessage().catch(console.error);
Note: The x-delay header must be an integer representing the delay in milliseconds.
Warning: Ensure that the rabbitmq_delayed_message_exchange plugin is enabled before attempting to use delayed messages.

Key Features of Delayed Message Plugin

  • Supports delayed message delivery at a specific time in the future
  • Uses x-delay header to specify delay duration in milliseconds
  • Exchange type x-delayed-message is required for delayed exchanges
  • Works with any exchange type (direct, topic, fanout, etc.) as the underlying type

9. Using Consistent Hash Exchange

The consistent hash exchange in RabbitMQ is used to distribute messages to queues based on a hash of the routing key, ensuring that messages with the same routing key are consistently routed to the same queue.

Property Description Default Value Notes
type The exchange type for consistent hash consistent-hash Must be set to consistent-hash
hash.algorithm Algorithm used for hashing md5 Can be md5, sha1, or sha256

Example: Declaring a Consistent Hash Exchange

const amqp = require('amqplib');

async function declareConsistentHashExchange() {
  const connection = await amqp.connect('amqp://localhost');
  const channel = await connection.createChannel();

  await channel.assertExchange('consistent-hash-exchange', 'consistent-hash', {
    durable: true,
    autoDelete: false
  });

  console.log('Consistent hash exchange declared');
  await channel.close();
  await connection.close();
}

declareConsistentHashExchange().catch(console.error);

Example: Publishing Messages to Consistent Hash Exchange

const amqp = require('amqplib');

async function publishToConsistentHashExchange() {
  const connection = await amqp.connect('amqp://localhost');
  const channel = await connection.createChannel();

  const exchangeName = 'consistent-hash-exchange';
  const routingKey = 'user-123';

  await channel.publish(exchangeName, routingKey, Buffer.from('Hello World'));

  console.log(`Message published with routing key: ${routingKey}`);
  await channel.close();
  await connection.close();
}

publishToConsistentHashExchange().catch(console.error);
Note: The consistent hash exchange is particularly useful in scenarios where you want to ensure that messages with the same routing key are always processed by the same consumer, such as in a sharding strategy for load balancing.

10. Using Top Plugin

Command Description Notes
rabbitmq-top Display real-time statistics for RabbitMQ nodes Part of the rabbitmq_management plugin

Example: Running rabbitmq-top

rabbitmq-top -n rabbit@localhost
Note: The rabbitmq-top command provides a real-time view of RabbitMQ node metrics, including memory usage, disk space, and queue statistics.

11. Using Tracing Plugin

Property Value Description
plugin.name rabbitmq_tracing Name of the tracing plugin
enabled true Whether the plugin is enabled
output.format json Format of trace output (JSON or XML)

Example: Enable Tracing Plugin

rabbitmq-plugins enable rabbitmq_tracing

Example: Configure Tracing Output

{
  "tracing": {
    "output": {
      "format": "json"
    }
  }
}
Note: Tracing is useful for debugging and monitoring message flows in RabbitMQ.

12. Using Recent History Exchange

The Recent History Exchange plugin in RabbitMQ provides a way to store and retrieve recent messages for a specific queue or exchange. It's particularly useful for scenarios where you need to replay or inspect recent messages.

Property Description Default Value Notes
recent_history_exchange.max_age Maximum age of messages to keep in the history 3600 seconds (1 hour) Can be specified in seconds, minutes, hours, etc.
recent_history_exchange.max_size Maximum number of messages to keep in history 1000 Messages are evicted based on age first, then size
recent_history_exchange.ttl Time To Live for messages in the exchange 3600 seconds (1 hour) Messages older than this will be removed

Example: Configuring Recent History Exchange

// Enable the recent history exchange plugin
// rabbitmq-plugins enable rabbitmq_recent_history_exchange

// Configure exchange with default settings
const config = {
  "recent_history_exchange": {
    "max_age": 3600,
    "max_size": 1000,
    "ttl": 3600
  }
};

// Apply configuration via RabbitMQ management API or config file

Example: Using Recent History Exchange in a Consumer

// Consume messages from recent history exchange
const amqp = require('amqplib');

async function consumeFromRecentHistory() {
  const connection = await amqp.connect('amqp://localhost');
  const channel = await connection.createChannel();
  
  // Bind queue to recent history exchange
  await channel.assertExchange('recent_history_exchange', 'direct');
  await channel.assertQueue('recent_history_queue');
  await channel.bindQueue('recent_history_queue', 'recent_history_exchange', '#');
  
  // Consume messages
  channel.consume('recent_history_queue', (msg) => {
    console.log('Received:', msg.content.toString());
    channel.ack(msg);
  });
}

consumeFromRecentHistory();
Note: The Recent History Exchange plugin requires the rabbitmq_recent_history_exchange to be enabled in RabbitMQ.
Warning: The exchange will keep messages in memory until they expire or are evicted based on size limits. Ensure sufficient memory is allocated for large message volumes.

Was this article helpful?