ruby-amqp / bunny

Bunny is a popular, easy to use, mature Ruby client for RabbitMQ
Other
1.38k stars 304 forks source link

Incorrect routing by routing key #546

Closed longhoangwkm closed 6 years ago

longhoangwkm commented 6 years ago
     [{rabbitmq_management,"RabbitMQ Management Console","3.7.4"},
      {rabbitmq_management_agent,"RabbitMQ Management Agent","3.7.4"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.7.4"},
      {cowboy,"Small, fast, modern HTTP server.","2.2.2"},
      {rabbitmq_stomp,"RabbitMQ STOMP plugin","3.7.4"},
      {rabbitmq_mqtt,"RabbitMQ MQTT Adapter","3.7.4"},
      {rabbitmq_amqp1_0,"AMQP 1.0 support for RabbitMQ","3.7.4"},
      {amqp_client,"RabbitMQ AMQP Client","3.7.4"},
      {rabbit,"RabbitMQ","3.7.4"},
      {rabbit_common,
          "Modules shared by rabbitmq-server and rabbitmq-erlang-client",
          "3.7.4"},

I followed this tutorial: http://rubybunny.info/articles/getting_started.html

Now let us take a look at a few routing keys that match the "americas.south.#" pattern:

"americas.south"
"americas.south.*brazil*"
"americas.south.*brazil.saopaulo*"
"americas.south.*chile.santiago*"
In other words, the "#" part of the pattern matches 0 or more words.

For a pattern like "americas.south.*", some matching routing keys would be:

"americas.south.*brazil*"
"americas.south.*chile*"
"americas.south.*peru*"
but not

"americas.south"
"americas.south.chile.santiago"
so "*" only matches a single word. The AMQP 0.9.1 specification says that topic segments (words) may contain the letters A-Z and a-z and digits 0-9.

I wanna check above section so i did:

require 'rubygems'
require 'bunny'

STDOUT.sync  = true

connection = Bunny.new
connection.start
channel = connection.create_channel
exchange = channel.topic("weathr", :auto_delete => true)

channel.queue("americas.south").bind(exchange, :routing_key => "americas.south.#").subscribe do |delivery_info, metadata, payload|
  puts "An update for South America: #{payload}, routing key is #{delivery_info.routing_key}"
end

exchange.publish("San Diego update", :routing_key => "americas.south")

sleep 1.0
connection.close

It ran perfectly but after that, i changed from americas.south.# to americas.south.*. And i ran again, I still display message

An update for South America: San Diego update, routing key is americas.south

I think it should not be display.

These problems was only solved after i reset Rabbitmq by brew services restart rabbitmq Is this a bug or i misunderstand somewhere, does anyone have any idea, many thanks ?!

longhoangwkm commented 6 years ago

i have just checked one more case. If i change channel.queue("americas.south") to channel.queue("americas.south2"). Message will has gone and if change name back to channel.queue("americas.south"). Message come back again

longhoangwkm commented 6 years ago

wew. i have to .unbind last routing_key before changing. This approach make me some confusing

michaelklishin commented 6 years ago

Besides binding management, # can match zero segments as well as a positive number.