我的测试rabbitmq环境中有一个队列D4 我想使用主题交换将消息发布到D4队列 在Web管理控制台中,我将带有路由密钥K的消息绑定到队列D4 但是我的消息没有发送到D4队列 当我将主题改为直接交换时,一切正常 我的代码出了什么问题?
ExchangeName = <<"custom.topic">>,
ExchangeType = <<"topic">>,
Key = <<"K">>,
Msg = <<"123">>,
{ok, Connection} = amqp_connection:start
(#amqp_params_network{username = <<"guest">>, password = <<"guest">>, host = "192.168.1.1"}),
{ok, Channel} = amqp_connection:open_channel(Connection),
#'exchange.declare_ok'{} =
amqp_channel:call(Channel, #'exchange.declare'{exchange=ExchangeName, durable=true, type = ExchangeType}),
amqp_channel:call(Channel, #'basic.publish'{routing_key = Key}, #amqp_msg{props = #'P_basic'{delivery_mode=2}, payload = Msg}),
答案 0 :(得分:0)
我自己发现了错误。
amqp_channel:call(频道,#'basic.publish'{ exchange = ExchangeName ,routing_key = Key},#amqp_msg {props =#'P_basic'{delivery_mode = 2},payload = Msg })