NServiceBus 버전 6 이전에는 IManageMessageFailures
을 사용하여 메시지 오류를 관리 할 수있었습니다. 첫 번째 수준의 재 시도가 시도 된 후에 메시지를 정상적으로 처리 할 수없는 경우 직렬화 예외 또는 처리중인 문제와 관련이있는 경우를 처리 할 수 있습니다.
다음은 특정 유형의 예외를 무시하거나 다른 오류가있는 오류 메시지를 오류 대기열로 다시 보내는 맞춤 FaultManager
을 구현하는 방법입니다. 1 단계 퇴역은 여전히 발생하며 2 단계 재 시도가 아니라 1 단계 퇴역이 계속 발생합니다.
public class IssueOrder : ICommand
{
public bool NotFound { get; set; }
public bool HasFaulted { get; set; }
}
public class OrderHandler : IHandleMessages<IssueOrder>
{
public void Handle(IssueOrder message)
{
if(message.NotFound)
throw new OrderNotFoundException();
if(message.HasFaulted)
throw new ApplicationException();
}
}
public class OrderNotFoundException : Exception
{
}
public class CustomFaultManager : IManageMessageFailures
{
private ISendMessages sender;
private MessageForwardingInCaseOfFaultConfig config;
private BusNotifications notifications;
private static ILog Logger = LogManager.GetLogger<CustomFaultManager>();
public CustomFaultManager(ISendMessages sender, IProvideConfiguration<MessageForwardingInCaseOfFaultConfig> config)
{
this.sender = sender;
this.config = config.GetConfiguration();
}
public void SerializationFailedForMessage(TransportMessage message, Exception e)
{
}
public void ProcessingAlwaysFailsForMessage(TransportMessage message, Exception e)
{
if (e is OrderNotFoundException)
{
//Ignore the exception;
Logger.WarnFormat("OrderNotFoundException was thrown. Ignoring the message Id {0}.", message.Id);
}
else
{
//Check if you have performed enough retries, ultimately send to error queue
SendToErrorQueue(message, e);
}
}
private void SendToErrorQueue(TransportMessage message, Exception ex)
{
message.TimeToBeReceived = TimeSpan.MaxValue;
sender.Send(message, new SendOptions(config.ErrorQueue));
Logger.WarnFormat("Message {0} will was moved to the error queue.", message.Id);
}
public void Init(Address address)
{
}
}
그리고 사용자 정의 FaultManager를 등록 :
var config = new BusConfiguration();
//Other configuration code
config.RegisterComponents(c =>
{
c.ConfigureComponent<CustomFaultManager>(DependencyLifecycle.InstancePerCall);
});
는 그러나 NServiceBus의 버전 6에서 IManageMessageFailures
인터페이스가 지원되지 않습니다. 버전 번호 6의 새로운 Recoverability api을 사용하면 예외를 무시/무시할 수있는 직접적인 방법이 없으므로 더 나은 맞춤 설정이 가능합니다. 이를 위해 NServiceBU pipeline에 사용자 지정 동작이 필요하며 알려진 단계 중 하나 (예 : 메시지가 오류 큐로 이동되기 전에) 사이의 단계에서이를 실행해야합니다.
좀 더 자세히 설명해 주시겠습니까? 우리는 Nsb 5를 사용하며 모든 경우를 구현할 수있는 방법이 보이지 않습니다. 1) 메시지 숨기기 2) 일반 SLR 3) IMRageResponse에 대한 SLR 없음. "이 확장 기능을 활성화하면 두 번째 수준의 재시도가 호출되지 않습니다"라고 표시됩니다. 둘째로 어떤 핸들러가 "메시지가 에러 큐로 옮겨지기 전에"이벤트를 처리 할 수있는 핸들러를 보지 못했습니다. 단지'SerializationFailedForMessage'와'ProcessingAlwaysFailsForMessage' 만 있습니다. – YMC
커스텀 폴트 매니저 구현 방법을 보여주는 더 나은 샘플을 만들었습니다. 나와 함께 견뎌주십시오. –
@YMC 코드가 적합한 지 확인하십시오. 또한 NSB docs 웹 사이트에서 v5 샘플을 업데이트 할 것입니다. –