Skip to content

Commit

Permalink
Durable consumer docs (#270)
Browse files Browse the repository at this point in the history
[nats:update-docs]
  • Loading branch information
mtmk authored Dec 6, 2023
1 parent 33c1d89 commit 5f925ea
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
10 changes: 10 additions & 0 deletions docs/documentation/jetstream/manage.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ Unlike streams, consumers are accessed by NATS client libraries as part of messa

[!code-csharp[](../../../tests/NATS.Net.DocsExamples/JetStream/ManagingPage.cs#consumer-create)]
[!code-csharp[](../../../tests/NATS.Net.DocsExamples/JetStream/ManagingPage.cs#consumer-get)]

### Ephemeral and Durable Consumers

A consumer can be ephemeral or durable. It is considered durable when an explicit name is set on the
DurableName field when creating the consumer, otherwise it is considered ephemeral. Durables and ephemeral behave
exactly the same except that an ephemeral will be automatically cleaned up (deleted) after a period of inactivity,
specifically when there are no subscriptions bound to the consumer.

[!code-csharp[](../../../tests/NATS.Net.DocsExamples/JetStream/ManagingPage.cs#consumer-durable)]
[!code-csharp[](../../../tests/NATS.Net.DocsExamples/JetStream/ManagingPage.cs#consumer-ephemeral)]
19 changes: 10 additions & 9 deletions docs/documentation/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ You can set the TLS options to use your client certificates when connecting to a

[!code-csharp[](../../tests/NATS.Net.DocsExamples/SecurityPage.cs#tls-mutual)]

### Intermediate CA Certificates

When connecting using intermediate CA certificates, it might noy be possible to validate the client certificate and the TLS handshake may fail.

Unfortunately, for .NET client applications it isn't possible to pass additional intermediate certificates and the only
solution is to add the certificates to the certificate store manually.

See also:
https://learn.microsoft.com/en-us/dotnet/core/extensions/sslstream-troubleshooting#intermediate-certificates-are-not-sent
> [!TIP]
> #### Intermediate CA Certificates
>
> When connecting using intermediate CA certificates, it might not be possible to validate the client certificate and
> TLS handshake may fail.
>
> Unfortunately, for .NET client applications it isn't possible to pass additional intermediate certificates and the
> only solution is to add the certificates to the certificate store manually.
>
> See also .NET documentation on [Troubleshooting SslStream authentication issues](https://learn.microsoft.com/en-us/dotnet/core/extensions/sslstream-troubleshooting#intermediate-certificates-are-not-sent)
32 changes: 32 additions & 0 deletions tests/NATS.Net.DocsExamples/JetStream/ManagingPage.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ReSharper disable RedundantAssignment
// ReSharper disable SuggestVarOrType_Elsewhere

using NATS.Client.Core;
Expand Down Expand Up @@ -58,5 +59,36 @@ public async Task Run()
var consumer = await js.GetConsumerAsync(stream: "orders", consumer: "order_processor");
#endregion
}

{
#region consumer-durable
// Create a durable consumer
var durableConfig = new ConsumerConfig("durable_processor");

// Same as above
durableConfig = new ConsumerConfig
{
Name = "durable_processor",
DurableName = "durable_processor",
AckPolicy = ConsumerConfigAckPolicy.Explicit,
};

var consumer = await js.CreateOrUpdateConsumerAsync(stream: "orders", durableConfig);

Console.WriteLine($"Consumer Name: {consumer.Info.Name}"); // durable_processor
Console.WriteLine($"Consumer DurableName: {consumer.Info.Config.DurableName}"); // durable_processor
#endregion
}

{
#region consumer-ephemeral
// Create an ephemeral consumer by not setting durable name
var ephemeralConfig = new ConsumerConfig();

var consumer = await js.CreateOrUpdateConsumerAsync(stream: "orders", ephemeralConfig);

Console.WriteLine($"Consumer Name: {consumer.Info.Name}"); // e.g. Z8YlwrP9 (server assigned random name)
#endregion
}
}
}

0 comments on commit 5f925ea

Please sign in to comment.