You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/asciidoc/advanced-topics.adoc
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,3 +74,35 @@ A defined set of values shared across the messages is a good candidate: geograph
74
74
75
75
Cardinality of filter values can be from a few to a few thousands.
76
76
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]
Copy file name to clipboardExpand all lines: docs/asciidoc/api.adoc
+149-3Lines changed: 149 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,6 +106,7 @@ The following table sums up the main settings to create an `StreamSystem` using
106
106
|Password to use to connect.
107
107
|`guest`
108
108
109
+
109
110
|`VirtualHost`
110
111
|Virtual host to connect to.
111
112
|`/`
@@ -131,8 +132,60 @@ The following table sums up the main settings to create an `StreamSystem` using
131
132
|Configuration helper for TLS.
132
133
|`null`
133
134
135
+
136
+
|`ConnectionPoolConfig`
137
+
|Define the connection pool policies. See <<connection-pool,Connection Pool>> for more details.
138
+
|1 producer/consumer per connection
139
+
134
140
|===
135
141
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]]
136
189
===== When a Load Balancer is in Use
137
190
138
191
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`:
288
341
|The confirmation handler where received the messages confirmations.
289
342
|`null` (no confirmation handler)
290
343
291
-
|ClientProvidedName
344
+
|`ClientProvidedName`
292
345
|The TCP connection name to identify the client.
293
346
|`dotnet-stream-producer`
294
347
@@ -308,11 +361,15 @@ This value is valid only for the `Send(Message)` method.
308
361
|`TimeoutMessageAfter`
309
362
|Time to wait before considering a message as not confirmed.
310
363
| 3 seconds
311
-
// TODO: Document Super stream
364
+
312
365
|`SuperStreamConfig`
313
366
|The super stream configuration.
314
367
|`null` (no super stream)
315
368
369
+
|`StatusChanged`
370
+
|The callback invoked when the producer status changes. See <<entity-status,Producer Status>> for more details.
371
+
|`null`
372
+
316
373
|===
317
374
318
375
===== Sending Messages
@@ -732,6 +789,10 @@ The following table sums up the main settings to create a `Consumer` with `Consu
732
789
|The <<crc-on-delivery,CRC32 implementation>> to use to validate the chunk server crc32 .
733
790
|`null` (no CRC32)
734
791
792
+
|`StatusChanged`
793
+
|The callback invoked when the consumer status changes. See <<entity-status,Consumer Status>> for more details.
`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
+
985
1122
[[low-high-level-classes]]
986
1123
==== Low Level and High Level classes
987
1124
@@ -1042,5 +1179,14 @@ You need to handle it yourself.
1042
1179
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.
1043
1180
See <<confirmation-status>> for more details.
1044
1181
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.
0 commit comments