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)
-
0
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.
-
0
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*Eto
s and use theSaveChanges()
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.
-
0
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(....); } }
-
0
The approach in the link seems promising, we will get it a try.
-
0
ok