Skip to content

Commit fba2bc8

Browse files
Modernize a headers exchange routing example rabbitmq/rabbitmq-server#13934
1 parent f2e048c commit fba2bc8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

docs/guides/exchanges.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,8 @@ conn.start
972972
ch = conn.create_channel
973973
x = ch.headers("headers")
974974

975-
q1 = ch.queue("", :exclusive => true).bind(x, :arguments => {"os" => "linux", "cores" => 8, "x-match" => "all"})
976-
q2 = ch.queue("", :exclusive => true).bind(x, :arguments => {"os" => "osx", "cores" => 4, "x-match" => "any"})
975+
q1 = ch.queue("headers.q1.linux.8cores").bind(x, :arguments => {"os" => "linux", "cores" => 8, "x-match" => "all"})
976+
q2 = ch.queue("headers.q2.macos.any", exclusive: true).bind(x, :arguments => {"os" => "macos", "cores" => 4, "x-match" => "any"})
977977

978978
q1.subscribe do |delivery_info, properties, content|
979979
puts "#{q1.name} received #{content}"
@@ -983,7 +983,7 @@ q2.subscribe do |delivery_info, properties, content|
983983
end
984984

985985
x.publish("8 cores/Linux", :headers => {"os" => "linux", "cores" => 8})
986-
x.publish("8 cores/OS X", :headers => {"os" => "osx", "cores" => 8})
986+
x.publish("8 cores/OS X", :headers => {"os" => "macos", "cores" => 8})
987987
x.publish("4 cores/Linux", :headers => {"os" => "linux", "cores" => 4})
988988

989989
sleep 0.5
@@ -1079,18 +1079,18 @@ A quote from the project README:
10791079
> In various scenarios, you may wish to ensure that messages sent to an exchange are consistently and equally distributed across a number of different queues based on
10801080
> the routing key of the message. You could arrange for this to occur yourself by using a direct or topic exchange, binding queues to that exchange and then publishing
10811081
> messages to that exchange that match the various binding keys.
1082-
>
1082+
>
10831083
> However, arranging things this way can be problematic:
1084-
>
1084+
>
10851085
> It is difficult to ensure that all queues bound to the exchange will receive a (roughly) equal number of messages without baking in to the publishers quite a lot of
10861086
> knowledge about the number of queues and their bindings.
1087-
>
1087+
>
10881088
> If the number of queues changes, it is not easy to ensure that the new topology still distributes messages between the different queues evenly.
1089-
>
1089+
>
10901090
> Consistent Hashing is a hashing technique whereby each bucket appears at multiple points throughout the hash space, and the bucket selected is the nearest
10911091
> higher (or lower, it doesn't matter, provided it's consistent) bucket to the computed hash (and the hash space wraps around). The effect of this is that when a new
10921092
> bucket is added or an existing bucket removed, only a very few hashes change which bucket they are routed to.
1093-
>
1093+
>
10941094
> In the case of Consistent Hashing as an exchange type, the hash is calculated from the hash of the routing key of each message received. Thus messages that have
10951095
> the same routing key will have the same hash computed, and thus will be routed to the same queue, assuming no bindings have changed.
10961096

examples/guides/exchanges/headers_exchange_routing.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
ch = conn.create_channel
1414
x = ch.headers("headers")
1515

16-
q1 = ch.queue("", :exclusive => true).bind(x, :arguments => {"os" => "linux", "cores" => 8, "x-match" => "all"})
17-
q2 = ch.queue("", :exclusive => true).bind(x, :arguments => {"os" => "osx", "cores" => 4, "x-match" => "any"})
16+
q1 = ch.queue("headers.q1.linux.8cores").bind(x, :arguments => {"os" => "linux", "cores" => 8, "x-match" => "all"})
17+
q2 = ch.queue("headers.q2.macos.any", exclusive: true).bind(x, :arguments => {"os" => "macos", "cores" => 4, "x-match" => "any"})
1818

1919
q1.subscribe do |delivery_info, properties, content|
2020
puts "#{q1.name} received #{content}"
@@ -24,7 +24,7 @@
2424
end
2525

2626
x.publish("8 cores/Linux", :headers => {"os" => "linux", "cores" => 8})
27-
x.publish("8 cores/OS X", :headers => {"os" => "osx", "cores" => 8})
27+
x.publish("8 cores/OS X", :headers => {"os" => "macos", "cores" => 8})
2828
x.publish("4 cores/Linux", :headers => {"os" => "linux", "cores" => 4})
2929

3030
sleep 0.5

0 commit comments

Comments
 (0)