Created
February 23, 2012 22:45
-
-
Save phatboyg/1895517 to your computer and use it in GitHub Desktop.
Working Both Handler and Consumer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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