Skip to content

Instantly share code, notes, and snippets.

@hiyosi
Created November 6, 2011 13:11
Show Gist options
  • Save hiyosi/1342856 to your computer and use it in GitHub Desktop.
Save hiyosi/1342856 to your computer and use it in GitHub Desktop.
amap_example
-module(amqp_example).
-include("./deps/amqp_client-2.6.1/include/amqp_client.hrl").
-compile([export_all]).
test() ->
{ok, Connection} = amqp_connection:start(#amqp_params_network{}),
{ok, Channel} = amqp_connection:open_channel(Connection),
#'queue.declare_ok'{queue = Q}
= amqp_channel:call(Channel, #'queue.declare'{}),
Payload = <<"foobar">>,
Publish = #'basic.publish'{exchange = <<>>, routing_key = Q},
amqp_channel:cast(Channel, Publish, #amqp_msg{payload = Payload}),
Get = #'basic.get'{queue = Q},
{#'basic.get_ok'{delivery_tag = Tag}, Content} = amqp_channel:call(Channel, Get),
amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}),
amqp_channel:close(Channel),
amqp_connection:close(Connection),
ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment