저는 Masstransit의 초보 사용자이며 한 지점에서 매우 심하게 갇혀 있습니다.
아래는 내 아키텍처입니다.
1) 아래 코드를 사용하여 하늘색 대기열에서 메시지를 보내는 WebApi COntroller가 있습니다.
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
try
{
if (done)
{
response = await UpdateDIPDecision(applicationNumber, systemId, decisionId, externalApplicationReference).ConfigureAwait(false);
}
}
여기서 내가하는 일은 대기열에서 메시지를 푸시 한 후 결정을 업데이트하고 응답으로 응답을 받기 위해 타사에 전화를 겁니다. 위의 코드는 EventController 클래스에 있습니다.
2) 이제 아래와 같이 DipConsumer.cs로 다른 파일에 아래와 같은 수신기가 있습니다.
public async Task Consume(ConsumeContext<DipDecision> context)
{
await _service.ServiceTheThing(context.Message.ApplicationNumber).ConfigureAwait(true);
await context.RespondAsync<IMassTransit>(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);
}
EventController에있는 내 응답 변수에서 응답으로 "Ok"가 표시 될 때만 내 소비자가 실행되기를 원합니다. 그러나 내 webapi 응답을 수신자 컨텍스트에 삽입 할 수 없습니다.
여기에 몇 가지 지침을 안내하거나 제공하십시오.
API 컨트롤러에서 응답을 기다리려면 문서에 설명 된대로 요청 클라이언트를 사용할 수 있습니다 .
본질적으로 컨트롤러는 응답을 기다린 다음 처리를 계속합니다.
public class RequestController :
Controller
{
IRequestClient<CheckOrderStatus> _client;
public RequestController(IRequestClient<CheckOrderStatus> client)
{
_client = client;
}
public async Task<ActionResult> Get(string id)
{
var response = await _client.GetResponse<OrderStatusResult>(new {OrderId = id});
// do the rest of the thing, based upon response.Ok
return View(response.Message);
}
}
위에 링크 된 문서는 컨테이너를 구성하는 방법도 보여줍니다.
대신 별도의 컨트롤러 메서드 호출을 원하는 경우 HTTP 클라이언트를 사용하여 컨트롤러 메서드를 호출하는 이벤트에 응답하는 소비자 (위에서 설명한 소비자가 Respond를 호출하는 대신 게시)를 만들 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다