- Template: microservice
- Created ABP Studio Version: 0.9.24
- Current ABP Studio Version: 0.9.25
- Multi-Tenancy: Yes
- UI Framework: angular
- Theme: leptonx
- Theme Style: system
- Run Install Libs: Yes
- Database Provider: ef
- Database Management System: sqlserver
- Mobile Framework: none
- Public Website: No
- Include Tests: Yes
- Dynamic Localization: Yes
- Kubernetes Configuration: Yes
- Grafana Dashboard: Yes
- Use Local References: No
- Optional Modules:
- GDPR
- FileManagement
- TextTemplateManagement
- AuditLogging
- Chat
- OpenIddictAdmin
- Exception message and full stack trace:
- Steps to reproduce the issue:
Hi,
I am publishing event in one microservice and listen in another. I've noticed that when I create or delete entities in the distributed event handlers the CreatorId or DeletorId record fields not added. Any ideas?
Thanks.
7 Answer(s)
-
0
Hi,
Can you send your entity contents and if you have a configuration for AbpDistributedEntityEventOptions?
-
0
-
0
Hi,
CreatorId and DeletorId are auto-filled using ICurrentUser during HTTP requests. However, in distributed event handling, events are processed asynchronously in another microservice without the original HTTP context, so ICurrentUser data isn’t available, leaving these fields null. I suggest adding CreatorId and DeletorId to the ETO object when publishing the event and then setting them in the event handler as follows:
test.CreatorId = eventData.Entity.CreatorId; test.DeleterId = eventData.Entity.DeleterId;
-
0
-
0
Hi,
Even if I'll set them manually, as you suggest, the repository Update and Delete methods will set them to null.
Yes, you are right. Instead, you can try to change the current principal, which will change the
CurrentUser
as you stated in the related scope.We have a section in our documentation for changing the current principal, which you can check out at https://abp.io/docs/latest/framework/infrastructure/current-user#changing-the-current-principal
You basically, need to inject the
ICurrentPrincipalAccessor
service, and use its Change method (which is a disposable method, so you should create a scope as stated in the documentation) and specify the CurrentUser as you wish. With this way, it should set theCreatorId
andDeleterId
.Let me know, if it fixes your problem. Regards.
-
0
Everything is working now. Thanks.
-
0
Everything is working now. Thanks.
Great to hear that. Regards.