Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2013 17:03
Show Gist options
  • Save anonymous/4485595 to your computer and use it in GitHub Desktop.
Save anonymous/4485595 to your computer and use it in GitHub Desktop.
Subscription with the EasyNetQ V2 API
[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