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

Add event status changed #349

Merged
merged 7 commits into from
Jan 30, 2024
Merged

Add event status changed #349

merged 7 commits into from
Jan 30, 2024

Conversation

Gsantomaggio
Copy link
Member

@Gsantomaggio Gsantomaggio commented Jan 26, 2024

Expose the event config.StatusChanged where it is possible to monitor and react with the internal status.

/// <summary>
/// StatusInfo is the information about the change status of the ReliableEntity
/// </summary>
/// <param name="From">The previous entity status </param>
/// <param name="To"> The new status </param>
/// <param name="Stream"> Stream or SuperSuper affected</param>
/// <param name="Identifier"> The Entity Identifier </param>
/// <param name="Partition"> Super stream partition. Valid only for SuperStream else is empty</param>
public record StatusInfo(
    ReliableEntityStatus From,
    ReliableEntityStatus To,
    string Stream,
    string Identifier,
    string Partition
);

It is possible to interact with the internal status, for example in case of producer you can decide to stop producing messages, like:

 producerConfig.StatusChanged += (status) =>
                        {
                            var streamInfo = status.Partition is not null
                                ? $" Partition {status.Partition} of super stream: {status.Stream}"
                                : $"Stream: {status.Stream}";

                            lp.LogInformation("Producer: {Id} - status changed from {From} to {To}. {Info}",
                                status.Identifier,
                                status.From,
                                status.To, streamInfo);

                            if (status.To == ReliableEntityStatus.Open)
                            {
                                publishEvent.Set();
                            }
                            else
                            {
                                publishEvent.Reset();
                            }
                        };

and:

async Task MaybeSend(Producer producer, Message message, ManualResetEvent publishEvent)
{
   publishEvent.WaitOne();
   await producer.Send(message).ConfigureAwait(false);
}

Expose the event config.StatusChanged where it is possible to
monitor and react with the internal status.

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

codecov bot commented Jan 27, 2024

Codecov Report

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

Comparison is base (85c220a) 92.08% compared to head (2767f37) 92.15%.

Files Patch % Lines
RabbitMQ.Stream.Client/Reliable/ReliableBase.cs 85.00% 6 Missing ⚠️
RabbitMQ.Stream.Client/Reliable/Consumer.cs 66.66% 1 Missing ⚠️
RabbitMQ.Stream.Client/Reliable/Producer.cs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #349      +/-   ##
==========================================
+ Coverage   92.08%   92.15%   +0.07%     
==========================================
  Files         116      116              
  Lines       11366    11622     +256     
  Branches      899      907       +8     
==========================================
+ Hits        10466    10710     +244     
- Misses        691      708      +17     
+ Partials      209      204       -5     

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

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
@Gsantomaggio Gsantomaggio marked this pull request as ready for review January 29, 2024 13:41
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>
@Gsantomaggio Gsantomaggio merged commit d70458a into main Jan 30, 2024
2 checks passed
@Gsantomaggio Gsantomaggio deleted the events_for_reliable_classes branch January 30, 2024 14:41
@Gsantomaggio Gsantomaggio mentioned this pull request Jan 30, 2024
6 tasks
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.

None yet

1 participant