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

Include EventHub and option to SubscribeGlobalEvents #445

Closed
wants to merge 18 commits into from

Conversation

simaoribeiro
Copy link
Contributor

Description

Includes EventHub and option to SubscribeGlobalEvents in KafkaConfigurationBuilder

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests to cover my changes
  • I have made corresponding changes to the documentation

@simaoribeiro simaoribeiro changed the base branch from master to release/3.0 October 4, 2023 15:43
{
public IMessageContext MessageContext { get; set; }

public IDependencyResolver DependencyResolver { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

no setters and initialization from ctor. Or just use a record, now we can :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to use a record but my VS kept saying that I couldn't use C#9 features in .netstandard2.0 projects 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, please review

var middlewareContext = this.workerDependencyResolverScope.Resolver.Resolve<ConsumerMiddlewareContext>();
this.eventHub = this.workerDependencyResolverScope.Resolver.Resolve<IEventHub>() as EventHub;
Copy link
Contributor

Choose a reason for hiding this comment

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

this.workerDependencyResolverScope.Resolver.Resolve<EventHub>()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, please review

await this.eventHub.FireMessageConsumeStartedAsync(
new MessageEventContext
{
DependencyResolver = this.workerDependencyResolverScope.Resolver,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we don't need the Resolver here, since we have it in the IMessageContext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we remove the IDependencyResolver from the MessageEventContext class given that, currently, it only contains the IMessageContext and IDependencyResolver objects? 🤔 And only include it later if needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's it 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up keeping as it was and included a constructor with only the IMessageContext


public Event(ILogHandler logHandler)
{
this.logHandler = logHandler;
}

public IEventSubscription Subscribe(Func<TArg, Task> handler)
public void Subscribe(Func<TArg, Task> handler)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the IEventSubscription was removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error in the rebase process. Solved now

@simaoribeiro simaoribeiro marked this pull request as ready for review October 9, 2023 10:14
Copy link
Contributor

@ruiqbarbosa ruiqbarbosa left a comment

Choose a reason for hiding this comment

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

Should some tests be added to cover the new SubscribeGlobalEvents configuration?

@@ -20,7 +20,7 @@ public interface IEvent
/// Represents an Event to be subscribed.
/// </summary>
/// <typeparam name="TArg">The argument expected by the event.</typeparam>
public interface IEvent<TArg>
public interface IEvent<out TArg>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a covariant generic here?

public void AddClusters(IEnumerable<ClusterConfiguration> configurations) =>
this.clusters.AddRange(configurations);
}
internal void AddClusters(IEnumerable<ClusterConfiguration> configurations) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a reason to move this to internal?

There is an issue in KafkaFlow where the AddClusters method was suggested as a workaround. This change could break those use cases.

return this;
}

public IKafkaConfigurationBuilder SubscribeGlobalEvents(Action<IGlobalEvents> builder)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename the parameter to observers to be consistent with the interface.

@@ -91,7 +91,7 @@ public interface IConsumerContext
/// By default, this method is automatically invoked when message processing concludes, unless
/// the consumer is configured for manual message completion or the <see cref="AutoMessageCompletion"/> flag is set to false.
/// </summary>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider adding the following suggestion:

Suggested change
/// </summary>
/// </summary>
/// <param name="context">The message context</param>

@@ -4,14 +4,15 @@ namespace KafkaFlow.Consumers
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using KafkaFlow.Configuration;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider removing the unnecessary using

Copy link
Contributor

@erik-catalao erik-catalao left a comment

Choose a reason for hiding this comment

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

LGTM

public Task FireMessageConsumeStartedAsync(MessageEventContext context)
=> this.messageConsumeStarted.FireAsync(context);

public Task FireMessageConsumeCompletedAsync(MessageEventContext context)
Copy link
Contributor Author

@simaoribeiro simaoribeiro Oct 18, 2023

Choose a reason for hiding this comment

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

Ailton asked:
"Why not to expose the FireAsync in the IEvent interface and reduce the complexity for calling the event?"
#451 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

8 participants