Skip to content

Instantly share code, notes, and snippets.

@phatboyg
Forked from jrutley/Ping.cs
Created June 29, 2011 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phatboyg/1052738 to your computer and use it in GitHub Desktop.
Save phatboyg/1052738 to your computer and use it in GitHub Desktop.
MassTransit 2.0 beta questions (updated to allow run from different machines)
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();
}
}
}
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();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MassTransitExperimentShared
{
public class MyRequest
{
public string Text { get; set; }
}
public class MyResponse
{
public int Counter { get; set; }
}
}
@DavidChristiansen
Copy link

FYI: Typo at Line 29 of MassTransitConsumer

@phatboyg
Copy link
Author

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