-
-
Save phatboyg/1052738 to your computer and use it in GitHub Desktop.
MassTransit 2.0 beta questions (updated to allow run from different machines)
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using MassTransit; | |
using MassTransitExperimentShared; | |
using System.Threading; | |
namespace MassTransitConsumer | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int responseNumber = 0; | |
Bus.Initialize(sbc => | |
{ | |
sbc.UseMsmq(); | |
sbc.VerifyMsmqConfiguration(); | |
sbc.UseMulticastSubscriptionClient(x => x.SetNetworkKey("MyNetwork")); | |
sbc.ReceiveFrom("msmq://localhost/test_queue_receive"); | |
sbc.Subscribe(subs => | |
{ | |
subs.Handler<MyRequest>(msg => | |
{ | |
Console.WriteLine(msg.Text); | |
Bus.Instance.MessageContext<MyRequest>().Respond(new MyResponse() { Counter = Interlocked.Increment(ref responseNumber) }); | |
} | |
}); | |
}); | |
}); | |
Console.ReadLine(); | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using MassTransit; | |
using MassTransitExperimentShared; | |
using System.Threading; | |
namespace MassTransitExperiment | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Bus.Initialize(sbc=> | |
{ | |
sbc.UseMsmq(); | |
sbc.VerifyMsmqConfiguration(); | |
sbc.UseMulticastSubscriptionClient(x => x.SetNetworkKey("MyNetwork")); | |
sbc.ReceiveFrom("msmq://localhost/test_queue"); | |
sbc.Subscribe(subs => | |
{ | |
subs.Handler<MyResponse>(msg => Console.WriteLine("Response: " + msg.Counter)); | |
}); | |
}); | |
for (int i = 0; i < 150; i++) | |
{ | |
Console.WriteLine("Queuing message #{0}", i); | |
Bus.Instance.Publish<MyRequest>(new MyRequest { Text = "Hi " + i }, context => | |
{ | |
context.SendResponseTo(Bus.Instance); | |
}); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
In Beta 3, there is a bug with the Handler() registration that does not properly set the MessageContext<> for the thread, causing it to throw an exception (which you can see in the log if enabled). I've fixed this in the /develop branch. I'm working on a few more fixed before releasing a beta 4 release next week.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI: Typo at Line 29 of MassTransitConsumer