Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Forked from anonymous/SubscriptionDemo.cs
Created January 8, 2013 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tugberkugurlu/4485630 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/4485630 to your computer and use it in GitHub Desktop.
[Test]
public void Should_be_able_to_consume()
{
var autoResetEvent = new AutoResetEvent(false);
using (var channel = connection.OpenChannel())
{
channel.Declare(queue);
var settings = new ConsumerSettings(queue)
{
ConsumerTag = Guid.NewGuid().ToString()
};
var loop = new QueueingConsumerLoop();
var handlerSelector = new BasicHandlerSelector();
handlerSelector.SetHandler(message =>
{
var stringMessage = Encoding.UTF8.GetString(message.Body);
Console.Out.WriteLine("Got Message: '{0}'", stringMessage);
autoResetEvent.Set();
});
var executionPolicyBuilder = new DefaultExecutionPolicyBuilder();
var consumer = new Consumer(
loop,
handlerSelector,
executionPolicyBuilder
);
channel.StartConsuming(consumer, settings);
autoResetEvent.WaitOne(TimeSpan.FromSeconds(10));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment