Open Closed

Decide which messages are posted to Kafka, based on entity property values or some other business logic. #5689


User avatar
0
tushar_ww created

Provide us with the following info:

  • ABP Framework version: ABP CLI 7.3.0
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): Yes
  • Exception message and full stack trace: NA
  • Steps to reproduce the issue: Probably applicable

I have enabled ABP framework to post message to Kafka using the builtin mechanism (not PublishAsync()). The message gets posted correctly. But sometimes I may want to publish the message only if say the status = "ACTIVE" or IsExpired = false. Is there any way like overriding a class method or dependency injection that I can introduce this check in the publish pipeline which will publish the message only if certain conditions are met?

I know PublishAsync() can achieve it for me, but then I will end up writing the PublishAsync() for about 95% of the entities just because I want to send the message only when status = "ACTIVE".

Let me know what additional information do you need ?


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

    Hi,

    I have enabled ABP framework to post message to Kafka using the builtin mechanism (not PublishAsync()).

    So are you manually using the Kafka API to post messages instead of EventBus?

    I may want to publish the message only if say the status = "ACTIVE" or IsExpired = false

    Can you explain in detail? thanks.

  • User Avatar
    0
    tushar_ww created

    Hi,

    So are you manually using the Kafka API to post messages instead of EventBus?

    Sorry, I was too short in my context. We have enabled Kafka using AbpEventBusKafkaModule and *Etos and use the SaveChanges() to trigger the messages. We do not (want to) use _distributedEventBus.PublishAsync(...) to explicitly fire the message.

    I may want to publish the message only if say the status = "ACTIVE" or IsExpired = false

    Can you explain in detail? thanks.

    So, in the implementation so far, when a new entity is created a message is published immediately. But maybe I do not want the message published because an entity property IsActive = false. Later sometime, IsActive = true will happen. That time the message should be published. It doesn't matter to me if the publish of the entity happens using UpdatedEvent or CreatedEvent.

    Basically, I am looking for a mechanism to filter which messages should be posted.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Sorry, but there is no such filter.

    You can do something like this: https://docs.abp.io/en/abp/latest/Distributed-Event-Bus#publishing-events-inside-entity-aggregate-root-classes

    public class MyEntity : AggregateRoot<Guid>
    {
        public bool IsActive { get; private set; }
        
        public void ChangeIsActive(bool isActive)
        {
            IsActive = isActive;
            
            AddDistributedEvent(....);
        }
    }
    
  • User Avatar
    0
    tushar_ww created

    The approach in the link seems promising, we will get it a try.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    ok

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 01, 2025, 08:37