-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RabbitMQ Subscription Provider (#5599)
- Loading branch information
Showing
15 changed files
with
776 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/HotChocolate/Core/src/Subscriptions.Nats/HotChocolate.Subscriptions.Nats.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...Chocolate/Core/src/Subscriptions.RabbitMQ/DependencyInjection/RabbitMQPubSubExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using HotChocolate.Execution.Configuration; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using HotChocolate.Subscriptions; | ||
using HotChocolate.Subscriptions.RabbitMQ; | ||
using RabbitMQ.Client; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
/// <summary> | ||
/// These helper methods allows to register the RabbitMQ subscription provider with the GraphQL configuration. | ||
/// </summary> | ||
public static class RabbitMQPubSubExtensions | ||
{ | ||
/// <summary> | ||
/// Adds support for using RabbitMQ as a subscription provider. | ||
/// </summary> | ||
/// <param name="builder"> | ||
/// The GraphQL configuration 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="builder"/> is <c>null</c>. | ||
/// </exception> | ||
public static IRequestExecutorBuilder AddRabbitMQSubscriptions( | ||
this IRequestExecutorBuilder builder, | ||
ConnectionFactory? connectionFactory = null, | ||
SubscriptionOptions? options = null) | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
builder | ||
.AddSubscriptionDiagnostics() | ||
.Services | ||
.AddRabbitMQSubscriptions(connectionFactory, options); | ||
|
||
return builder; | ||
} | ||
|
||
private static void AddRabbitMQSubscriptions( | ||
this IServiceCollection services, | ||
ConnectionFactory? connectionFactory = null, | ||
SubscriptionOptions? options = null) | ||
{ | ||
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>()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/HotChocolate/Core/src/Subscriptions.RabbitMQ/HotChocolate.Subscriptions.RabbitMQ.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<PackageId>HotChocolate.Subscriptions.RabbitMQ</PackageId> | ||
<AssemblyName>HotChocolate.Subscriptions.RabbitMQ</AssemblyName> | ||
<RootNamespace>HotChocolate.Subscriptions.RabbitMQ</RootNamespace> | ||
<Description>Contains a Hot Chocolate GraphQL subscription provider for RabbitMQ.</Description> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<TargetFrameworks>$(Library2TargetFrameworks)</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<InternalsVisibleTo Include="HotChocolate.Subscriptions.RabbitMQ.Tests" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Execution.Abstractions\HotChocolate.Execution.Abstractions.csproj" /> | ||
<ProjectReference Include="..\Subscriptions\HotChocolate.Subscriptions.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Update="Properties\RabbitMQResources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>RabbitMQResources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="Properties\RabbitMQResources.Designer.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>RabbitMQResources.resx</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
src/HotChocolate/Core/src/Subscriptions.RabbitMQ/IRabbitMQConncetion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using RabbitMQ.Client; | ||
|
||
namespace HotChocolate.Subscriptions.RabbitMQ; | ||
|
||
internal interface IRabbitMQConnection | ||
{ | ||
public Task<IModel> GetChannelAsync(); | ||
} |
103 changes: 103 additions & 0 deletions
103
src/HotChocolate/Core/src/Subscriptions.RabbitMQ/Properties/RabbitMQResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/HotChocolate/Core/src/Subscriptions.RabbitMQ/Properties/RabbitMQResources.resx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<root> | ||
<xsd:schema id="root" | ||
xmlns="" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
|
||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>1.3</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<data name="RabbitMQPubSubExtensions_AddRabbitMQSubscriptions_PrefixInvalid" xml:space="preserve"> | ||
<value>Prefix can only contain letters and numbers.</value> | ||
</data> | ||
<data name="RabbitMQPubSub_RabbitMQPubSub_PrefixCannotBeNull" xml:space="preserve"> | ||
<value>Value cannot be null or whitespace.</value> | ||
</data> | ||
<data name="Subscription_Unsubscribe_UnsubscribedFromRabbitMQ" xml:space="preserve"> | ||
<value>Unsubscribed from RabbitMQ.</value> | ||
</data> | ||
<data name="RabbitMQTopic_ConnectAsync_SubscribedToRabbitMQ" xml:space="preserve"> | ||
<value>Subscribed to RabbitMQ.</value> | ||
</data> | ||
<data name="RabbitMQConnection_InitializeConnection_ConnectionSucceededButFailedUnexpectedly" xml:space="preserve"> | ||
<value>Although the connection was successful, something went wrong.</value> | ||
</data> | ||
<data name="RabbitMQConnection_InitializeConnection_ConnectionAttemptFailed" xml:space="preserve"> | ||
<value>Connection could not be established. Connection attempt: {0}</value> | ||
</data> | ||
<data name="RabbitMQConnection_InitializeConnection_ConnectionFailedAfterRetry" xml:space="preserve"> | ||
<value>Connection could not be established after {0} connection attempts. Please check the connection settings and message broker service status.</value> | ||
</data> | ||
<data name="RabbitMQConnection_InitializeConnection_ConnectionFailedUnexpectedly" xml:space="preserve"> | ||
<value>Something went completely wrong,</value> | ||
</data> | ||
<data name="RabbitMQConnectionFailedException_RabbitMQConnectionFailedException_ConnectionFailed" xml:space="preserve"> | ||
<value>Connection could not be established after {0} attempts.</value> | ||
</data> | ||
</root> |
Oops, something went wrong.