问题
I am stuck at one point in Azure ServiceBus Queue implementation using MASSTRANSIT. Below is my scenario and code.
My Sender is in EventController.cs and its code is as follow's.
[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;
}
Now instead of return Null I want to get Consumer Reply here.
My consumer is as follow's.
/// <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
However return Accepted(), BadRequest() are showing me error as doesn't exist in context.
Also if all looks good I want to execute consumer code and it should return OK() to sender.
My consumer code is in same project but in DipDecisionConsumer.cs File.
Please help and let me know your suggestions.
来源:https://stackoverflow.com/questions/60151444/send-async-taskiactionresult-from-receiver-to-sender-in-masstrannsit