1 Star 0 Fork 0

zhzhouq9/rabbitmq-tutorials

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rpc_server.exs 811 Bytes
一键复制 编辑 原始数据 按行查看 历史
Jeff Weiss 提交于 2016-01-09 06:20 +08:00 . add Elixir source for tutorial 6
defmodule FibServer do
def fib(0), do: 0
def fib(1), do: 1
def fib(n) when n > 1, do: fib(n-1) + fib(n-2)
def wait_for_messages(channel) do
receive do
{:basic_deliver, payload, meta} ->
{n, _} = Integer.parse(payload)
IO.puts " [.] fib(#{n})"
response = fib(n)
AMQP.Basic.publish(channel, "", meta.reply_to, "#{response}", correlation_id: meta.correlation_id)
AMQP.Basic.ack(channel, meta.delivery_tag)
wait_for_messages(channel)
end
end
end
{:ok, connection} = AMQP.Connection.open
{:ok, channel} = AMQP.Channel.open(connection)
AMQP.Queue.declare(channel, "rpc_queue")
AMQP.Basic.qos(channel, prefetch_count: 1)
AMQP.Basic.consume(channel, "rpc_queue")
IO.puts " [x] Awaiting RPC requests"
FibServer.wait_for_messages(channel)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/zhzhouq9/rabbitmq-tutorials.git
git@gitee.com:zhzhouq9/rabbitmq-tutorials.git
zhzhouq9
rabbitmq-tutorials
rabbitmq-tutorials
master

搜索帮助