Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sending commands from message handlers #11

Closed
charlessolar opened this issue Sep 30, 2016 · 2 comments
Closed

Support for sending commands from message handlers #11

charlessolar opened this issue Sep 30, 2016 · 2 comments

Comments

@charlessolar
Copy link
Owner

In NSB 6 I can't use request / response in message handlers - see Particular/NServiceBus.Callbacks#42

The "correct" way to do this from what I'm told is to setup a saga which can collect replies from normal Sends and handle timeouts / retries and such in itself.

It sounds good - and sounds like something we can include in the library so users won't have to deal with that logic themselves

@charlessolar
Copy link
Owner Author

I added a small extension IMessageHandleContext.LocalSaga to help with sending a series of commands from message handlers.

Usage is like so:

public void Handle(Commands.DoSomethingComplicated command, IMessageHandlerContext ctx) {
   var complicated = await ctx.For<Complicated>().Get(command.ComplicatedId);
   await ctx.LocalSaga(async bus => {
       var reply = await bus.Request<bool>(new Commands.StartSomething{ ComplicatedId = complicated.Id });
       complicated.Success = reply;
   });
}

awaiting ctx.LocalSaga will pause the command processing until the saga function is complete.

charlessolar added a commit that referenced this issue Mar 5, 2019
Which operates a NSB saga to perform commands in order
@charlessolar
Copy link
Owner Author

Working on the feature - syntax is going to be

var saga = ctx.Saga("blah")
.Command<Commands.Allocate>(x => {
  x.Id = "blah"
})
.Command<Commands.SetName>(x => {
  x.Id= "blah";
  x.Name = "Test";
})
.Command<Commands.Activate>(x => {
  x.Id = "blah";
})
.OnAbort<Commands.SetException>(x => {
  x.Id = "blah";
});
await saga.Start();

Under the covers we'll be running a normal NSB saga which will keep track of the commands already sent and accepted. If any command is rejected the abort commands will be run in order and the originating message will be sent to the error queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant