8000 Minor follow-ups to #60 by michaelklishin · Pull Request #61 · rabbitmq/rabbitmq-tutorials · GitHub
[go: up one dir, main page]

Skip to content

Minor follow-ups to #60 #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions dotnet/RPCClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ public RPCClient()
connection = factory.CreateConnection();
channel = connection.CreateModel();
replyQueueName = channel.QueueDeclare().QueueName;
consumer = new QueueingBasicConsumer( channel );
channel.BasicConsume( queue: replyQueueName, noAck: true, consumer: consumer );
consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(queue: replyQueueName, noAck: true, consumer: consumer);
}

public string Call( string message )
public string Call(string message)
{
var corrId = Guid.NewGuid().ToString();
var props = channel.CreateBasicProperties();
props.ReplyTo = replyQueueName;
props.CorrelationId = corrId;

var messageBytes = Encoding.UTF8.GetBytes( message );
channel.BasicPublish( exchange: "", routingKey: "rpc_queue", basicProperties: props, body: messageBytes );
var messageBytes = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "", routingKey: "rpc_queue", basicProperties: props, body: messageBytes);

while( true )
while(true)
{
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
if( ea.BasicProperties.CorrelationId == corrId )
if(ea.BasicProperties.CorrelationId == corrId)
{
return Encoding.UTF8.GetString( ea.Body );
return Encoding.UTF8.GetString(ea.Body);
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions dotnet/RPCServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ class RPCServer
public static void Main()
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using( var connection = factory.CreateConnection() )
using( var channel = connection.CreateModel() )
using(var connection = factory.CreateConnection())
using(var channel = connection.CreateModel())
{
channel.QueueDeclare( queue: "rpc_queue", durable: false, exclusive: false, autoDelete: false, arguments: null );
channel.BasicQos( 0, 1, false );
var consumer = new QueueingBasicConsumer( channel );
channel.BasicConsume( queue: "rpc_queue", noAck: false, consumer: consumer );
Console.WriteLine( " [x] Awaiting RPC requests" );
channel.QueueDeclare(queue: "rpc_queue", durable: false, exclusive: false, autoDelete: false, arguments: null);
channel.BasicQos(0, 1, false);
var consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(queue: "rpc_queue", noAck: false, consumer: consumer);
Console.WriteLine(" [x] Awaiting RPC requests");

while( true )
while(true)
{
string response = null;
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
Expand All @@ -29,21 +29,21 @@ public static void Main()

try
{
var message = Encoding.UTF8.GetString( body );
int n = int.Parse( message );
Console.WriteLine( " [.] fib({0})", message );
response = fib( n ).ToString();
var message = Encoding.UTF8.GetString(body);
int n = int.Parse(message);
Console.WriteLine(" [.] fib({0})", message);
response = fib(n).ToString();
}
catch( Exception e )
catch(Exception e)
{
Console.WriteLine( " [.] " + e.Message );
Console.WriteLine(" [.] " + e.Message);
response = "";
}
finally
{
var responseBytes = Encoding.UTF8.GetBytes( response );
channel.BasicPublish( exchange: "", routingKey: props.ReplyTo, basicProperties: replyProps, body: responseBytes );
channel.BasicAck( deliveryTag: ea.DeliveryTag, multiple: false );
var responseBytes = Encoding.UTF8.GetBytes(response);
channel.BasicPublish(exchange: "", routingKey: props.ReplyTo, basicProperties: replyProps, body: responseBytes);
channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
}
}
}
Expand All @@ -53,13 +53,13 @@ public static void Main()
/// Assumes only valid positive integer input.
/// Don't expect this one to work for big numbers, and it's probably the slowest recursive implementation possible.
/// </summary>
private static int fib( int n )
private static int fib(int n)
{
if( n == 0 || n == 1 )
if(n == 0 || n == 1)
{
return n;
}

return fib( n - 1 ) + fib( n - 2 );
return fib(n - 1) + fib(n - 2);
}
}
5 changes: 5 additions & 0 deletions dotnet/recompile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

for f in *.cs; do \
mcs -r:lib/bin/RabbitMQ.Client.dll $f; \
done
0