Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Reconnection #343

Merged
merged 5 commits into from
Jan 11, 2024
Merged

Improve Reconnection #343

merged 5 commits into from
Jan 11, 2024

Conversation

Gsantomaggio
Copy link
Member

@Gsantomaggio Gsantomaggio commented Jan 9, 2024

  • Part of Improve reconnection #336

  • Improve the disconnection message. It is possible to understand if it is a normal disconnection or an unexpected.

  • Remove the Active Items from the connection pool and use the Publishers and Consumers client list directly to check the pool size

  • Refactor the Factory Classes. Remove code duplication in case of metadata update and connection closed. See ReliableBase.OnEntityClosed

  • Handle streamNotAvailable error. In this case the client will try to reconnect the entity

  • Fix the events attach to the RawConsumer and RawProducer. The events are attached only if the ResponseCode is OK

  • Detach the events once the entity receives the disconnection or metadata update. In that case, the entity is closed

  • Introduce ReliableEntityStatus like a state machine to understand the status of Producer and Consumer classes

  • Add ResourceAvailableReconnectStrategy interface to Handle the retry in case testing in a stream exists. See ReliableBase CheckIfStreamIsAvailable

  • Change the MetadataHandler to Func<MetaDataUpdate, Task> to be like the other methods

  • Producer and Consumer classes fail fast during the first initialization. The user is aware of what is happening. The reconnect part occurs only after the first boot.

How to test

  • Setup a cluster. I use:
git clone git@github.com:rabbitmq/rabbitmq-stream-go-client.git .
make rabbitmq-ha-proxy 
/etc/hosts
127.0.0.1 node0
127.0.0.1 node1
127.0.0.1 node2

* Part of #336

* Improve the disconnection message.
  It is possible to understand if it is a normal disconnection or an unexpected.
* Remove the Active Items from the connection pool and use the
  Publishers and Consumers client list directly to check the pool size
* Refactor the Factory Classes.
  Remove code duplication in case of metadata update and connection closed. See ReliableBase.OnEntityClosed
* Handle streamNotAvailable error.
  In this case the client will try to reconnect the entity
* Fix the events attach to the RawConsumer and RawProducer.
  The events are attached only if the ResponseCode is OK
* Detach the events once the entity receives the disconnection or metadata update.
  In that case, the entity is closed
* Introduce ReliableEntityStatus like a state machine to understand the status of Producer and Consumer classes
* Add ResourceAvailableReconnectStrategy interface to Handle the retry in case testing in a stream exists.
  See ReliableBase CheckIfStreamIsAvailable
* Change the  MetadataHandler to Func<MetaDataUpdate, Task> to be like the other methods
* Producer and Consumer classes fail fast during the first initialization.
  The user is aware of what is happening. The reconnect part occurs only after the first boot.

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
* clean the publishers and consumers list when a connection is removed
* restore pool tests
* more clear logs

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Attention: 81 lines in your changes are missing coverage. Please review.

Comparison is base (a7c9fd6) 92.83% compared to head (10a3f5c) 91.87%.

Files Patch % Lines
RabbitMQ.Stream.Client/Reliable/ReliableBase.cs 75.47% 21 Missing and 5 partials ⚠️
...bitMQ.Stream.Client/Reliable/IReconnectStrategy.cs 39.28% 17 Missing ⚠️
RabbitMQ.Stream.Client/Reliable/Producer.cs 52.00% 7 Missing and 5 partials ⚠️
RabbitMQ.Stream.Client/ClientExceptions.cs 16.66% 2 Missing and 3 partials ⚠️
RabbitMQ.Stream.Client/ConnectionsPool.cs 86.48% 3 Missing and 2 partials ⚠️
RabbitMQ.Stream.Client/Reliable/Consumer.cs 37.50% 3 Missing and 2 partials ⚠️
RabbitMQ.Stream.Client/StreamSystem.cs 80.00% 5 Missing ⚠️
RabbitMQ.Stream.Client/IConsumer.cs 0.00% 3 Missing ⚠️
RabbitMQ.Stream.Client/Client.cs 96.29% 0 Missing and 1 partial ⚠️
RabbitMQ.Stream.Client/Connection.cs 88.88% 0 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #343      +/-   ##
==========================================
- Coverage   92.83%   91.87%   -0.97%     
==========================================
  Files         116      116              
  Lines       11084    11065      -19     
  Branches      913      915       +2     
==========================================
- Hits        10290    10166     -124     
- Misses        595      694      +99     
- Partials      199      205       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Gsantomaggio Gsantomaggio marked this pull request as ready for review January 10, 2024 13:43
@lukebakken lukebakken self-requested a review January 10, 2024 15:51
lukebakken
lukebakken previously approved these changes Jan 10, 2024
Copy link
Contributor

@lukebakken lukebakken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tour @Gsantomaggio

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
@Gsantomaggio
Copy link
Member Author

@lukebakken Thanks for the help! Lock removed

@Gsantomaggio Gsantomaggio merged commit 7fa33dd into main Jan 11, 2024
2 checks passed
@Gsantomaggio Gsantomaggio deleted the check_stream_status branch January 11, 2024 07:29
@Gsantomaggio Gsantomaggio mentioned this pull request Jan 11, 2024
6 tasks
@Gsantomaggio Gsantomaggio added this to the 1.8.0 milestone Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants