How to respond from a consumer?

75 views
Skip to first unread message

George Mauer

unread,
Aug 13, 2015, 9:45:12 PM8/13/15
to masstransit-discuss
On the Request/Respond page in the documentation it shows a response like this

Bus.Initialize(sbc => {
   sbc
.UseMsmq();
   sbc
.UseMulticastSubscriptionClient();
   sbc
.ReceiveFrom("msmq://localhost/message_responder");
   sbc
.Subscribe(subs=> {
     subs
.Handler<BasicRequest>( (cxt, msg )=> {
       cxt
.Respond(new BasicResponse{Text = "RESP"+msg.Text});
     
});
   
});
})
In my application I'm using Consumers rather than Handlers (because I need dependency injection via Autofac) so my consumer looks like this
public class DoctorImporter : Consumes<ImportDoctorCommand>.For<Guid>
{
public void Consume(ImportDoctorCommand cmd) {
                                foo.DoStuff();
var ev = new ImportDoctorCommand.Occurred() { CorrelationId = cmd.CorrelationId };
              bus.Publish(ev);
}
              readonly IServiceBus bus;
                        readonly Foo foo;
public DoctorImporter(IServiceBus bus, Foo foo) {
this.bus = bus;
                                this.foo = foo;
}
public Guid CorrelationId { get; private set; }
}

but this doesn't work because it seems like I need `.Respond()` rather than `.Publish()` and there's no `.Respond()` on `IServiceBus`.

So how do I do request/response from a consumer? 

Dru Sellers

unread,
Aug 16, 2015, 11:52:10 AM8/16/15
to masstrans...@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.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/02cf2474-f7c5-4a14-833b-b1aadda52899%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages