-
Notifications
You must be signed in to change notification settings - Fork 41
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
Event bus [Proposal] #320
Event bus [Proposal] #320
Conversation
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #320 +/- ##
==========================================
+ Coverage 92.66% 92.73% +0.07%
==========================================
Files 113 116 +3
Lines 9961 10195 +234
Branches 825 840 +15
==========================================
+ Hits 9230 9454 +224
- Misses 555 562 +7
- Partials 176 179 +3
☔ View full report in Codecov by Sentry. |
Looks good. We will need to execute async code when the events are raised. Do you think the we could have async subscriptions aswell? So the registered action would be a |
Yes |
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
I think this proposal covers our operational needs. But I am not certain which events the "Reconnecting" state would entail. From the WIP code, it looks like there are two event types: Connection and Disconnection. I assume that, if modelled as a state machine, a Producer would start off in |
@TroelsL this was just a proposal. Of course, we will add other types like:
etc... |
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>
It is still a work in progress. So given:
And: var streamSystem = await StreamSystem.Create(new StreamSystemConfig());
await streamSystem.CreateStream(new StreamSpec("my-stream"));
IEventBus bus = new StreamEventsBus();
bus.Subscribe<RawProducerConnected>(async connected =>
{
myLogger.LogInformation(
"The raw producer {ClientProvidedName} is connected to the stream {Stream}",
connected.Parameters.ClientProvidedName, connected.Instance.Info.Stream);
await Task.CompletedTask;
});
bus.Subscribe<RawProducerDisconnected>(async disconnected =>
{
myLogger.LogInformation(
"The raw producer {ClientProvidedName} is disconnected from the stream {Stream}",
disconnected.Parameters.ClientProvidedName, disconnected.Instance.Info.Stream);
await Task.CompletedTask;
});
bus.Subscribe<ProducerReconnected>(async reconnected =>
{
var value = (reconnected.IsReconnection) ? "is in reconnection.." : "ended the reconnection";
myLogger.LogInformation("The producer {ClientProvidedName} {Value} to the stream {Stream}", reconnected.Instance.Info.ClientProvidedName, value, reconnected.Instance.Info.Stream);
await Task.CompletedTask;
});
var superStreamProducer = await Producer.Create(new ProducerConfig(streamSystem, SystemUtils.InvoicesExchange)
{
SuperStreamConfig = new SuperStreamConfig()
{
Routing = message => message.Properties.MessageId.ToString(),
RoutingStrategyType = RoutingStrategyType.Hash
},
ClientProvidedName = "my_super_producer",
Events = bus,
});
var standardProducer = await Producer.Create(new ProducerConfig(streamSystem, "my-stream")
{
ClientProvidedName = "my_producer",
Events = bus,
});
for (ulong i = 0; i < 2000; i++)
{
var message = new Message(Encoding.Default.GetBytes("hello"))
{
Properties = new Properties() {MessageId = $"hello{i}"}
};
await superStreamProducer.Send(message);
Thread.Sleep(1 * 1000);
}
} The connection part for the super stream is:
for the standard stream is:
I case I kill the standard producer connection the events will be:
The behaviour for the super stream is a bit different: the connection is re-created as soon a message is sent to the partition stream. The basic idea is to define your bus with the subscriptions you want to listen to and handle it with different information. The bus is an interface |
closed in favour of #336 |
ref: #316
The idea of this implementation is to have the possibility to subscribe to a partial event.
so like:
and somewhere to subscribe to the event based on the type, like:
In this way we can implement different events with detailed information and (why not ) with the class instance that raised the event, for example: