Starts in:
1 DAY
7 HRS
19 MIN
52 SEC
Starts in:
1 D
7 H
19 M
52 S
Open Closed

Idempotent Consumer: read REBUS MessageId and other params #5032


User avatar
0
Payoff created

Version 6.x introduce Publish with option to specify MessageId, but we need to read it and other attributes to avoid potential duplicate handling. I've not found any easy way to read messageId and other parameters like rbs2-senttime, rbs2-corr-id, ... from handler am I missing something?

I want to create something on top like: https://www.milanjovanovic.tech/blog/idempotent-consumer-handling-duplicate-messages Can I have entry point to add this to out solution?

tnx mik


1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can try to custom the RebusDistributedEventBus.

    For example:

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IDistributedEventBus), typeof(RebusDistributedEventBus))]
    public class MyRebusDistributedEventBus : RebusDistributedEventBus
    {
        public MyRebusDistributedEventBus(IServiceScopeFactory serviceScopeFactory, ICurrentTenant currentTenant, IUnitOfWorkManager unitOfWorkManager, IBus rebus, IOptions<AbpDistributedEventBusOptions> abpDistributedEventBusOptions, IOptions<AbpRebusEventBusOptions> abpEventBusRebusOptions, IRebusSerializer serializer, IGuidGenerator guidGenerator, IClock clock, IEventHandlerInvoker eventHandlerInvoker) : base(serviceScopeFactory, currentTenant, unitOfWorkManager, rebus, abpDistributedEventBusOptions, abpEventBusRebusOptions, serializer, guidGenerator, clock, eventHandlerInvoker)
        {
        }
    
        public async override Task TriggerHandlersAsync(Type eventType, object eventData)
        {
            var messageId = MessageContext.Current.TransportMessage.GetMessageId();
            var sentTime = MessageContext.Current.Headers["rbs2-senttime"];
            if (....)
            {
                return;
            }
            await base.TriggerHandlersAsync(eventType, eventData);
        }
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06