microservicesmasstransitrouting-slipmasstransit-courier

difference of typical usage of request client and RoutingSlip courier in masstransit


I know for distributed and sequential services we are using RoutingSlip courier. imagine I have scenario which I want to have a reuquest publisher we name it as apiPublisher which wants call a dbMicro to get some data and after that call another Micro to do some stuff and then calling dbmicro to insert new data there and after all back the response to my publisher. so I'm going to create a rout and activities like that:

 private RoutingSlip CreateRoutingSlip(ConsumeContext<AccountModel> context)
            {
                var builder = new RoutingSlipBuilder(NewId.NextGuid());
                builder.AddSubscription
                    (context.ReceiveContext.InputAddress,
                        RoutingSlipEvents.Completed
                        | RoutingSlipEvents.Faulted);
                builder.AddVariable("AccountId", context.Message.AccountId);
                builder.AddVariable(nameof(context.RequestId), context.RequestId);
                builder.AddVariable(nameof(context.ResponseAddress), context.ResponseAddress);
                builder.AddVariable(nameof(context.FaultAddress), context.FaultAddress);
                builder.AddVariable("Request", context.Message);
                var dbQueueName = _formatter.
                    ExecuteActivity<SetAuthenticatedRequestWithDbActivity, AccountModel>();
    
                builder.AddActivity(nameof(SetAuthenticatedRequestWithDbActivity)
                    , new Uri($"queue:{dbQueueName}"), new
                {
                        AccountId = context.Message.AccountId,                
                });
                var apiQueueName = _formatter.ExecuteActivity<CallCampaignTpTestMicro, SpecialOfferActivePackageRequestModel>();
                builder.AddActivity("specialOffer", new Uri($"queue:{apiQueueName}"), new
                {
                    TelNum = "09195847189",
                    OfferId = "1",
                    ChoiceNo = "1",
    
                    Gateway = context.Message.Gateway,
                    HeaderNo = "1",
                    ChannelId = "1",
                });
                //next activity ...
                var dbResult = new AccountModel()
                {
                    AccountId = context.Message.AccountId,               
                };
                builder.AddVariable("Model", dbResult);
                return builder.Build();
            }

Now I want to know what is difference if I just simply call each this micro in my consumer after calling each other for example doing this:

var massResult= await _massClientRequest.GetResponse<AuthenticatePaymentResponeModel>
                (new AuthenticatePaymentRequestModel
                {
                    AccountRequest = context.Arguments.AccountRequest,
                    MyRequestedUrl = context.Arguments.MyRequestedUrl,
                    UserId = context.Arguments.UserId,                    

                });
            var res = massResult.Message;
var nextMasResult  =  await _massClientRequest.GetResponse<PaymentBankResponseModel>
               (new PaymentBankRequestModel
               {
                   BankeName = bankeName,
                   MyRequestUrl = context.Arguments.MyRequestUrl,
                   NewUrl = context.Arguments.NewUrl,
               });
 var 2ndRes= nextMasResult.Message;
if (2ndRes.IsSuccess){
var lastMasResult  =  await _massClientRequest.GetResponse<mymodel>
               (new mymodelReq
               {
                   BankeName = bankeName,
                   MyRequestUrl = context.Arguments.MyRequestUrl,
                   NewUrl = context.Arguments.NewUrl,
               });

is this scenario not working well and in order? what is the benefits of first approach.


Solution

  • The routing slip pattern is a saga (in the original sense of the paper) that offers additional features including:

    There is also a RoutingSlipRequestProxy and RoutingSlipResponseProxy which can be used to provide a standard request client entry point to a routing slip transaction. This allows the original API to use the request client to initiate the transaction and then handle the success/failure of that transaction as a result/fault combination (or result/bad-result pair).