Skip to content

Commit

Permalink
Take advantage of the sensible defaults for command records.
Browse files Browse the repository at this point in the history
Per Ben Hood, The codegen module creates sensible defaults for the command
records, so unless you need to override an attribute, you can make
your record definitions more concise;
  • Loading branch information
grempe committed Feb 26, 2010
1 parent d8d2fdd commit 6ab8898
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/stocks_example.erl
Expand Up @@ -20,27 +20,20 @@ amqp_lifecycle() ->
X = <<"stocks">>,
BindKey = <<"#">>,

QueueDeclare = #'queue.declare'{queue = Q,
passive = false, durable = false,
exclusive = false, auto_delete = false,
nowait = false, arguments = []},
QueueDeclare = #'queue.declare'{queue = Q},
#'queue.declare_ok'{queue = Q,
message_count = MessageCount,
consumer_count = ConsumerCount}
= amqp_channel:call(Channel, QueueDeclare),
log(message_count,MessageCount),
log(consumer_count,ConsumerCount),

ExchangeDeclare = #'exchange.declare'{exchange = X, type = <<"topic">>,
passive = false, durable = false,
auto_delete = false, internal = false,
nowait = false, arguments = []},
ExchangeDeclare = #'exchange.declare'{exchange = X, type = <<"topic">>},
#'exchange.declare_ok'{} = amqp_channel:call(Channel, ExchangeDeclare),

QueueBind = #'queue.bind'{queue = Q,
exchange = X,
routing_key = BindKey,
nowait = false, arguments = []},
routing_key = BindKey},
#'queue.bind_ok'{} = amqp_channel:call(Channel, QueueBind),

%% Inject a sample message so we have something to consume later on. For testing purposes only.
Expand All @@ -56,8 +49,7 @@ amqp_lifecycle() ->

%% After you've finished with the channel and connection you should close them down
log(channel_close,"start"),
ChannelClose = #'channel.close'{reply_code = 200, reply_text = <<"Goodbye">>,
class_id = 0, method_id = 0},
ChannelClose = #'channel.close'{reply_code = 200, class_id = 0, method_id = 0},
#'channel.close_ok'{} = amqp_channel:call(Channel, ChannelClose),

log(connection_close,"start"),
Expand All @@ -67,10 +59,7 @@ amqp_lifecycle() ->

send_message(Channel, X, RoutingKey, Payload) ->
log(send_message,"basic.publish setup"),
BasicPublish = #'basic.publish'{exchange = X,
routing_key = RoutingKey,
mandatory = false,
immediate = false},
BasicPublish = #'basic.publish'{exchange = X, routing_key = RoutingKey},

log(send_message,"amqp_channel:cast"),
ok = amqp_channel:cast(Channel, BasicPublish, _MsgPayload = #amqp_msg{payload = Payload}).
Expand All @@ -81,10 +70,7 @@ setup_consumer(Channel, Q) ->
log(setup_consumer,"basic.consume"),
BasicConsume = #'basic.consume'{queue = Q,
consumer_tag = <<"">>,
no_local = false,
no_ack = true,
exclusive = false,
nowait = false},
no_ack = true},
#'basic.consume_ok'{consumer_tag = ConsumerTag}
= amqp_channel:subscribe(Channel, BasicConsume, self()),

Expand All @@ -103,8 +89,7 @@ setup_consumer(Channel, Q) ->

%% After the consumer is finished interacting with the queue, it can deregister itself
log(basic_cancel,"start"),
BasicCancel = #'basic.cancel'{consumer_tag = ConsumerTag,
nowait = false},
BasicCancel = #'basic.cancel'{consumer_tag = ConsumerTag},
#'basic.cancel_ok'{consumer_tag = ConsumerTag} = amqp_channel:call(Channel,BasicCancel).

read_messages(Timeouts) ->
Expand Down

0 comments on commit 6ab8898

Please sign in to comment.