Отправить asyn c Task <IActionResult>от получателя отправителю в MASSTRANNSIT - PullRequest
0 голосов
/ 10 февраля 2020

Я застрял в одной точке Azure Реализация ServiceBus Queue с использованием MASSTRANSIT. Ниже приведены мой сценарий и код.

Мой отправитель находится в EventController.cs, и его код выглядит следующим образом.

    [ProducesResponseType(202)]
    [ProducesResponseType(400)]
    [ProducesResponseType(401)]
    [ProducesResponseType(404)]
    [HttpPut("{applicationNumber}/{systemId}/DipDecisionUpdated/{decisionId}")]
    public async Task<IActionResult> DipDecisionUpdated([Required]string applicationNumber, [Required]SystemEnum systemId, [Required]string decisionId, [Required][FromQuery]string externalApplicationReference)
    {
        bool done = false;
        if (!_applicationHelper.CheckApplicationAndOtherSystemReferences(applicationNumber, externalApplicationReference))
        {
            return NotFound();
        }

        if (!ModelState.IsValid)
        {
            return BadRequest();
        }

        #region MassTransit Sender for DipDecisionUpdated
        if (_dipDecisionSendersEnabled)
        {
            //If MassTransit Senders are enabled, send a "ApplicationUpgradeDecision" message to the Message Bus                
            Task<bool> downloading = SendDipDecisionMessagetoMessageBus(applicationNumber, systemId.ToString(), decisionId, externalApplicationReference);
            done = await downloading.ConfigureAwait(false);
        }
        #endregion MassTransit Sender DipDecisionUpdated
        return null;            
    }

Теперь вместо возврата Null я хочу получить здесь ответ от пользователя.

Мой потребитель такой же, как и следующий.

 /// <summary>
    /// Consume and action the incoming "DipDecision" message
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    public async Task Consume(ConsumeContext<DipDecision> context)
    {
        try
        {
            var decision = await _getDecisionRepository.GetDecision(context.Message.ApplicationNumber).ConfigureAwait(false);

            int decisionInNum = 0;
            bool result = Int32.TryParse(context.Message.DecisionId, out decisionInNum);

            if (!string.IsNullOrWhiteSpace(decision) && decision == context.Message.DecisionId && result)
            {
                MortgageApplyApplicationStatus applicationStatus;
                switch (decisionInNum)
                {
                    case (int)UnderWritersDecision.Accepted:
                        applicationStatus = MortgageApplyApplicationStatus.Accepted;
                        break;

                    case (int)UnderWritersDecision.Referred:
                        applicationStatus = MortgageApplyApplicationStatus.UnderwriterAssigned;
                        break;

                    case (int)UnderWritersDecision.Declined:
                        applicationStatus = MortgageApplyApplicationStatus.Declined;
                        break;

                    case (int)UnderWritersDecision.NoDecision:
                        applicationStatus = MortgageApplyApplicationStatus.Declined;
                        break;

                    default:
                        applicationStatus = MortgageApplyApplicationStatus.Withdrawn;
                        break;

                }

                if (context.Message.SystemId == SystemEnum.Twenty7Tec.ToString())
                    await Update27TecApplicationStatus(context.Message.ExternalApplicationReference, applicationStatus).ConfigureAwait(false);
            }
            //return null;
        }

        catch (WebException we)
        {
            var exceptionCode = we.Response as HttpWebResponse;
            if (exceptionCode != null)
            {
                switch (exceptionCode.StatusCode)
                {
                    case HttpStatusCode.Accepted:
                        return Accepted();
                    case HttpStatusCode.Forbidden:
                        return Forbid(); //StatusCode(403);
                    case HttpStatusCode.BadRequest:
                        return BadRequest();
                    default:
                        return NotFound();
                }
            }
        }
        //Consumer Start from here
        await _service.ServiceTheThing(context.Message.ApplicationNumber).ConfigureAwait(true);

        await context.RespondAsync(new
        {
            applicationNumber = $"DipDecision - Consumer Received DIP Decision for application number : {context.Message.ApplicationNumber}",
            systemId = $"DipDecision - Consumer Received DIP Decision against system : {context.Message.SystemId}",
            decisionId = $"DipDecision - Consumer Received DIP Decision against system : {context.Message.DecisionId}",
            externalApplicationReference = $"DipDecision - Consumer Received DIP Decision from external application reference number : {context.Message.ExternalApplicationReference}"
        }).ConfigureAwait(true);

    }
    //Consumer Over

Однако возвращаемые значения Accepted (), BadRequest () показывают мне ошибку, поскольку не существует в контексте.

Также, если все выглядит хорошо, я хочу выполнить потребительский код, и он должен вернуть OK () отправителю.

Мой потребительский код находится в том же проекте, но в файле DipDecisionConsumer.cs.

Пожалуйста, помогите и дайте мне знать ваши предложения.

...