Multiple receive endpoints with autofac?

已查看 1,160 次
跳至第一个未读帖子

Scott Vickers

未读,
2015年12月7日 14:29:302015/12/7
收件人 masstransit-discuss
Trying to get autofac working with mt3 based on the docs but can't wrap my head around how to have multiple receive endpoints registered without creating multiple buses.

Current configuration without autofac:
_bus = Bus.Factory.CreateUsingAzureServiceBus(x =>
{
    var host = x.Host(...);

    x.ReceiveEndpoint("orders", e =>{
        e.Consumer<AddOrderConsumer>();
        e.Consumer<SendOrderReceipt>();
    });

    x.ReceiveEndpoint("users", e =>
    {
        e.Consumer<AddAccountConsumer>();
        e.Consumer<SendWelcomeEmail>();
    });
});


with autofac:
var builder = new ContainerBuilder();
builder.RegisterType<AddOrderConsumer>();
builder.RegisterType<SendOrderReceipt>();
builder.RegisterType<AddAccountConsumer>();
builder.RegisterType<SendWelcomeEmail>();
builder.Register(context =>
{
    return Bus.Factory.CreateUsingAzureServiceBus(cfg =>
    {

        var host = cfg.Host(...);

        cfg.ReceiveEndpoint("orders", ec =>
        {
            ec.LoadFrom(context);
        });

        cfg.ReceiveEndpoint("users", ec =>
        {
            // uhhhh
        });
    });
})
    .SingleInstance()
    .As<IBusControl>()
    .As<IBus>();

Where am I going wrong?

Chris Patterson

未读,
2015年12月7日 14:31:502015/12/7
收件人 masstrans...@googlegroups.com
For this case, you should create a lifetime scope for each receive endpoint with the consumers for that endpoint.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/c3edae61-1c18-4d6a-a0d1-cbe7097c5028%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Vickers

未读,
2015年12月7日 14:59:522015/12/7
收件人 masstransit-discuss
Know of any examples around, haven't had much luck searching.  I can create different scopes in autofac but totally failing figuring out what to do differently with: ec.LoadFrom(context);
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

Chris Patterson

未读,
2015年12月7日 17:26:282015/12/7
收件人 masstrans...@googlegroups.com
You can also just use the extensions for the consumers you want:

cfg.ReceiveEndpoint("orders", ec => ec.Consumer<AddOrderConsumer>(context));

That might not work in your situation without using context.Resolve<ILifetimeScope>().

Scott Vickers

未读,
2015年12月7日 23:02:382015/12/7
收件人 masstransit-discuss
I got it to work but it doesn't look so pretty, and is a pain to do for each consumer.

var builder = new ContainerBuilder();
builder
.RegisterType<AddOrderConsumer>();
builder.RegisterType<SendOrderReceipt>();
builder.RegisterType<AddAccountConsumer>();
builder.RegisterType<SendWelcomeEmail>();
builder.Register(context =>
{
   return Bus.Factory.CreateUsingAzureServiceBus(cfg =>
   {

        var host = cfg.Host(...);

        cfg.ReceiveEndpoint("orders", ec =>
       {
            ec
.Consumer<AddOrderConsumer>(context.Resolve<ILifetimeScope>());
            ec.Consumer<SendOrderReceipt>(context.Resolve<ILifetimeScope>());
        });

        cfg.ReceiveEndpoint("users", ec =>
       {
           ec.Consumer<AddAccountConsumer>(context.Resolve<ILifetimeScope>());
            ec
.Consumer<SendWelcomeEmail>(context.Resolve<ILifetimeScope>());
        });
   });
})
   .SingleInstance()
   .As<IBusControl>()
   .As<IBus>();
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

Sadprofessor

未读,
2015年12月8日 09:55:132015/12/8
收件人 masstransit-discuss

This is how we have it with autofac:

var autofacBuilder = new ContainerBuilder();

ILifetimeScope customerOrdersScope;
ILifetimeScope someOtherScope;

builder.Register(af =>
    Bus.Factory.CreateUsingRabbitMq(x =>
    {
        var host = x.Host(broker, h =>
        {
            h.Username(rabbitUser);
            h.Password(rabbitPass);
        });

        x.UseNLog();
        x.UseJsonSerializer();

        x.ReceiveEndpoint(ordersQueue, r =>
        {
            r.LoadFrom(customerOrdersScope);
        });

        x.ReceiveEndpoint(otherQueue, r =>
        {
            r.LoadFrom(someOtherScope);
        });      
    })

    ).As<IBusControl>().As<IBus>().SingleInstance();


var container = autofacBuilder.Build();

customerOrdersScope = container.BeginLifetimeScope(c =>
{
c.RegisterModule(new OrdersModule());
});

someOtherScope = container.BeginLifetimeScope(c =>
{
c.RegisterModule(new SomeOtherModule());
});




Scott Vickers

未读,
2015年12月8日 17:57:282015/12/8
收件人 masstransit-discuss
I tried something similar but build wont work because customerOrdersScope and someOtherScope are undefined when they are used.  I can't figure out how to create lifetime scopes without access to the container, and I can't get the container until builder.Build(), which of course is too late because I need the scopes within builder.Register().

Jeff Smith

未读,
2016年2月16日 08:39:142016/2/16
收件人 masstransit-discuss
I'm in the same boat.  Is there a complete example somewhere?

Peter Davis

未读,
2016年2月16日 18:10:252016/2/16
收件人 masstransit-discuss
The MassTransit.Host.exe project creates a scope for an Assembly that contains a IServiceSpecification implementation, and then any IEndpointSpecification that are also in that assembly are used to configure any endpoints for that scope / Assembly.

