rabbitmq / rabbitmq-stream-dotnet-client

RabbitMQ client for the stream protocol
https://rabbitmq.github.io/rabbitmq-stream-dotnet-client/stable/htmlsingle/index.html
Other
122 stars 41 forks source link

Add event status changed #349

Closed Gsantomaggio closed 9 months ago

Gsantomaggio commented 10 months ago

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);
}
codecov[bot] commented 10 months ago

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 :warning:
RabbitMQ.Stream.Client/Reliable/Consumer.cs 66.66% 1 Missing :warning:
RabbitMQ.Stream.Client/Reliable/Producer.cs 66.66% 1 Missing :warning:
Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.