Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split rabbit mq topic event sender into seperate registration method #6559

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading