Skip to content

Commit bb5e513

Browse files
authored
Update documentation [skip ci] (#360)
Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent 86b9d4c commit bb5e513

File tree

2 files changed

+181
-3
lines changed

2 files changed

+181
-3
lines changed

docs/asciidoc/advanced-topics.adoc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,35 @@ A defined set of values shared across the messages is a good candidate: geograph
7474

7575
Cardinality of filter values can be from a few to a few thousands.
7676
Extreme cardinality (a couple or dozens of thousands) can make filtering less efficient.
77+
78+
79+
=== Deal with broker disconnections, reconnections and metadata update events
80+
81+
The classes `Producer` and `Consumer` automatically handle broker disconnections and reconnections.
82+
83+
It is important to know what happens when a broker is disconnected and reconnected.
84+
See this https://docs.google.com/presentation/d/111PccBLRGb-RNpYEKeIm2MQvdky-fXrQ/edit#slide=id.p1[presentation] about that.
85+
86+
The `Producer` and `Consumer` classes also handle metadata update events.
87+
When a stream is deleted, the `Producer` and `Consumer` classes automatically close the underlying `Raw*Producer` and `Raw*Consumer` objects.
88+
89+
The classes provides two interfaces:
90+
91+
- ResourceAvailableReconnectStrategy (checks when the resource is available)
92+
- ReconnectStrategy (reconnects to the broker)
93+
94+
That by default implement the reconnection strategy using a back off algorithm.
95+
You can provide your own implementation of these interfaces to customize the reconnection strategy. Most of the time, the default implementation is enough.
96+
97+
You can find a full example https://github.com/rabbitmq/rabbitmq-stream-dotnet-client/tree/main/docs/ReliableClient[here]
98+
99+
=== Update Secret
100+
101+
To update the secret, you can use:
102+
103+
[source,csharp]
104+
----
105+
await system.UpdateSecret(await NewAccessToken()).ConfigureAwait(false);
106+
----
107+
108+
You can see a full example with a Keycloak integration https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/tree/main/stream_dot_net/Keycloak[here]

docs/asciidoc/api.adoc

Lines changed: 149 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ The following table sums up the main settings to create an `StreamSystem` using
106106
|Password to use to connect.
107107
|`guest`
108108

109+
109110
|`VirtualHost`
110111
|Virtual host to connect to.
111112
|`/`
@@ -131,8 +132,60 @@ The following table sums up the main settings to create an `StreamSystem` using
131132
|Configuration helper for TLS.
132133
|`null`
133134

135+
136+
|`ConnectionPoolConfig`
137+
|Define the connection pool policies. See <<connection-pool,Connection Pool>> for more details.
138+
|1 producer/consumer per connection
139+
134140
|===
135141

142+
[[connection-pool]]
143+
==== Connection pool
144+
Introduced on version 1.8.0.
145+
With the connection pool you can define how many producers and consumers can be created on a single connection.
146+
147+
[source]
148+
----
149+
ConnectionPoolConfig = new ConnectionPoolConfig()
150+
{
151+
ProducersPerConnection = 2,
152+
ConsumersPerConnection = 3,
153+
}
154+
----
155+
156+
By default the connection pool is set to 1 producer and 1 consumer per connection.
157+
The maximum number of producers and consumers per connection is 200.
158+
159+
An high value can reduce the number of connections to the server but it could reduce the performance of the producer and the consumer.
160+
161+
An low value can increase the number of connections to the server but it could increase the performance of the producer and the consumer.
162+
163+
The consumers share the same handler, so if you have a high number of consumers per connection, the handler could be a bottleneck. It means that if there is a slow consumer all the other consumers could be slow.
164+
165+
TIP:
166+
You can use different StreamSystemConfig like:
167+
168+
[source]
169+
----
170+
171+
streamSystemToReduceTheConnections = new StreamSystemConfig{
172+
ConnectionPoolConfig = new ConnectionPoolConfig() {
173+
ConsumersPerConnection = 50, // high value
174+
ProducersPerConnection = 50, // high value
175+
}
176+
}
177+
178+
streamSystemToIncreaseThePerformances = new StreamSystemConfig{
179+
ConnectionPoolConfig = new ConnectionPoolConfig() {
180+
ConsumersPerConnection = 1, // low value
181+
ProducersPerConnection = 1, // low value
182+
}
183+
}
184+
----
185+
There is not a magic number, you have to test and evaluate the best value for your use case.
186+
187+
188+
[[address-resolver]]
136189
===== When a Load Balancer is in Use
137190

138191
A load balancer can misguide the client when it tries to connect to nodes that host stream leaders and replicas.
@@ -288,7 +341,7 @@ The following table sums up the main settings to create a `ProducerConfig`:
288341
|The confirmation handler where received the messages confirmations.
289342
|`null` (no confirmation handler)
290343

291-
|ClientProvidedName
344+
|`ClientProvidedName`
292345
|The TCP connection name to identify the client.
293346
|`dotnet-stream-producer`
294347

@@ -308,11 +361,15 @@ This value is valid only for the `Send(Message)` method.
308361
|`TimeoutMessageAfter`
309362
|Time to wait before considering a message as not confirmed.
310363
| 3 seconds
311-
// TODO: Document Super stream
364+
312365
|`SuperStreamConfig`
313366
|The super stream configuration.
314367
|`null` (no super stream)
315368

369+
|`StatusChanged`
370+
|The callback invoked when the producer status changes. See <<entity-status,Producer Status>> for more details.
371+
|`null`
372+
316373
|===
317374

318375
===== Sending Messages
@@ -732,6 +789,10 @@ The following table sums up the main settings to create a `Consumer` with `Consu
732789
|The <<crc-on-delivery,CRC32 implementation>> to use to validate the chunk server crc32 .
733790
|`null` (no CRC32)
734791

792+
|`StatusChanged`
793+
|The callback invoked when the consumer status changes. See <<entity-status,Consumer Status>> for more details.
794+
|`null`
795+
735796
|===
736797

737798
[NOTE]
@@ -982,6 +1043,82 @@ include::{test-examples}/ConsumerUsage.cs[tag=sac-consumer-update-listener]
9821043
<2> Enable single active consumer
9831044
<3> Handle `ConsumerUpdateListener` callback
9841045

1046+
1047+
[[entity-status]]
1048+
==== Producer/Consumer change status callback
1049+
`Producer` and `Consumer` classes provide a callback to handle the status change.
1050+
It is possible to configure the event using the configuration `StatusChanged` property.
1051+
1052+
like the following snippet:
1053+
[source,c#,indent=0]
1054+
--------
1055+
var conf = new ConsumerConfig(system, stream)
1056+
{
1057+
StatusChanged = (statusInfo) =>
1058+
{
1059+
Console.WriteLine($"Consumer status changed to {statusInfo}");
1060+
}
1061+
};
1062+
var consumer = Consumer.Create(conf);
1063+
--------
1064+
1065+
the `statusInfo` contains the following information:
1066+
1067+
[%header,cols=2*]
1068+
|===
1069+
|Parameter Name
1070+
|Description
1071+
1072+
|`From`
1073+
|The previous status
1074+
1075+
|`To`
1076+
|The new status
1077+
1078+
|`Stream`
1079+
|The stream where the Producer or the Consumer is connected
1080+
1081+
|`Identifier`
1082+
|The identifier of the Producer or the Consumer
1083+
1084+
|`Partition`
1085+
|The partition in case of super stream
1086+
1087+
|`Reason`
1088+
|The reason of the status change. See <<status-reason,Status Reason>> for more details.
1089+
1090+
|===
1091+
1092+
[[status-reason]]
1093+
`statusInfo.Reason` values:
1094+
1095+
[%header,cols=2*]
1096+
|===
1097+
|Parameter Name
1098+
|Description
1099+
1100+
|`None`
1101+
|No reason, default value
1102+
1103+
|`UnexpectedlyDisconnected`
1104+
|The client was unexpectedly disconnected from the server
1105+
1106+
|`MetaDataUpdate`
1107+
|The server has updated the metadata of the stream. See this https://docs.google.com/presentation/d/111PccBLRGb-RNpYEKeIm2MQvdky-fXrQ/edit?usp=sharing&ouid=106772747306273309885[presentation] about metadata update for more details
1108+
1109+
| `ClosedByUser`
1110+
| The client was closed by the user
1111+
1112+
| `ClosedByStrategyPolicy`
1113+
| The Producer or Consumer was closed by the strategy policy
1114+
1115+
|`BoolFailure`
1116+
| The Producer or Consumer has failed to connect to the server.
1117+
|===
1118+
1119+
A full example of the status change callback can be found in https://github.com/rabbitmq/rabbitmq-stream-dotnet-client/tree/main/docs/ReliableClient[here].
1120+
1121+
9851122
[[low-high-level-classes]]
9861123
==== Low Level and High Level classes
9871124

@@ -1042,5 +1179,14 @@ You need to handle it yourself.
10421179
The `Producer` traces the sent and received messages to give back to the user the original message sent to the server and also handle the message timeout.
10431180
See <<confirmation-status>> for more details.
10441181

1045-
It would be best to use `Producer` and `Consumer` classes unless you need to handle the low-level details.
1182+
It would be best to use `Producer` and `Consumer` classes unless you need to handle the low-level details.
1183+
1184+
This is a https://github.com/rabbitmq/rabbitmq-stream-dotnet-client/tree/main/docs/ReliableClient[full example] how to deal with disconnections and metadata updates.
1185+
1186+
1187+
1188+
1189+
1190+
1191+
10461192

0 commit comments

Comments
 (0)