RabbitMQ:如何从Erlang客户端发送死信交换

时间:2015-06-19 12:55:57

标签: erlang queue rabbitmq message-queue dead-letter

我想从Erlang客户端发送死信交换,但尝试了几天但无法弄清楚如何通过Ruby客户端轻松发送它。

resolve()

由于

1 个答案:

答案 0 :(得分:2)

问题在于你设置参数。

以下是代码:

 %% Start a network connection
  {ok, Connection} = amqp_connection:start(#amqp_params_network{}),
  erlang:display("Connection established"),
  Ex=#'exchange.declare'{exchange    = <<"my_exchange">>,
    ticket      = 0,
    type        = <<"topic">>,
    passive     = false,
    durable     = false,
    auto_delete = false,
    internal    = false,
    nowait      = false,
    arguments   = []},

  {ok, Channel} = amqp_connection:open_channel(Connection),
  amqp_channel:call(Channel, Ex),
  erlang:display("Exchange created"),
  amqp_channel:call(Channel, #'queue.declare'{
    queue = <<"myqueue12">>,
    arguments = [{<<"x-dead-letter-exchange">>,longstr, <<"my_exchange">>}, {<<"x-dead-letter-routing-key">>,longstr, <<"task_pool1">>}, {<<"x-message-ttl">>, signedint,60000}],
    durable = true}
  ),

设置参数时,还必须指定类型(longstr, signedint)

我将队列绑定到ex "my_exchange"然后我向队列发布了一条消息:"myqueue12"并且它正常工作:

enter image description here

希望它有所帮助。