Skip to content

Commit

Permalink
Reduce the SchemaMessageValidatorMiddleware only to two mandatory che…
Browse files Browse the repository at this point in the history
…cks: Source and CorrelationId (#175)

* check against StreamId header has been removed as it is used only in Kafka contex

* check against Source header has been removed as it is not mandatory

* reduce the SchemaMessageValidatorMiddleware only to two mandatory checks
  • Loading branch information
VCuzmin authored Sep 1, 2021
1 parent ac6b775 commit d5c9d50
Showing 1 changed file with 0 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,9 @@ public class SchemaMessageValidatorMiddleware : IPipelineMiddleware<MessagingCon
{
public async Task Invoke(MessagingContext context, CancellationToken cancellationToken, Func<Task> next)
{
if (!context.MessagingEnvelope.Headers.TryGetValue(MessagingHeaders.MessageType, out var _))
throw new Exception($"Message of type {context.MessagingEnvelope.Payload.GetType().GetPrettyName()} does not contain {MessagingHeaders.MessageType} header.");

if (!context.MessagingEnvelope.Headers.TryGetValue(MessagingHeaders.CorrelationId, out var _))
throw new Exception($"Message of type {context.MessagingEnvelope.Payload.GetType().GetPrettyName()} does not contain {MessagingHeaders.CorrelationId} header.");

if (!context.MessagingEnvelope.Headers.TryGetValue(MessagingHeaders.MessageId, out var _))
throw new Exception($"Message of type {context.MessagingEnvelope.Payload.GetType().GetPrettyName()} does not contain {MessagingHeaders.MessageId} header.");

if (!context.MessagingEnvelope.Headers.TryGetValue(MessagingHeaders.PublishTime, out var _))
throw new Exception($"Message of type {context.MessagingEnvelope.Payload.GetType().GetPrettyName()} does not contain {MessagingHeaders.PublishTime} header.");

if (!context.MessagingEnvelope.Headers.TryGetValue(MessagingHeaders.StreamId, out var _))
throw new Exception($"Message of type {context.MessagingEnvelope.Payload.GetType().GetPrettyName()} does not contain {MessagingHeaders.StreamId} header.");

if (!context.MessagingEnvelope.Headers.TryGetValue(MessagingHeaders.Source, out var _))
throw new Exception($"Message of type {context.MessagingEnvelope.Payload.GetType().GetPrettyName()} does not contain {MessagingHeaders.Source} header.");

Expand Down

0 comments on commit d5c9d50

Please sign in to comment.