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

Allow postgres subscriptions to be configured in publish only mode #6512

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
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 @@ -40,9 +40,31 @@ public static IRequestExecutorBuilder AddPostgresSubscriptions(
this IRequestExecutorBuilder builder,
Action<IServiceProvider, PostgresSubscriptionOptions> configure)
{
builder.AddSubscriptionDiagnostics();

var services = builder.Services;

services.AddPostgresSubscriptionPublisher(configure);

services.TryAddSingleton<ITopicEventReceiver>(
sp => sp.GetRequiredService<PostgresPubSub>());

return builder;
}
/// <summary>
/// Registers the Postgres subscription provider for use in publisher scenarios where the graphql server is
/// not running, but you still want to publish events via Postgres for another process to receive.
/// </summary>
/// <param name="builder">
/// The service collecion builder.
/// </param>
/// <param name="configure">
/// A delegate that configures the Postgres subscription provider options.
/// </param>
public static IServiceCollection AddPostgresSubscriptionPublisher(
this IServiceCollection services,
Action<IServiceProvider, PostgresSubscriptionOptions> configure)
{
services.AddSubscriptionDiagnostics();

services.AddSingleton(sp =>
{
var options = new PostgresSubscriptionOptions();
Expand All @@ -61,9 +83,7 @@ public static IRequestExecutorBuilder AddPostgresSubscriptions(
services.AddSingleton<PostgresPubSub>();
services.TryAddSingleton<ITopicEventSender>(
sp => sp.GetRequiredService<PostgresPubSub>());
services.TryAddSingleton<ITopicEventReceiver>(
sp => sp.GetRequiredService<PostgresPubSub>());

return builder;
return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,32 @@ public static IRequestExecutorBuilder AddSubscriptionDiagnostics(
throw new ArgumentNullException(nameof(builder));
}

builder.Services.TryAddSingleton<ISubscriptionDiagnosticEvents>(
builder.Services.AddSubscriptionDiagnostics();

return builder;
}

/// <summary>
/// Adds the subscription provider diagnostics.
/// </summary>
/// <param name="services">
/// The ServiceCollection.
/// </param>
/// <returns>
/// Returns the ServiceCollection for configuration chaining.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="services"/> is <c>null</c>.
/// </exception>
public static IServiceCollection AddSubscriptionDiagnostics(
this IServiceCollection services)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

services.TryAddSingleton<ISubscriptionDiagnosticEvents>(
sp =>
{
var listeners = sp.GetService<IEnumerable<ISubscriptionDiagnosticEventsListener>>();
Expand Down Expand Up @@ -61,6 +86,6 @@ public static IRequestExecutorBuilder AddSubscriptionDiagnostics(
return new AggregateSubscriptionDiagnosticEventsListener(listenerArray);
});

return builder;
return services;
}
}
Loading