rabbitmq-server/deps/rabbitmq_random_exchange
Aitor Perez 07adc3e571
Remove Bazel files
2025-03-13 13:42:34 +00:00
..
include Created an empty include dir in order for make package to work 2011-04-27 08:37:48 +02:00
src Bump (c) line year 2025-01-01 17:54:10 -05:00
test Adapt to the current build system used by RabbitMQ plugins 2017-09-08 14:28:47 -04:00
CODE_OF_CONDUCT.md Replace files with symlinks 2022-04-15 06:04:29 -07:00
CONTRIBUTING.md Replace files with symlinks 2022-04-15 06:04:29 -07:00
LICENSE Replace @rabbitmq.com addresses with rabbitmq-core@groups.vmware.com 2023-06-20 15:40:13 +04:00
LICENSE-APACHE2 More missed license header updates #9969 2024-02-05 12:26:25 -05:00
LICENSE-MPL-RabbitMQ Revert drop of Exhibit B on MPL 2.0 2020-07-20 17:02:57 +01:00
Makefile Update Erlang.mk and switch to new xref code 2022-05-31 13:51:12 +02:00
README.md Random exchange: README.md updates 2023-04-15 14:22:30 +04:00

README.md

RabbitMQ Random Exchange Type

This exchange type is for load-balancing among consumers. It's basically a direct exchange, with the exception that, instead of each consumer bound to that exchange with the same routing key getting a copy of the message, the exchange type randomly selects a queue to route to.

There is no weighting or anything, so maybe load "balancing" might be a bit of a misnomer. It uses Erlang's crypto:rand_uniform/2 function, if you're interested.

Installation

This plugin ships with RabbitMQ. Like all other plugins, it must be enabled before it can be used:

[sudo] rabbitmq-plugins enable rabbitmq_random_exchange

Usage

To create a random, just declare an exchange providing the type "x-random".

channel.exchangeDeclare("logs", "x-random");

and bind several queues to it. Routing keys will be ignored by modern releases of this exchange plugin: the binding and its target queue (exchange) are picked entirely randomly.

Extended Example

This example uses Bunny and demonstrates how the plugin is mean to be used with 3 queues:

#!/usr/bin/env ruby

require 'bundler'
Bundler.setup(:default)
require 'bunny'

c  = Bunny.new; c.start
ch = c.create_channel

rx  = ch.exchange("x.rnd", durable: true, type: "x-random")

q1 = ch.queue("r1").bind(rx)
q2 = ch.queue("r2").bind(rx)
q3 = ch.queue("r3").bind(rx)

ch.confirm_select

100.times do
  rx.publish(rand.to_s, routing_key: rand.to_s)
end

ch.wait_for_confirms

# the consumer part is left out: see
# management UI

puts "Done"

License

See LICENSE.