0

I am new to nservice bus and am trying to learn the concepts.

I am trying to create an application which would register a customer after taking some payments from them. There are couple of third party integration in the registration process e.g. Payment and ExternalXYZ etc

I am thinking to do below steps

  1. From MVC controller call the WebAPI layer, which will send a Command for Registering a customer using NService bus e.g. BeginRegistrationProcess
  2. BeginRegistrationProcess will generate a correlation id, Create a DB entry and would start a Saga through another command e.g ProcessRegistration
  3. ProcessRegistration will do following things

    • Make A Db entry
    • Call Payment Service (through DoPayment command- this would include steps like creating DB entry, making call, handling response)
    • Call ExternalXYZ web services (through CallExternalXYZ command-similar steps as in DoPayment)

    I am thinking to create two separate commands for these 2 service calls so that they are in their own little transaction scope. These commands will log the details before and after making service call. (This might be helpful for compensation logic incase service calls fails and I need to retry them)

Here are my questions

  1. Does this sounds an ok approach?
  2. How will I handle the error scenario. for e.g say DB entry of Step 3 is done and then while making Payment, a timeout occurs (may be the card was debited and timeout occured while posting the reply or could be a network timeout). How would I ensure that card is not debited twice.
  3. Will nservicebus rollback the transaction inside the ProcessRegistration saga if error comes in the DoPayment handler
  4. what will happen to any DB calls which I make from DoPayment before calling service in case of errors.

Is there any sample which shows how to handle compensation in sagas. I am keen on creating a Compensation saga which can be initiated by ProcessRegistration, Can I utilize the log table (this table has records of each service calls before/after) to initiate the compensation?

Sarvesh
  • 269
  • 1
  • 2
  • 10

1 Answers1

0

A couple of pointers:

  • The CustomerId should be created by the Client app (web in your case) using Guids, the rest should flow using asynchronous messaging.
  • Components shouldn't be doing RPC(Remote Procedure Call), instead use pub/sub or commands

For a sample you can take a look at the sample here

Also look at some of the presentations here And Udi's blog

Also look at the Community discussion group

HTH

Sean Farmar
  • 2,254
  • 13
  • 10