Hi,
I try to start using MassTransit for simple scenario - two services,
one is publishing events, the other consuming. But I cant get two
simple apps to work. I can publish and receive messages on the same
process/application. But how to configure it to work between two
applications? Do I have to use RunTimeServices.exe? Do I need to
configure endpoints, I cant really find it on documentation. Its
really painful I must say. And I cant figure it out from Starbucks
sample (I dont need Sagas) and Publish/Subscribe I cant compile
(missing MassTransit.Infrastructure). And Getting Started is bit to
short ;)
http://masstransit-project.com/documentation/getting-started
What am I missing? I have publisher
public class MySender
{
private readonly Timer _timer;
private IServiceBus _bus;
private int _counter;
public MySender()
{
_timer = new Timer(3000)
{
AutoReset = true,
};
_timer.Elapsed += DoWorkOnTimerElapsed;
}
void DoWorkOnTimerElapsed(object sender, ElapsedEventArgs e)
{
Interlocked.Increment(ref _counter);
_bus.Publish(new MyMessage()
{
Id = Guid.NewGuid(),
Content = string.Format("I like MT
for the {0} time", _counter)
});
Console.WriteLine("{0} Timer elasped {1}", _counter,
e.SignalTime);
}
public void Start()
{
_bus = ServiceBusFactory.New(o =>
{
o.UseMsmq();
o.SetPurgeOnStartup(true);
o.ReceiveFrom("msmq://
localhost/mysender");
o.UseMulticastSubscriptionClient();
o.UseControlBus();
o.SetCreateMissingQueues(true);
//
o.UseSubscriptionService("msmq://localhost/my_subscriptions");
});
_timer.Start();
Console.WriteLine("Started");
}
public void Stop()
{
_timer.Stop();
_bus.Dispose();
Console.WriteLine("Stopped...");
}
}
and Consumer
public class MyReceiver : Consumes<MyMessage>.All
{
private IServiceBus _busService;
private UnsubscribeAction _unsubscribeAction;
public void Start()
{
_busService = ServiceBusFactory.New(o =>
{
o.UseMsmq();
o.SetPurgeOnStartup(true);
o.ReceiveFrom("msmq://localhost/myreceiver");
o.SetConcurrentConsumerLimit(2);
o.UseMulticastSubscriptionClient();
o.UseControlBus();
o.SetCreateMissingQueues(true);
});
_unsubscribeAction =
_busService.SubscribeConsumer<MyMessage>();
Console.WriteLine("Started receiver");
}
public void Stop()
{
_unsubscribeAction();
_busService.Dispose();
Console.WriteLine("Stopped receiver");
}
public void Consume(MyMessage message)
{
Console.WriteLine("Message {0} received {1}", message.Id,
message.Content);
}
}