LocalEventBus Performance #11581
Answered
by
realLiangshiwei
mehmetuken
asked this question in
Q&A
-
Hi, add save my entity change history logger. I add ILocalHandler but slow performance update many or insert many. Endpoint wait all event finish. Any idea perform way? Example: AppService public async Task CreateManyAsync(List<CreateUpdateProductDto> inputs)
{
await Repository.InsertManyAsync(ObjectMapper.Map<List<CreateUpdateProductDto>, List<Product>>(inputs));
} Event Handler public class ProductEventHandler : ILocalEventHandler<EntityCreatedEventData<Product>>, ITransientDependency
{
private readonly IRepository<ProductHistory> _productHistoryRepository;
public ProductEventHandler(IRepository<ProductHistory> productHistoryRepository)
{
_productHistoryRepository = productHistoryRepository;
}
[UnitOfWork]
public virtual async Task HandleEventAsync(EntityCreatedEventData<Product> eventData)
{
await _productHistoryRepository.InsertAsync(new ProductHistory
{
ProductId = eventData.Entity.Id,
StockCount = eventData.Entity.StockCount
});
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
realLiangshiwei
Feb 15, 2022
Replies: 1 comment
-
Hi, You can consider publishing batch event data. For example: var products = ObjectMapper.Map<List<CreateUpdateProductDto>, List<Product>(inputs);
await Repository.InsertManyAsync(products, autoSave : true);
await _localEventBus.PublishAsync(new ProductsEventData(products ));
public class ProductsEventData
{
public IReadOnlyList<Product> Products { get; }
public ProductsEventData(List<Product> products)
{
Products = products;
}
}
public class ProductEventHandler : ILocalEventHandler<ProductsEventData>, ITransientDependency
{
private readonly IRepository<ProductHistory> _productHistoryRepository;
public ProductEventHandler(IRepository<ProductHistory> productHistoryRepository)
{
_productHistoryRepository = productHistoryRepository;
}
[UnitOfWork]
public virtual async Task HandleEventAsync(ProductsEventData eventData)
{
//.. insertMany
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mehmetuken
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
You can consider publishing batch event data.
For example: