1

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

amqp_channel:call(Channel, #'queue.declare'{
  queue = QueueName,
  arguments = [{<<"x-dead-letter-exchange">>, <<"">>}, {<<"x-dead-letter-routing-key">>, <<"task_pool1">>}, {<<"x-message-ttl">>, UnhideInMinute*60000}],
  durable = true}
),
io:format("DECLARED CHANNEL.~n"),
amqp_channel:cast(Channel,
  #'basic.publish'{
    exchange = <<"">>,
    routing_key = QueueName
    },
  #amqp_msg{props = #'P_basic'{delivery_mode = 2},
  payload = JsonMsg}
)

谢谢

4

1 回答 1

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"它工作正常:

在此处输入图像描述

希望能帮助到你。

于 2015-06-22T20:59:37.810 回答