【发布时间】:2019-01-19 13:31:45
【问题描述】:
我与生产者和消费者一起运行 elixir 程序。我为我的消息设置了优先级。但优先级不起作用。
我的程序:
出版商:
Basic.publish(channel, "my_exchange", "my_queue", "1", persistent: true, priority: 2)
Basic.publish(channel, "my_exchange", "my_queue", "2", persistent: true, priority: 3)
Basic.publish(channel, "my_exchange", "my_queue", "3", persistent: true, priority: 1)
Basic.publish(channel, "my_exchange", "my_queue", "4", persistent: true, priority: 0)
Basic.publish(channel, "my_exchange", "my_queue", "5", persistent: true, priority: 4)
消费者:
def init(_) do
Connection.open(Application.get_env(:app, :rabbitmq))
{:ok, channel} = Channel.open(conn)
:ok = Basic.qos(channel, prefetch_count: 1, global: true)
{:ok, _consumer_tag} = Basic.consume(channel, "my_queue", nil, arguments: [{"x-priority", :signedint, 100}])
{:ok, %{channel: channel}}
end
def handle_info({:basic_deliver, payload, %{delivery_tag: tag, priority: priority}}, %{channel: channel} = state) do
Logger.info("Received message with payload: #{payload} and priority: #{priority}")
Basic.ack(channel, tag)
{:noreply, state}
end
发布后,我运行消费者。
预期输出:
Received message with payload: 5 and priority: 4
Received message with payload: 2 and priority: 3
Received message with payload: 1 and priority: 2
Received message with payload: 3 and priority: 1
Received message with payload: 4 and priority: 0
实际输出:
Received message with payload: 1 and priority: 2
Received message with payload: 2 and priority: 3
Received message with payload: 3 and priority: 1
Received message with payload: 4 and priority: 0
Received message with payload: 5 and priority: 4
我做错了什么吗?消息的优先级不起作用吗?
【问题讨论】: