|
29 | 29 | - [Track Offset](#track-offset) |
30 | 30 | - [Handle Close](#handle-close) |
31 | 31 | - [Handle Metadata Update](#handle-metadata-update) |
| 32 | + - [Reliable](#reliable) |
| 33 | + - [Reliable Producer](#reliable-producer) |
32 | 34 | - [Build from source](#build-from-source) |
33 | 35 | - [Project Status](#project-status) |
34 | 36 |
|
@@ -220,7 +222,6 @@ var producer = await system.CreateProducer( |
220 | 222 | Stream = "my_stream", |
221 | 223 | }); |
222 | 224 | ``` |
223 | | - |
224 | 225 | Consider a Producer instance like a long-lived object, do not create one to send just one message. |
225 | 226 |
|
226 | 227 | | Parameter | Description | Default | |
@@ -408,6 +409,81 @@ You can use `MetadataHandler` to handle it: |
408 | 409 | }, |
409 | 410 | } |
410 | 411 | ``` |
| 412 | +### Reliable |
| 413 | + - Reliable Producer |
| 414 | + - Reliable Consumer (not ready yet) |
| 415 | + |
| 416 | +### Reliable Producer |
| 417 | +Reliable Producer is a smart layer built up of the standard `Producer`. </b> |
| 418 | +The idea is to leave the user decides what to use, the standard or reliable producer. </b> |
| 419 | + |
| 420 | +The main features are: |
| 421 | +- Provide publishingID automatically |
| 422 | +- Auto-Reconnect in case of disconnection |
| 423 | +- Trace sent and received messages |
| 424 | +- Invalidate messages |
| 425 | +- Handle the metadata Update |
| 426 | + |
| 427 | +#### Provide publishingID automatically |
| 428 | +Reliable Producer retrieves the last publishingID given the producer name. </b> |
| 429 | +Zero(0) is the default value in case there is no a publishingID. |
| 430 | + |
| 431 | +#### Auto-Reconnect |
| 432 | +Reliable Producer restores the TCP connection in case the Producer is disconnected for some reason. |
| 433 | +During the reconnection it continues to store the messages in a local-list. |
| 434 | +The user will receive back the confirmed or un-confirmed messages. |
| 435 | + |
| 436 | +#### Trace sent and received messages |
| 437 | +Reliable Producer keeps in memory each sent message and remove from the memory when the message is confirmed or goes in timout. |
| 438 | +`ConfirmationHandler` receives the messages back with the status. |
| 439 | +`confirmation.Status` can have different values, but in general `ConfirmationStatus.Confirmed` means the messages |
| 440 | +is stored on the server other status means that there was a problem with the message/messages. |
| 441 | +```csharp |
| 442 | +ConfirmationHandler = confirmation => |
| 443 | +{ |
| 444 | + if (confirmation.Status == ConfirmationStatus.Confirmed) |
| 445 | + { |
| 446 | + |
| 447 | + // OK |
| 448 | + } |
| 449 | + else |
| 450 | + { |
| 451 | + // Some problem |
| 452 | + } |
| 453 | +} |
| 454 | +``` |
| 455 | +#### Invalidate messages |
| 456 | +If the client doesn't receive a confirmation within 2 seconds Reliable Producer removes the message from the internal messages cache. |
| 457 | +The user will receive `ConfirmationStatus.TimeoutError` in the `ConfirmationHandler`. |
| 458 | + |
| 459 | +#### Handle the metadata Update |
| 460 | +If the streams changes the topology (ex:Stream deleted or add/remove follower), the client receives an `MetadataUpdate` event. |
| 461 | +Reliable Producer detects the event and tries to reconnect the producer if the stream still exist else closes the producer. |
| 462 | +#### Send API |
| 463 | +Reliable Producer implements two `send(..)` |
| 464 | +- `Send(Message message)` // standard |
| 465 | +- `Send(List<Message> messages, CompressionType compressionType)` //sub-batching with compression |
| 466 | +
|
| 467 | +### Reconnection Strategy |
| 468 | +By default Reliable Producer uses an `BackOffReconnectStrategy` to reconnect the client. |
| 469 | +You can customize the behaviour implementing the `IReconnectStrategy` interface: |
| 470 | +```csharp |
| 471 | +void WhenDisconnected(out bool reconnect); |
| 472 | +void WhenConnected(); |
| 473 | +``` |
| 474 | +with `reconnect` you can decide when reconnect the producer. |
| 475 | + |
| 476 | +You can use it: |
| 477 | +```csharp |
| 478 | +var p = await ReliableProducer.CreateReliableProducer(new ReliableProducerConfig() |
| 479 | +{ |
| 480 | +... |
| 481 | +ReconnectStrategy = MyReconnectStrategy |
| 482 | +``` |
| 483 | + |
| 484 | +#### Examples |
| 485 | +See the directory [Examples/Reliable](./Examples/Reliable) |
| 486 | + |
411 | 487 |
|
412 | 488 | ### Build from source |
413 | 489 | Build: |
|
0 commit comments