Howto start using MassTransit - Publish/Subscribe

645 views
Skip to first unread message

llapinski

unread,
Sep 6, 2011, 8:23:50 AM9/6/11
to masstransit-discuss
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);
}
}




Dru Sellers

unread,
Sep 6, 2011, 11:20:16 AM9/6/11
to masstrans...@googlegroups.com

Hmm, I thought for a moment you had used both the SubscriptionService and the multicast service. But I see that was commented out.

Ah, it looks like your subscription on the subscriber side may be a bit borked. Could you by chance put the 'MyReceiver' code in a gist pls? I want to make sure I am seeing it correctly.

-d






--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-dis...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.


llapinski

unread,
Sep 6, 2011, 12:34:49 PM9/6/11
to masstransit-discuss
Hi,

sure, here is the code

https://gist.github.com/1198053

I miss something, and I cant figure it out what. Starbucs sample works
for me (so I have msmq installed and working).

Kind regards,
llapinski


On 6 Wrz, 17:20, Dru Sellers <d...@drusellers.com> wrote:
> Hmm, I thought for a moment you had used both the SubscriptionService and
> the multicast service. But I see that was commented out.
>
> Ah, it looks like your subscription on the subscriber side may be a bit
> borked. Could you by chance put the 'MyReceiver' code in a gist pls? I want
> to make sure I am seeing it correctly.
>
> -d
>
>
>
>
>
>
>
> On Tue, Sep 6, 2011 at 7:23 AM, llapinski <llapin...@gmail.com> wrote:
> > 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

Dru Sellers

unread,
Sep 6, 2011, 2:18:36 PM9/6/11
to masstrans...@googlegroups.com
MyReceiver.cs line 14


_busService.SubscribeInstance(this);

I will work on improving the docs related to the subscription api off of IServiceBus

-d

llapinski

unread,
Sep 6, 2011, 2:45:17 PM9/6/11
to masstransit-discuss
I am so happy to see it working :) Thanks.

Dru Sellers

unread,
Sep 6, 2011, 2:55:40 PM9/6/11
to masstrans...@googlegroups.com
:)

Once I get this feature tested at work, I can write the first pass on those docs up. Hopefully that will help in the future.

-d
Reply all
Reply to author
Forward
0 new messages