-
Notifications
You must be signed in to change notification settings - Fork 87
Description
Use case: From a producer-perspective, I want to avoid poison messages being produced due to missing attributes that are required in the system (either by intermediaries or consumers). This should be handled as a cross-cutting concern, to avoid gaps.
Currently, the SDK allows extensions to be created, and it allows users to provide a validator to execute.
The validator method can be used to ensure the type, structure, or even combination of extensions that should be set, providing full validation of the extension. However, it doesn't allow users to indicate that it is a required extension.
Taking the example of a tenant
attribute that is required within the system's boundaries, I could register the attribute as follows:
var tenantIdAttribute =
CloudEventAttribute.CreateExtension("tenant", CloudEventAttributeType.String, tenantValue =>
{
if (tenantValue is not string tenant) throw new ArgumentException("tenant attribute must be of type string");
if (string.IsNullOrWhiteSpace(tenant))
throw new ArgumentException("tenant attribute must not be null, empty or whitespace");
});
However, the validation only runs if the attribute is actually set, but from a user's perspective, the ability to indicate this as a required extension is equally important. Currently, the SDK allows me to tackle extension validation as a cross-cutting concern by providing a validation method to the SDK, however, it currently neglects what may be most essential to many users, verifying that the attribute is actually there.