Skip to content

Instantly share code, notes, and snippets.

@phatboyg
Created February 23, 2012 22:45
Show Gist options
  • Save phatboyg/1895517 to your computer and use it in GitHub Desktop.
Save phatboyg/1895517 to your computer and use it in GitHub Desktop.
Working Both Handler and Consumer
namespace ConsoleApplication12
{
using System;
using MassTransit;
class Program
{
static void Main(string[] args)
{
Bus.Initialize(sbc =>
{
sbc.UseMsmq();
sbc.VerifyMsmqConfiguration();
sbc.UseMulticastSubscriptionClient();
sbc.ReceiveFrom("msmq://localhost/test_client");
sbc.SetPurgeOnStartup(true);
sbc.Subscribe(
s =>
{
s.Handler<DiagnosticCommand>((context, msg) =>
{
Console.WriteLine("Handler Handled Message: {0}", msg.Text);
context.Respond(new DiagnosticResponse());
});
s.Instance(new CommandConsumer());
});
});
Bus.Instance.Publish(new DiagnosticCommand {Text = "Hello!"});
Console.Write("Press any key to die a horrible death...");
Console.ReadKey();
}
}
class CommandConsumer :
Consumes<DiagnosticCommand>.Context
{
public void Consume(IConsumeContext<DiagnosticCommand> context)
{
Console.WriteLine("Consumer Handled Message: {0}", context.Message.Text);
}
}
class DiagnosticResponse
{
}
class DiagnosticCommand
{
public string Text { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment