Skip to content

Commit

Permalink
chore: remove guard.net references from eventhubs
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnmoreels committed Jan 29, 2025
1 parent 5ca6a64 commit 43dbd26
Show file tree
Hide file tree
Showing 22 changed files with 389 additions and 328 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Threading;
using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Producer;
using GuardNet;

namespace Arcus.Messaging.Abstractions.EventHubs
{
Expand All @@ -13,7 +12,7 @@ namespace Arcus.Messaging.Abstractions.EventHubs
public class AzureEventHubsMessageContext : MessageContext
{
private AzureEventHubsMessageContext(
EventData eventData,
EventData eventData,
string eventHubsName,
string consumerGroup,
string eventHubsNamespace,
Expand Down Expand Up @@ -125,8 +124,10 @@ public static AzureEventHubsMessageContext CreateFrom(
EventData message,
EventProcessorClient eventProcessor)
{
Guard.NotNull(message, nameof(message), "Requires an Azure EventHubs event data message to retrieve the information to create a messaging context for this message");
Guard.NotNull(eventProcessor, nameof(eventProcessor), "Requires an Azure EventHubs event processor to retrieve the information to create a messaging context for the consumed event");
if (eventProcessor is null)
{
throw new ArgumentNullException(nameof(eventProcessor));
}

return CreateFrom(
message,
Expand Down Expand Up @@ -157,11 +158,6 @@ public static AzureEventHubsMessageContext CreateFrom(
string consumerGroup,
string eventHubsName)
{
Guard.NotNull(message, nameof(message), "Requires an Azure EventHubs event data message to retrieve the information to create a messaging context for this message");
Guard.NotNullOrWhitespace(eventHubsNamespace, nameof(eventHubsNamespace), "Requires a non-blank Azure EventHubs fully qualified namespace to relate the messaging context to the event message");
Guard.NotNullOrWhitespace(consumerGroup, nameof(consumerGroup), "Requires a non-blank Azure EventHubs consumer group to relate the messaging context to the event message");
Guard.NotNullOrWhitespace(eventHubsName, nameof(eventHubsName), "Requires a non-blank Azure EventHubs name to relate the messaging context to the event message");

return CreateFrom(message, eventHubsNamespace, consumerGroup, eventHubsName, "<not-defined>");
}

Expand All @@ -179,9 +175,10 @@ public static AzureEventHubsMessageContext CreateFrom(
EventProcessorClient eventProcessor,
string jobId)
{
Guard.NotNull(message, nameof(message), "Requires an Azure EventHubs event data message to retrieve the information to create a messaging context for this message");
Guard.NotNull(eventProcessor, nameof(eventProcessor), "Requires an Azure EventHubs event processor to retrieve the information to create a messaging context for the consumed event");
Guard.NotNullOrWhitespace(jobId, nameof(jobId), "Requires a non-blank job ID to link this message context to a message pump that processes the event message");
if (eventProcessor is null)
{
throw new ArgumentNullException(nameof(eventProcessor));
}

return CreateFrom(
message,
Expand Down Expand Up @@ -213,11 +210,30 @@ public static AzureEventHubsMessageContext CreateFrom(
string eventHubsName,
string jobId)
{
Guard.NotNull(message, nameof(message), "Requires an Azure EventHubs event data message to retrieve the information to create a messaging context for this message");
Guard.NotNullOrWhitespace(eventHubsNamespace, nameof(eventHubsNamespace), "Requires a non-blank Azure EventHubs fully qualified namespace to relate the messaging context to the event message");
Guard.NotNullOrWhitespace(consumerGroup, nameof(consumerGroup), "Requires a non-blank Azure EventHubs consumer group to relate the messaging context to the event message");
Guard.NotNullOrWhitespace(eventHubsName, nameof(eventHubsName), "Requires a non-blank Azure EventHubs name to relate the messaging context to the event message");
Guard.NotNullOrWhitespace(jobId, nameof(jobId), "Requires a non-blank job ID to link this message context to a message pump that processes the event message");
if (message is null)
{
throw new ArgumentNullException(nameof(message));
}

if (string.IsNullOrWhiteSpace(eventHubsNamespace))
{
throw new ArgumentException("Requires a non-blank Azure EventHubs fully qualified namespace to relate the messaging context to the event message", nameof(eventHubsNamespace));
}

if (string.IsNullOrWhiteSpace(consumerGroup))
{
throw new ArgumentException("Requires a non-blank Azure EventHubs consumer group to relate the messaging context to the event message", nameof(consumerGroup));
}

if (string.IsNullOrWhiteSpace(eventHubsName))
{
throw new ArgumentException("Requires a non-blank Azure EventHubs name to relate the messaging context to the event message", nameof(eventHubsName));
}

if (string.IsNullOrWhiteSpace(jobId))
{
throw new ArgumentException("Requires a non-blank job ID to link this message context to a message pump that processes the event message", nameof(jobId));
}

return new AzureEventHubsMessageContext(message, eventHubsName, consumerGroup, eventHubsNamespace, jobId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using Arcus.Messaging.Abstractions.EventHubs;
using GuardNet;

// ReSharper disable once CheckNamespace
namespace Azure.Messaging.EventHubs
Expand All @@ -20,10 +19,6 @@ public static class EventDataExtensions
/// <exception cref="ArgumentException">Thrown when the <paramref name="jobId"/> is blank.</exception>
public static AzureEventHubsMessageContext GetMessageContext(this EventData message, EventProcessorClient eventProcessor, string jobId)
{
Guard.NotNull(message, nameof(message), "Requires an event data to retrieve the Azure EventHubs message context");
Guard.NotNull(eventProcessor, nameof(eventProcessor), "Requires an Azure EventHubs event processor to retrieve the information to create a messaging context for the consumed event");
Guard.NotNullOrWhitespace(jobId, nameof(jobId), "Requires a non-blank job ID to link this message context to a message pump that processes the event message");

return AzureEventHubsMessageContext.CreateFrom(message, eventProcessor, jobId);
}

Expand All @@ -44,12 +39,6 @@ public static AzureEventHubsMessageContext GetMessageContext(this EventData mess
/// </exception>
public static AzureEventHubsMessageContext GetMessageContext(this EventData message, string eventHubsNamespace, string eventHubsName, string consumerGroup, string jobId)
{
Guard.NotNull(message, nameof(message), "Requires an event data to retrieve the Azure EventHubs message context");
Guard.NotNullOrWhitespace(eventHubsNamespace, nameof(eventHubsNamespace), "Requires an Azure EventHubs namespace to built-up the message context");
Guard.NotNullOrWhitespace(eventHubsName, nameof(eventHubsName), "Requires an Azure EventHubs name to built-up the message context");
Guard.NotNullOrWhitespace(consumerGroup, nameof(consumerGroup), "Requires an Azure EventHubs consumer group to built-up the message context");
Guard.NotNullOrWhitespace(jobId, nameof(jobId), "Requires a non-blank job ID to link this message context to a message pump that processes the event message");

return AzureEventHubsMessageContext.CreateFrom(message, eventHubsNamespace, consumerGroup, eventHubsName, jobId);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Arcus.Messaging.Abstractions.EventHubs;
using Arcus.Messaging.Abstractions.EventHubs.MessageHandling;
using GuardNet;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
Expand All @@ -24,7 +23,10 @@ public static EventHubsMessageHandlerCollection WithEventHubsMessageHandler<TMes
where TMessageHandler : class, IAzureEventHubsMessageHandler<TMessage>
where TMessage : class
{
Guard.NotNull(handlers, nameof(handlers), "Requires a set of handlers to add the message handler");
if (handlers is null)
{
throw new ArgumentNullException(nameof(handlers));
}

handlers.WithMessageHandler<TMessageHandler, TMessage, AzureEventHubsMessageContext>();
return handlers;
Expand All @@ -45,8 +47,15 @@ public static EventHubsMessageHandlerCollection WithEventHubsMessageHandler<TMes
where TMessageHandler : class, IAzureEventHubsMessageHandler<TMessage>
where TMessage : class
{
Guard.NotNull(handlers, nameof(handlers), "Requires a set of handlers to add the message handler");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent handlers");
if (handlers is null)
{
throw new ArgumentNullException(nameof(handlers));
}

if (implementationFactory is null)
{
throw new ArgumentNullException(nameof(implementationFactory));
}

handlers.WithMessageHandler<TMessageHandler, TMessage, AzureEventHubsMessageContext>(implementationFactory);
return handlers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using Arcus.Messaging.Abstractions.EventHubs.MessageHandling;
using GuardNet;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;

Expand All @@ -22,8 +21,6 @@ public static class IServiceCollectionExtensions
public static EventHubsMessageHandlerCollection AddEventHubsMessageRouting(
this IServiceCollection services)
{
Guard.NotNull(services, nameof(services), "Requires a set of services to register the Azure EventHubs message routing");

return AddEventHubsMessageRouting(services, configureOptions: null);
}

Expand All @@ -38,8 +35,6 @@ public static EventHubsMessageHandlerCollection AddEventHubsMessageRouting(
this IServiceCollection services,
Action<AzureEventHubsMessageRouterOptions> configureOptions)
{
Guard.NotNull(services, nameof(services), "Requires a set of services to register the Azure EventHubs message routing");

return AddEventHubsMessageRouting(services, (serviceProvider, options) =>
{
var logger = serviceProvider.GetService<ILogger<AzureEventHubsMessageRouter>>();
Expand All @@ -60,9 +55,6 @@ public static EventHubsMessageHandlerCollection AddEventHubsMessageRouting<TMess
Func<IServiceProvider, TMessageRouter> implementationFactory)
where TMessageRouter : IAzureEventHubsMessageRouter
{
Guard.NotNull(services, nameof(services), "Requires a set of services to register the Azure EventHubs message routing");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the Azure EventHubs message router");

return AddEventHubsMessageRouting(services, (serviceProvider, options) => implementationFactory(serviceProvider), configureOptions: null);
}

Expand All @@ -81,8 +73,15 @@ public static EventHubsMessageHandlerCollection AddEventHubsMessageRouting<TMess
Action<AzureEventHubsMessageRouterOptions> configureOptions)
where TMessageRouter : IAzureEventHubsMessageRouter
{
Guard.NotNull(services, nameof(services), "Requires a set of services to register the Azure EventHubs message routing");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the Azure EventHubs message router");
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

if (implementationFactory is null)
{
throw new ArgumentNullException(nameof(implementationFactory));
}

services.TryAddSingleton<IAzureEventHubsMessageRouter>(serviceProvider =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Arcus.Messaging.Abstractions.EventHubs;
using Arcus.Messaging.Abstractions.EventHubs.MessageHandling;
using GuardNet;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
Expand All @@ -27,8 +26,10 @@ public static EventHubsMessageHandlerCollection WithEventHubsMessageHandler<TMes
where TMessageHandler : class, IAzureEventHubsMessageHandler<TMessage>
where TMessage : class
{
Guard.NotNull(handlers, nameof(handlers), "Requires a set of handlers to add the message handler");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");
if (handlers is null)
{
throw new ArgumentNullException(nameof(handlers));
}

handlers.WithMessageHandler<TMessageHandler, TMessage, AzureEventHubsMessageContext>(messageBodyFilter);
return handlers;
Expand All @@ -51,9 +52,10 @@ public static EventHubsMessageHandlerCollection WithEventHubsMessageHandler<TMes
where TMessageHandler : class, IAzureEventHubsMessageHandler<TMessage>
where TMessage : class
{
Guard.NotNull(handlers, nameof(handlers), "Requires a set of handlers to add the message handler");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent handlers");
if (handlers is null)
{
throw new ArgumentNullException(nameof(handlers));
}

handlers.WithMessageHandler<TMessageHandler, TMessage, AzureEventHubsMessageContext>(messageBodyFilter, implementationFactory);
return handlers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Arcus.Messaging.Abstractions.EventHubs;
using Arcus.Messaging.Abstractions.EventHubs.MessageHandling;
using GuardNet;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
Expand All @@ -27,8 +26,10 @@ public static EventHubsMessageHandlerCollection WithEventHubsMessageHandler<TMes
where TMessageHandler : class, IAzureEventHubsMessageHandler<TMessage>
where TMessage : class
{
Guard.NotNull(handlers, nameof(handlers), "Requires a set of handlers to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
if (handlers is null)
{
throw new ArgumentNullException(nameof(handlers));
}

handlers.WithMessageHandler<TMessageHandler, TMessage, AzureEventHubsMessageContext>(
messageContextFilter, serviceProvider => ActivatorUtilities.CreateInstance<TMessageHandler>(serviceProvider));
Expand All @@ -53,9 +54,10 @@ public static EventHubsMessageHandlerCollection WithEventHubsMessageHandler<TMes
where TMessageHandler : class, IAzureEventHubsMessageHandler<TMessage>
where TMessage : class
{
Guard.NotNull(handlers, nameof(handlers), "Requires a set of handlers to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent handlers");
if (handlers is null)
{
throw new ArgumentNullException(nameof(handlers));
}

handlers.WithMessageHandler<TMessageHandler, TMessage, AzureEventHubsMessageContext>(messageContextFilter, implementationFactory);
return handlers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Arcus.Messaging.Abstractions.EventHubs;
using Arcus.Messaging.Abstractions.EventHubs.MessageHandling;
using GuardNet;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
Expand Down Expand Up @@ -29,8 +28,10 @@ public static EventHubsMessageHandlerCollection WithEventHubsMessageHandler<TMes
where TMessageHandler : class, IAzureEventHubsMessageHandler<TMessage>
where TMessage : class
{
Guard.NotNull(handlers, nameof(handlers), "Requires a set of handlers to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
if (handlers is null)
{
throw new ArgumentNullException(nameof(handlers));
}

handlers.WithMessageHandler<TMessageHandler, TMessage, AzureEventHubsMessageContext>(messageContextFilter, messageBodyFilter);
return handlers;
Expand All @@ -55,12 +56,12 @@ public static EventHubsMessageHandlerCollection WithEventHubsMessageHandler<TMes
where TMessageHandler : class, IAzureEventHubsMessageHandler<TMessage>
where TMessage : class
{
Guard.NotNull(handlers, nameof(handlers), "Requires a set of handlers to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent handlers");
if (handlers is null)
{
throw new ArgumentNullException(nameof(handlers));
}

handlers.WithMessageHandler<TMessageHandler, TMessage, AzureEventHubsMessageContext>(messageContextFilter, messageBodyFilter, implementationFactory);
handlers.WithMessageHandler(messageContextFilter, messageBodyFilter, implementationFactory);
return handlers;
}
}
Expand Down
Loading

0 comments on commit 43dbd26

Please sign in to comment.