Just a serializer/deserializer for cloud events.
Configure.With(new EmptyActivator())
.Transport(t => t.UseRabbitMqAsOneWayClient(_container.ConnectionString))
.Serialization(s => s.UseCloudEvents()
.AddWithCustomName<UserLoggedIn>("io.cloudevents.demo.user.loggedIn") // explicit
.AddWithShortName<UserLoggedIn>()) // or with short name
.Start();
Configure.With(activator)
.Transport(t => t
.UseNativeHeaders()
.UseAzureServiceBus($"Endpoint={ConnectionString}", queue, new DefaultAzureCredential()))
.Options(o => o
.UseCustomTypeNameForTopicName())
.Serialization(s => s.UseCloudEvents()
.AddWithCustomName<UserLoggedIn>("io.cloudevents.demo.user.loggedIn")) // <-- all types _must_ be mapped explicitly, either by short name or custom name
.Start();
Using custom source for one-way clients:
Configure.OneWayClient()
.Transport(t => t
.UseNativeHeaders()
.UseAzureServiceBusAsOneWayClient($"Endpoint={ConnectionString}", new DefaultAzureCredential()))
.Options(o => o
.UseSenderAddress("my-custom-source")
.UseCustomTypeNameForTopicName())
.Serialization(s => s.UseCloudEvents()
.AddWithCustomName<UserLoggedIn>("io.cloudevents.demo.user.loggedIn")) // <-- all types _must_ be mapped explicitly, either by short name or custom name
.Start();
On bus level:
var bus = Bus.Factory
.CreateUsingRabbitMq(cfg =>
{
cfg.UseCloudEvents()
};
On a specific receive endpoint:
var bus = Bus.Factory
.CreateUsingRabbitMq(cfg =>
{
cfg.ReceiveEndpoint("...", x =>
{
x.UseCloudEvents();
}
};
This adds a deserializer to support incoming messages using the default application/cloudevents+json
content type and
sets the serializer to wrap outgoing messages in a cloud event envelope.
All (custom) types must be explicitly mapped, both for outgoing and incoming messages.
.UseCloudEvents()
.WithTypes(t => t.Map<UserLoggedIn>("loggedIn"));
Specify the type
attribute on the cloud events envelope.
Used by the deserializer when you want to deserialize to a specific (sub)type.
The subject can be constructed using the instance of the outgoing message (currently not available for Rebus).
.UseCloudEvents()
.WithTypes(t => t.Map<UserLoggedIn>("loggedIn"), map => map with { Subject = x => x.SomeProperty });
The use of cloud events is only developed for and tested in a pure pub/sub broker setup. It is safe to assume that other patterns supported by MassTransit will not work since the information required for that is not conveyed.
In the integration tests, dapr is used as publisher and subscriber to test both the serializer and deserializer.