Browse Source
Merge pull request #12670 from abpframework/liangshiwei/rebus
Rebus: Fix the problem of calling Handler multiple times
pull/12671/head
maliming
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
14 additions and
4 deletions
-
framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventHandlerStep.cs
-
framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/IRebusDistributedEventHandlerAdapter.cs
-
framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventHandlerAdapter.cs
|
|
@ -1,4 +1,5 @@ |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Rebus.Messages; |
|
|
using Rebus.Messages; |
|
|
@ -14,9 +15,12 @@ public class AbpRebusEventHandlerStep : IIncomingStep |
|
|
var message = context.Load<Message>(); |
|
|
var message = context.Load<Message>(); |
|
|
var handlerInvokers = context.Load<HandlerInvokers>().ToList(); |
|
|
var handlerInvokers = context.Load<HandlerInvokers>().ToList(); |
|
|
|
|
|
|
|
|
handlerInvokers.RemoveAll(x => x.Handler.GetType() == typeof(RebusDistributedEventHandlerAdapter<object>)); |
|
|
if (handlerInvokers.All(x => x.Handler is IRebusDistributedEventHandlerAdapter)) |
|
|
context.Save(new HandlerInvokers(message, handlerInvokers)); |
|
|
{ |
|
|
|
|
|
handlerInvokers = new List<HandlerInvoker> {handlerInvokers.Last()}; |
|
|
|
|
|
context.Save(new HandlerInvokers(message, handlerInvokers)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return next(); |
|
|
return next(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
@ -0,0 +1,6 @@ |
|
|
|
|
|
namespace Volo.Abp.EventBus.Rebus; |
|
|
|
|
|
|
|
|
|
|
|
public interface IRebusDistributedEventHandlerAdapter |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
@ -3,7 +3,7 @@ using Rebus.Handlers; |
|
|
|
|
|
|
|
|
namespace Volo.Abp.EventBus.Rebus; |
|
|
namespace Volo.Abp.EventBus.Rebus; |
|
|
|
|
|
|
|
|
public class RebusDistributedEventHandlerAdapter<TEventData> : IHandleMessages<TEventData> |
|
|
public class RebusDistributedEventHandlerAdapter<TEventData> : IHandleMessages<TEventData> , IRebusDistributedEventHandlerAdapter |
|
|
{ |
|
|
{ |
|
|
protected RebusDistributedEventBus RebusDistributedEventBus { get; } |
|
|
protected RebusDistributedEventBus RebusDistributedEventBus { get; } |
|
|
|
|
|
|
|
|
|