How shite can documentation be? Just look at MassTransit. FAIL.
this link was a tiny bit useful
The following code took a few hours to form – it shouldn’t be so difficult. Why spend an age writing something that looks to be great and then offer little to no help in how to use it?
public class Model1
{
public long id { get; set; }
public string name { get; set; }
}
public class Dispatch : CorrelatedBy<Guid>
{
public Guid CorrelationId
{
get { return Guid.Parse("48931901-243F-4BC4-A693-462C45ADB1F3"); }
}
public Model1 content { get; set; }
}
public interface IHandler<TInstruction> where TInstruction : class
{
void Execute(TInstruction instruction);
}
public class DispatchHandler :
IHandler<Dispatch>
{
public void Execute(Dispatch instruction)
{
Console.WriteLine("Start {0}", instruction.content.id);
string value = instruction.content.name;
Thread.Sleep(250);
Console.WriteLine("End {0}", instruction.content.id);
}
}
private void button5_Click(object sender, EventArgs e)
{
IServiceBus bus = ServiceBusFactory.New(x =>
{
x.UseMsmq();
x.ReceiveFrom("msmq://localhost/testservice");
x.Validate();
});
for (int i = 0; i < 500000; i++)
{
lock (_locker)
{
Task.Factory.StartNew(() =>
{
_id++;
bus.GetEndpoint(new Uri("msmq://localhost/testservice")).Send(
new Dispatch()
{
content = new Model1()
{
id = _id,
name = "Joe"
}
});
});
}
}
}
public void OnStart(string[] args)
{
_bus = ServiceBusFactory.New(x =>
{
x.UseMsmq();
x.VerifyMsmqConfiguration();
x.SetConcurrentConsumerLimit(10);
x.ReceiveFrom("msmq://localhost/testservice");
x.Subscribe(subs =>
{
subs.Handler<Dispatch>(msg =>
{
var handler = _container.GetInstance<IHandler<Dispatch>>();
handler.Execute(msg);
});
});
x.Validate();
});
}