Hi,
We need to send events across applications and cannot use a shared ETO library. Some research indicate you can decorate the class with EventName attribute.
We implemented Rebus with Postgress but it does not look like Rebus can support routing with the EventName.
Is this even possible. Some code snippets out of our project:
Consumer: const string QueueName = "abc";
PreConfigure<AbpRebusEventBusOptions>(options =>
{
options.InputQueueName = QueueName;
options.Configurer = cfg =>
{
cfg.Transport(t => t.UsePostgreSql(
connectionString: rebusConnectionString,
tableName: "RebusMessages",
inputQueueName: QueueName))
.Subscriptions(s => s.StoreInPostgres(rebusConnectionString, "RebusSubscriptions"));
};
});
}
Publisher:
internal class Program
{
static async Task Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
#if DEBUG .MinimumLevel.Debug() #else .MinimumLevel.Information() #endif .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Async(c => c.File("Logs/logs.txt", rollingInterval: RollingInterval.Day)) #if DEBUG .WriteTo.Async(c => c.Console()) #endif .CreateLogger();
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.AddUserSecrets<Program>()
.AddEnvironmentVariables()
.Build();
using var app = AbpApplicationFactory.Create<CLIModule>(options =>
{
options.UseAutofac();
options.Services.ReplaceConfiguration(configuration);
options.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.ClearProviders();
loggingBuilder.AddSerilog();
});
});
await app.InitializeAsync();
var eventBus = app.ServiceProvider.GetRequiredService<IDistributedEventBus>();
var uowManager = app.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
var evt = new TenantChangedEventEto
{
Id = Guid.NewGuid(),
Name = "SampleTenant",
NormalizedName = "SAMPLETENANT",
EditionId = null,
//ChangeType = TenantChangeType.Created
};
using (var uow = uowManager.Begin())
{
await eventBus.PublishAsync(evt);
await uow.CompleteAsync();
}
Console.WriteLine("Event published!");
Console.ReadLine();
await app.ShutdownAsync();
}
}
}
ETO (each project in its own namespace):
[EventName("TenantChanged")] public class TenantChangedEventEto { public Guid Id { get; set; } public string Name { get; set; } = null!; public string NormalizedName { get; set; } = null!; public Guid? EditionId { get; set; } }
But this CLI continues to report:
[17:30:51 DBG] Sending Accounting.Etos.TenantChangedEventEto -> "<no destinations>"
I even added the "TenantChanged" entry to the RebusSubscriptions table.
As a side note. I've tested this sharing a single class then the publisher works and the events fire.
ABP version: 9.2.2
Let me know if you need more info.
Carel
1 Answer(s)
-
0
In ABP's distributed event bus, the EventName attribute allows you to decouple event contracts between services by specifying a string event name, so different assemblies can use different class names as long as the EventName matches. This is supported by ABP's event bus abstraction.
However, Rebus itself (the underlying transport library) does not natively route messages based on the EventName attribute. Rebus uses the .NET type name for routing and subscription matching. This means that unless both publisher and consumer share the same .NET type (i.e., the same class full name and namespace), Rebus will not match the event, even if the EventName attribute is present.
In your scenario, since you cannot share the ETO class library and want to use only the EventName for routing, this will not work with Rebus out of the box. The ABP EventName attribute is respected by ABP's own event bus implementations (like RabbitMQ, Azure Service Bus, etc.), but not by Rebus, which relies on type-based routing.
The only way to make this work with Rebus is to ensure both publisher and consumer use the same .NET type (shared contract), or to implement a custom message mapping layer that serializes/deserializes based on EventName, which is not provided by default.
If you need to decouple contracts and use EventName-based routing, consider using another ABP-supported event bus provider (like RabbitMQ or Azure Service Bus) that supports this feature.
Sources:
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.