MT3 ConnectConsumer

173 views
Skip to first unread message

Kyle Bradley

unread,
Aug 17, 2015, 5:59:09 AM8/17/15
to masstransit-discuss
Hi

I'm trying to add a consumer after the bus instance has been created. The reason being is that the consumer I create needs the IBus to be injected.

Therefore, I am trying to use the "ConnectConsumer" method on the buscontrol, but this doesn't hit the hander.

The code can be seen below. 

The commented out code e.Consumer is hit, whereas the bus.ConnectConsumer doesn't cause the handler to be hit.

I am new to MassTransit and I know that MassTransit 3 is in beta still.

Is it a configuration issue or a feature still needed to be added to masstransit 3.

Thanks
Kyle

Chris Patterson

unread,
Aug 17, 2015, 11:13:48 AM8/17/15
to masstrans...@googlegroups.com
Why would you need IBus injected, your message consume methods all get a ConsumeContext, which has all the methods on IBus you could need. I highly recommend not injecting IBus to your consumers for that very reason.


--
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/1d1ae2f5-e964-470b-bb73-da6324c5e062%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kyle Bradley

unread,
Aug 18, 2015, 3:04:27 AM8/18/15
to masstransit-discuss
The reason for this, is that the consumer is a wrapper for the command handler, which then calls an action on the aggregate that fires an event. This event is published on the bus. 

Therefore, I want to inject the IBus at the last stage rather than pass it through the different layers.

ConsumeContext doesn't seem to implement the IBus interfaces as it did before. Not sure how best to do this.

Any advice would be appreciated, thanks.


On Monday, 17 August 2015 17:13:48 UTC+2, Chris Patterson wrote:
Why would you need IBus injected, your message consume methods all get a ConsumeContext, which has all the methods on IBus you could need. I highly recommend not injecting IBus to your consumers for that very reason.

On Mon, Aug 17, 2015 at 2:59 AM, Kyle Bradley <kbrad...@gmail.com> wrote:
Hi

I'm trying to add a consumer after the bus instance has been created. The reason being is that the consumer I create needs the IBus to be injected.

Therefore, I am trying to use the "ConnectConsumer" method on the buscontrol, but this doesn't hit the hander.

The code can be seen below. 

The commented out code e.Consumer is hit, whereas the bus.ConnectConsumer doesn't cause the handler to be hit.

I am new to MassTransit and I know that MassTransit 3 is in beta still.

Is it a configuration issue or a feature still needed to be added to masstransit 3.

Thanks
Kyle

--
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.

Chris Patterson

unread,
Aug 18, 2015, 10:48:15 AM8/18/15
to masstrans...@googlegroups.com
The reason I mention that ConsumeContext should be used, is that it ensures that all asynchronous events that are published/sent as part of the message consumer are correlated (ConversationId/InitiatorId) using headers, as well as ensuring that the source address matches the input address of the receive endpoint.

Using IPublishEndpoint as a dependency (instead of IBus) is preferred, and ConsumeContext inherits IPublishEndpoint, so it can be passed to anything accepting an IPublishEndpoint.

IBus is a logical construct, and while in earlier versions of MT IServiceBus was passed around like a, it's not meant to be really used inside of a consumer since each receive endpoint on the bus has a separate context (queue name, etc.).

The other thing I can think of is that when you connect a consumer to IBus, it's only connecting to the temporary queue created by the bus, and not the receive endpoint. Receive endpoints are subscribed connections, where the consumer types are bound to the queue using the RabbitMQ exchanges. With the IBus, no exchange binding is performed and there are no subscriptions. Bindings to the temporary bus are meant for responses and other messages where the sender knows the address because it was passed with a request/etc.



On Tue, Aug 18, 2015 at 12:04 AM, Kyle Bradley <kbrad...@gmail.com> wrote:
The reason for this, is that the consumer is a wrapper for the command handler, which then calls an action on the aggregate that fires an event. This event is published on the bus. 

Therefore, I want to inject the IBus at the last stage rather than pass it through the different layers.

ConsumeContext doesn't seem to implement the IBus interfaces as it did before. Not sure how best to do this.

Any advice would be appreciated, thanks.


On Monday, 17 August 2015 17:13:48 UTC+2, Chris Patterson wrote:
Why would you need IBus injected, your message consume methods all get a ConsumeContext, which has all the methods on IBus you could need. I highly recommend not injecting IBus to your consumers for that very reason.

On Mon, Aug 17, 2015 at 2:59 AM, Kyle Bradley <kbrad...@gmail.com> wrote:
Hi

I'm trying to add a consumer after the bus instance has been created. The reason being is that the consumer I create needs the IBus to be injected.

Therefore, I am trying to use the "ConnectConsumer" method on the buscontrol, but this doesn't hit the hander.

The code can be seen below. 

The commented out code e.Consumer is hit, whereas the bus.ConnectConsumer doesn't cause the handler to be hit.

I am new to MassTransit and I know that MassTransit 3 is in beta still.

Is it a configuration issue or a feature still needed to be added to masstransit 3.

Thanks
Kyle

--
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.

--
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.
Reply all
Reply to author
Forward
0 new messages