The ETO class:
using Volo.Abp.EventBus;
namespace MyProject.CustomerService.Customers;
[EventName("MyProject.CustomerService.Customers.CustomerUpdated")]
public class CustomerUpdatedEto
{
public Guid Id { get; set; }
public string Name { get; set; } = null!;
public string Street { get; set; } = null!;
public string ZipCode { get; set; } = null!;
public string City { get; set; } = null!;
public string PhoneNumber { get; set; } = null!;
public string Email { get; set; }
public bool IsCompany { get; set; }
public string? IdentificationNumber { get; set; }
public string? AttName { get; set; }
}
That's everything I have done in the CustomerService. In the subscriber, InvoiceService is only one added class CustomerServiceEventHandler
using MyProject.CustomerService.Customers;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
namespace MyProject.InvoiceService;
public class CustomerServiceEventHandler : IDistributedEventHandler<CustomerUpdatedEto>, ITransientDependency
{
public async Task HandleEventAsync(CustomerUpdatedEto eventData)
{
var customerId = eventData.Id;
}
}
Now, I have started the both services, CustomerService and the InvoiceService, and the RabbitMQ queues are listed by using the RabbitMQ CLI:
$ docker exec -it rabbitmq rabbitmqctl list_queues
Timeout: 60.0 seconds ...
Listing queues for vhost / ...
name messages
AbpBackgroundJobsDelayed.Volo.Abp.Emailing.BackgroundEmailSendingJobArgs 0
MyProject_AuthServer 0
MyProject_IdentityService 0
MyProject_CustomerService 0
AbpBackgroundJobs.Volo.Abp.Emailing.BackgroundEmailSendingJobArgs 0
MyProject_InvoiceService 0
So the queues seems to be registered. However, I can't see that any message is published, nor received at the subscribe. Notice that the receiver has a binding to the ETO class MyProject.CustomerService.Customers.CustomerUpdated.
$ docker exec -it rabbitmq rabbitmqctl list_bindings | grep MyProject_CustomerService
exchange MyProject_CustomerService queue MyProject_CustomerService []
MyProject exchange MyProject_CustomerService queue Volo.Abp.Localization.LanguageChangedEto []
MyProject exchange MyProject_CustomerService queue Volo.Payment.RecurringPaymentUpdated []
MyProject exchange MyProject_CustomerService queue Volo.Payment.SubscriptionCanceled []
MyProject exchange MyProject_CustomerService queue Volo.Payment.SubscriptionCreated []
MyProject exchange MyProject_CustomerService queue abp.data.apply_database_migrations []
MyProject exchange MyProject_CustomerService queue abp.multi_tenancy.tenant.connection_string.updated []
MyProject exchange MyProject_CustomerService queue abp.multi_tenancy.tenant.created []
$ docker exec -it rabbitmq rabbitmqctl list_bindings | grep MyProject_InvoiceService
exchange MyProject_InvoiceService queue MyProject_InvoiceService []
MyProject exchange MyProject_InvoiceService queue MyProject.CustomerService.Customers.CustomerUpdated []
MyProject exchange MyProject_InvoiceService queue Volo.Abp.Localization.LanguageChangedEto []
MyProject exchange MyProject_InvoiceService queue Volo.Payment.RecurringPaymentUpdated []
MyProject exchange MyProject_InvoiceService queue Volo.Payment.SubscriptionCanceled []
MyProject exchange MyProject_InvoiceService queue Volo.Payment.SubscriptionCreated []
MyProject exchange MyProject_InvoiceService queue abp.data.apply_database_migrations []
MyProject exchange MyProject_InvoiceService queue abp.multi_tenancy.tenant.connection_string.updated []
MyProject exchange MyProject_InvoiceService queue abp.multi_tenancy.tenant.created []
2 Answer(s)
-
0
Hi :-)
I have tried to follow https://abp.io/docs/latest/framework/infrastructure/event-bus/distributed
The CustomerService shall publish a message over RabbitMQ disitrbuted bus to the InvoiceService when Customer is updated.
The publisher:
public class CustomersAppService : ApplicationService, ICustomersAppService { protected IDistributedCache<CustomerDownloadTokenCacheItem, string> _downloadTokenCache; protected ICustomerRepository _customerRepository; protected CustomerManager _customerManager; protected IDistributedEventBus _eventBus; public CustomersAppService( ICustomerRepository customerRepository, CustomerManager customerManager, IDistributedEventBus eventBus, IDistributedCache<CustomerDownloadTokenCacheItem, string> downloadTokenCache) { _downloadTokenCache = downloadTokenCache; _customerRepository = customerRepository; _customerManager = customerManager; _eventBus = eventBus; } public virtual async Task<CustomerDto> UpdateAsync(Guid id, CustomerUpdateDto input) { var customer = await _customerManager.UpdateAsync( id, input.Name, input.Street, input.ZipCode, input.City, input.PhoneNumber, input.Email, input.IsCompany, input.IdentificationNumber, input.AttName, input.ConcurrencyStamp ); // Send update event var customerUpdatedEto = ObjectMapper.Map<Customer, CustomerUpdatedEto>(customer); await _eventBus.PublishAsync(customerUpdatedEto); // Return object return ObjectMapper.Map<Customer, CustomerDto>(customer); } ... }
The ETO class:
using Volo.Abp.EventBus; namespace MyProject.CustomerService.Customers; [EventName("MyProject.CustomerService.Customers.CustomerUpdated")] public class CustomerUpdatedEto { public Guid Id { get; set; } public string Name { get; set; } = null!; public string Street { get; set; } = null!; public string ZipCode { get; set; } = null!; public string City { get; set; } = null!; public string PhoneNumber { get; set; } = null!; public string Email { get; set; } public bool IsCompany { get; set; } public string? IdentificationNumber { get; set; } public string? AttName { get; set; } }
That's everything I have done in the CustomerService. In the subscriber, InvoiceService is only one added class CustomerServiceEventHandler
using MyProject.CustomerService.Customers; using Volo.Abp.DependencyInjection; using Volo.Abp.EventBus.Distributed; namespace MyProject.InvoiceService; public class CustomerServiceEventHandler : IDistributedEventHandler<CustomerUpdatedEto>, ITransientDependency { public async Task HandleEventAsync(CustomerUpdatedEto eventData) { var customerId = eventData.Id; } }
Now, I have started the both services, CustomerService and the InvoiceService, and the RabbitMQ queues are listed by using the RabbitMQ CLI:
$ docker exec -it rabbitmq rabbitmqctl list_queues Timeout: 60.0 seconds ... Listing queues for vhost / ... name messages AbpBackgroundJobsDelayed.Volo.Abp.Emailing.BackgroundEmailSendingJobArgs 0 MyProject_AuthServer 0 MyProject_IdentityService 0 MyProject_CustomerService 0 AbpBackgroundJobs.Volo.Abp.Emailing.BackgroundEmailSendingJobArgs 0 MyProject_InvoiceService 0
So the queues seems to be registered. However, I can't see that any message is published, nor received at the subscribe. Notice that the receiver has a binding to the ETO class MyProject.CustomerService.Customers.CustomerUpdated. When using debugger in CustomerService, I can see that there is no exceptions thrown in the
await _eventBus.PublishAsync(customerUpdatedEto);
line.$ docker exec -it rabbitmq rabbitmqctl list_bindings | grep MyProject_CustomerService exchange MyProject_CustomerService queue MyProject_CustomerService [] MyProject exchange MyProject_CustomerService queue Volo.Abp.Localization.LanguageChangedEto [] MyProject exchange MyProject_CustomerService queue Volo.Payment.RecurringPaymentUpdated [] MyProject exchange MyProject_CustomerService queue Volo.Payment.SubscriptionCanceled [] MyProject exchange MyProject_CustomerService queue Volo.Payment.SubscriptionCreated [] MyProject exchange MyProject_CustomerService queue abp.data.apply_database_migrations [] MyProject exchange MyProject_CustomerService queue abp.multi_tenancy.tenant.connection_string.updated [] MyProject exchange MyProject_CustomerService queue abp.multi_tenancy.tenant.created [] $ docker exec -it rabbitmq rabbitmqctl list_bindings | grep MyProject_InvoiceService exchange MyProject_InvoiceService queue MyProject_InvoiceService [] MyProject exchange MyProject_InvoiceService queue MyProject.CustomerService.Customers.CustomerUpdated [] MyProject exchange MyProject_InvoiceService queue Volo.Abp.Localization.LanguageChangedEto [] MyProject exchange MyProject_InvoiceService queue Volo.Payment.RecurringPaymentUpdated [] MyProject exchange MyProject_InvoiceService queue Volo.Payment.SubscriptionCanceled [] MyProject exchange MyProject_InvoiceService queue Volo.Payment.SubscriptionCreated [] MyProject exchange MyProject_InvoiceService queue abp.data.apply_database_migrations [] MyProject exchange MyProject_InvoiceService queue abp.multi_tenancy.tenant.connection_string.updated [] MyProject exchange MyProject_InvoiceService queue abp.multi_tenancy.tenant.created []
-
0
Hi,
I need to ask some additional questions.
Can you check the publisher RabbitMQ configuration is correct from the appsettings.json?
Also if you have different applications, make sure you're using the exact same
CustomerUpdatedEto
class from 2 different projecsts.- Make sure depending on .Contracts package where CustomerUpdatedEto is located from subscriber project.
Try adding
[Serialize]
attribute overCustomerUpdatedEto
class[Serializable] [EventName("MyProject.CustomerService.Customers.CustomerUpdated")] public class CustomerUpdatedEto : EtoBase { // ... }
In your example I see
IDistributedEventHandler
but there is no such an interface in ABP Framework. It should be IDistributedEventHandler<TEvent>, can you try using it as it is likeIDistributedEventHandler<CustomerUpdatedEto>
Do you see any logs in the publisher application logs whenever you publish an event? There might be an error that can help to find problem.
Do you use Microservice solution or is Outbox/Inbox pattern enabled in your application?