Skip to content

Commit

Permalink
Fixed comments to work with Manning.
Browse files Browse the repository at this point in the history
  • Loading branch information
williamsjj committed Nov 20, 2011
1 parent 122d82a commit 42e468c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ private static void critical_notify(IBasicConsumer consumer,
IBasicProperties msg_props = evt_args.BasicProperties;
String msg_body = Encoding.ASCII.GetString(evt_args.Body);

///(ascdn.6) Decode our message from JSON
//#/(ascdn.6) Decode our message from JSON
msg_body = JsonConvert.DeserializeObject<string>(msg_body);

///(ascdn.7) Transmit e-mail to SMTP server
//#/(ascdn.7) Transmit e-mail to SMTP server
send_mail(EMAIL_RECIPS, "CRITICAL ALERT", msg_body);

Console.WriteLine("Sent alert via e-mail! Alert Text: " +
msg_body + " Recipients: " +
string.Join(",", EMAIL_RECIPS));

///(ascdn.8) Acknowledge the message
//#/(ascdn.8) Acknowledge the message
consumer.Model.BasicAck(evt_args.DeliveryTag, false);
}

Expand All @@ -70,17 +70,17 @@ private static void rate_limit_notify(IBasicConsumer consumer,
IBasicProperties msg_props = evt_args.BasicProperties;
String msg_body = Encoding.ASCII.GetString(evt_args.Body);

///(ascdn.9) Decode our message from JSON
//#/(ascdn.9) Decode our message from JSON
msg_body = JsonConvert.DeserializeObject<string>(msg_body);

///(ascdn.10) Transmit e-mail to SMTP server
//#/(ascdn.10) Transmit e-mail to SMTP server
send_mail(EMAIL_RECIPS, "RATE LIMIT ALERT!", msg_body);

Console.WriteLine("Sent alert via e-mail! Alert Text: " +
msg_body + " Recipients: " +
string.Join(",", EMAIL_RECIPS));

///(ascdn.11) Acknowledge the message
//#/(ascdn.11) Acknowledge the message
consumer.Model.BasicAck(evt_args.DeliveryTag, false);
}

Expand All @@ -96,18 +96,18 @@ public static void Main(string[] args) {
conn_factory.UserName = "alert_user";
conn_factory.Password = "alertme";

///(ascdn.1) Establish connection to broker
//#/(ascdn.1) Establish connection to broker
IConnection conn = conn_factory.CreateConnection();
IModel chan = conn.CreateModel(); ///(hwcdn.2) Obtain channel
IModel chan = conn.CreateModel(); //#/(hwcdn.2) Obtain channel

///(ascdn.2) Declare the Exchange
//#/(ascdn.2) Declare the Exchange
chan.ExchangeDeclare("alerts",
ExchangeType.Topic,
true,
false,
null);

//(ascdn.3) Build the queues and bindings for our topics
//#/(ascdn.3) Build the queues and bindings for our topics
chan.QueueDeclare("critical",
false,
false,
Expand All @@ -124,7 +124,7 @@ public static void Main(string[] args) {

chan.QueueBind("rate_limit", "alerts", "*.rate_limit");

//(ascdn.4) Make our alert processors
//#/(ascdn.4) Make our alert processors
EventingBasicConsumer
c_consumer = new EventingBasicConsumer {Model = chan};
c_consumer.Received += critical_notify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public static void Main(string[] args) {
conn_factory.UserName = "alert_user";
conn_factory.Password = "alertme";

///(aspdn.1) Establish connection to broker
//#/(aspdn.1) Establish connection to broker
IConnection conn = conn_factory.CreateConnection();
IModel chan = conn.CreateModel(); ///(hwcdn.2) Obtain channel
IModel chan = conn.CreateModel(); //#/(hwcdn.2) Obtain channel

///(aspdn.2) Publish alert message to broker
//#/(aspdn.2) Publish alert message to broker
string msg = JsonConvert.SerializeObject(args[2]);
IBasicProperties msg_props = chan.CreateBasicProperties();
msg_props.ContentType = "application/json";
Expand Down
20 changes: 10 additions & 10 deletions csharp/appendix-a/HelloWorldConsumer/hello_world_consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,44 @@ public static void Main(string[] args) {
conn_factory.UserName = "guest";
conn_factory.Password = "guest";

///(hwcdn.1) Establish connection to broker
//#/(hwcdn.1) Establish connection to broker
IConnection conn = conn_factory.CreateConnection();
IModel chan = conn.CreateModel(); ///(hwcdn.2) Obtain channel
IModel chan = conn.CreateModel(); //#/(hwcdn.2) Obtain channel

//(hwcdn.3) Declare the exchange
//#/(hwcdn.3) Declare the exchange
chan.ExchangeDeclare("hello-exchange",
ExchangeType.Direct,
true,
false,
null);

///(hwcdn.4) Declare the queue
//#/(hwcdn.4) Declare the queue
chan.QueueDeclare("hello-queue",
false,
false,
false,
null);

///(hwcdn.5) Bind the queue and exchange together on the key "hola"
//#/(hwcdn.5) Bind the queue and exchange together on the key "hola"
chan.QueueBind("hello-queue", "hello-exchange", "hola");

///(hwcdn.6) Subscribe our consumer
//#/(hwcdn.6) Subscribe our consumer
QueueingBasicConsumer consumer = new QueueingBasicConsumer(chan);
String consumer_tag = chan.BasicConsume("hello-queue", false, consumer);

///(hwcdn.7) Start consuming
//#/(hwcdn.7) Start consuming
while(true) {
///(hwcdn.8) Process incoming messages
//#/(hwcdn.8) Process incoming messages
BasicDeliverEventArgs evt_args = (BasicDeliverEventArgs) consumer.Queue.Dequeue();
IBasicProperties msg_props = evt_args.BasicProperties;

String msg_body = Encoding.ASCII.GetString(evt_args.Body);

///(hwcdn.9) Message acknowledgement
//#/(hwcdn.9) Message acknowledgement
chan.BasicAck(evt_args.DeliveryTag, false);

if(msg_body == "quit") {
//(hwc.10) Stop consuming more messages and quit
//#/(hwc.10) Stop consuming more messages and quit
chan.BasicCancel(consumer_tag);
break;
} else
Expand Down
10 changes: 5 additions & 5 deletions csharp/appendix-a/HelloWorldProducer/hello_world_producer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ public static void Main(string[] args) {
conn_factory.UserName = "guest";
conn_factory.Password = "guest";

///(hwpdn.1) Establish connection to broker
//#/(hwpdn.1) Establish connection to broker
IConnection conn = conn_factory.CreateConnection();
IModel chan = conn.CreateModel(); ///(hwpdn.2) Obtain channel
IModel chan = conn.CreateModel(); //#/(hwpdn.2) Obtain channel

///(hwpdn.3) Declare the exchange
//#/(hwpdn.3) Declare the exchange
chan.ExchangeDeclare("hello-exchange",
ExchangeType.Direct,
true,
false,
null);

///(hwpdn.4) Create a plaintext message
//#/(hwpdn.4) Create a plaintext message
var msg_body = args[1];
IBasicProperties msg_props = chan.CreateBasicProperties();
msg_props.ContentType = "text/plain";

///(hwpdn.5) Publish the message
//#/(hwpdn.5) Publish the message
chan.BasicPublish("hello-exchange",
"hola",
msg_props,
Expand Down

0 comments on commit 42e468c

Please sign in to comment.