Skip to content

Commit

Permalink
Merge branch 'main' into use-sone-utf8-string-literals
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Oct 12, 2023
2 parents 64c49a5 + 0a2967e commit a6c8979
Showing 1 changed file with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,49 @@ public static IRequestExecutorBuilder AddRabbitMQSubscriptions(
throw new ArgumentNullException(nameof(builder));
}

builder
.AddSubscriptionDiagnostics()
.Services
.AddRabbitMQSubscriptions(connectionFactory, options);
builder.Services
.AddRabbitMQSubscriptionPublisher(connectionFactory, options)
.TryAddSingleton<ITopicEventReceiver>(sp => sp.GetRequiredService<RabbitMQPubSub>());

return builder;
}

private static void AddRabbitMQSubscriptions(
/// <summary>
/// Registers the RabbitMQ subscription provider for use in publisher scenarios where the graphql server is
/// not running, but you still want to publish events via RabbitMQ for another process to receive.
/// </summary>
/// <param name="services">
/// The service collecion builder.
/// </param>
/// <param name="connectionFactory">
/// The RabbitMQ connection factory. This parameter is optional; the default value is <c>null</c>.
/// The following properties will be overriden with <c>true</c> to make the connection recoverable.
/// - <c>AutomaticRecoveryEnabled</c>
/// - <c>DispatchConsumersAsync</c>
/// </param>
/// <param name="options">
/// The subscription provider options. This parameter is optional; the default value is <c>null</c>.
/// </param>
/// <returns>
/// Returns the GraphQL configuration builder for configuration chaining.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="services"/> is <c>null</c>.
/// </exception>
public static IServiceCollection AddRabbitMQSubscriptionPublisher(
this IServiceCollection services,
ConnectionFactory? connectionFactory = null,
SubscriptionOptions? options = null)
{
services.AddSubscriptionDiagnostics();

services.TryAddSingleton(connectionFactory ?? new ConnectionFactory());
services.TryAddSingleton<IRabbitMQConnection, RabbitMQConnection>();
services.TryAddSingleton(options ?? new SubscriptionOptions());
services.TryAddSingleton<IMessageSerializer, DefaultJsonMessageSerializer>();
services.TryAddSingleton<RabbitMQPubSub>();
services.TryAddSingleton<ITopicEventSender>(sp => sp.GetRequiredService<RabbitMQPubSub>());
services.TryAddSingleton<ITopicEventReceiver>(sp => sp.GetRequiredService<RabbitMQPubSub>());

return services;
}
}

0 comments on commit a6c8979

Please sign in to comment.