You should be able to find everything you need in the MassTransit.Host project.

Or use MassTransit.Host run your service ;) 

Just need paste this into your project to get a dll to run using MassTransit.Host https://github.com/MassTransit/MassTransit/issues/358

Peter Davis

未读,
2016年2月16日 18:13:242016/2/16
收件人 masstransit-discuss
Forgot to mention that there is a sample using MassTransit.Host in the MassTransit code currently at src\RapidTransit\RapidTransit.Sample

Chris Patterson

未读,
2016年2月16日 18:40:462016/2/16
收件人 masstrans...@googlegroups.com
Good call out Peter, there are definitely some Autofac gymnastics happening in the Host!


To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

ryan....@royaljay.net

未读,
2016年8月30日 16:27:472016/8/30
收件人 masstransit-discuss
I was wondering what you guys ended up doing to get multiple receive endpoints working, I have taken a peek in the MassTransit.Host project, and there is definitely some gymnastics going on there. Any concrete implementations?
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

Wayne Brantley

未读,
2016年10月26日 12:50:532016/10/26
收件人 masstransit-discuss
This has always been a problem for me from the beginning.

1)  Using auto registration of consumers means they are all defined in the container.  builder.RegisterConsumers(_assemblies);
2)  Using LoadFrom(context) is great...but there is only one context in the application, so it means every consumer is registered for that queue.
3)  What I ended up doing was manually setting up each consumer under the appropriate queue.
4)  Having multiple lifetime scopes like is shown is problematic as you have to manage those...and you have to manually registered your consumers on those...so might as well do it in the endpoint...

One doable solution I can think of is to modify the LoadFrom extension with something like this:

Create an attribute called EndpointName.  This would be put on each consumer class like this:
  [EndpointName("SomeEndpoint")]

Then the ep.LoadFrom(context, "SomeEndpoint") would be used.
This LoadFrom would filter out what was registered based on this attribute (easily doable).

That would take care of it.

An enhancement from Chris would be able to get the name of the endpoint from the IReceiveEndpointConfigurator so you could just do ep.LoadFromByEndpoint(context) and not have to have the queue name twice...but not a show stopper either way.

Thoughts anyone?

Alexey Zimarev

未读,
2016年10月26日 13:40:052016/10/26
收件人 masstransit-discuss
After watching Greg Young's "Eight lines of code" I am seriously considering getting rid of the container and using function composition. This is especially attractive because I believe MassTransit is also build this way, using pipelines.

Chris Patterson

未读,
2016年10月26日 13:57:182016/10/26
收件人 masstrans...@googlegroups.com
The MassTransit Host is definitely moving in the direction of making it easier to do this type of thing, and it will get some enhancements. The container support is jank, it assumes small isolated services and it turns out that people are still building monoliths with a giant single container. The nested scope option is great, and is the approach the MassTransit Host uses - I just need to make the discovery a little smarter. Group by namespace, etc. so that multiple endpoints are easy to create within the same assembly.

And yes, MT is all about functional composition versus container use :)


On Wed, Oct 26, 2016 at 10:40 AM, Alexey Zimarev <azim...@gmail.com> wrote:
After watching Greg Young's "Eight lines of code" I am seriously considering getting rid of the container and using function composition. This is especially attractive because I believe MassTransit is also build this way, using pipelines.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

Travis Smith

未读,
2016年10月26日 13:58:162016/10/26
收件人 masstransit-discuss
I might have a shared assembly of messages but each service only has the consumers of concern in it's assembly set.

Also, I could use sub containers for each service if I needed them all in shared assemblies.
On Wed, Oct 26, 2016 at 10:40 AM Alexey Zimarev <azim...@gmail.com> wrote:
After watching Greg Young's "Eight lines of code" I am seriously considering getting rid of the container and using function composition. This is especially attractive because I believe MassTransit is also build this way, using pipelines.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
-Travis

Wayne Brantley

未读,
2016年11月3日 17:41:312016/11/3
收件人 masstransit-discuss
I am deploying windows services, where each service handles consuming several messages - maybe 5 or 10 different messages.
Those messages may need to be consumed at different queues, but not sure that qualifies as monolith with a giant single container?
I do have only one container, but I would have to have one container per queue?  And then I could not autoregister those consumers, but would have to hand register - so I might as well hand register the end points.

I do like your way of grouping - like namespace, not sure I like namespace specifically, but grouping yes.   That is essentially what I presented above was a way to use an attribute to group the services by queue so they could be registered.

Really looking forward to what you come up with for MassTransit Host.   Thanks for your great project, we love it.


On Wednesday, October 26, 2016 at 1:57:18 PM UTC-4, Chris Patterson wrote:
The MassTransit Host is definitely moving in the direction of making it easier to do this type of thing, and it will get some enhancements. The container support is jank, it assumes small isolated services and it turns out that people are still building monoliths with a giant single container. The nested scope option is great, and is the approach the MassTransit Host uses - I just need to make the discovery a little smarter. Group by namespace, etc. so that multiple endpoints are easy to create within the same assembly.

And yes, MT is all about functional composition versus container use :)

On Wed, Oct 26, 2016 at 10:40 AM, Alexey Zimarev <azim...@gmail.com> wrote:
After watching Greg Young's "Eight lines of code" I am seriously considering getting rid of the container and using function composition. This is especially attractive because I believe MassTransit is also build this way, using pipelines.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
回复全部
回复作者
转发
0 个新帖子