Skip to content

Commit

Permalink
refactor: activityfactory
Browse files Browse the repository at this point in the history
  • Loading branch information
simaoribeiro committed Nov 14, 2023
1 parent 3e926e7 commit 9b9bb1b
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/KafkaFlow.Abstractions/ActivitySourceAccessor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace KafkaFlow
{
using System.Diagnostics;
using System.Reflection;
using System.Diagnostics;

Check warning on line 1 in src/KafkaFlow.Abstractions/ActivitySourceAccessor.cs

View workflow job for this annotation

GitHub Actions / Test deployment

Using directive should appear within a namespace declaration (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1200.md)

Check warning on line 1 in src/KafkaFlow.Abstractions/ActivitySourceAccessor.cs

View workflow job for this annotation

GitHub Actions / release

Using directive should appear within a namespace declaration (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1200.md) [/home/runner/work/kafkaflow/kafkaflow/src/KafkaFlow.Abstractions/KafkaFlow.Abstractions.csproj]

Check warning on line 1 in src/KafkaFlow.Abstractions/ActivitySourceAccessor.cs

View workflow job for this annotation

GitHub Actions / release

Using directive should appear within a namespace declaration (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1200.md) [/home/runner/work/kafkaflow/kafkaflow/src/KafkaFlow.Abstractions/KafkaFlow.Abstractions.csproj]

Check warning on line 1 in src/KafkaFlow.Abstractions/ActivitySourceAccessor.cs

View workflow job for this annotation

GitHub Actions / release

Field '_activityString' should not begin with an underscore (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1309.md) [/home/runner/work/kafkaflow/kafkaflow/src/KafkaFlow.Abstractions/KafkaFlow.Abstractions.csproj]

Check warning on line 1 in src/KafkaFlow.Abstractions/ActivitySourceAccessor.cs

View workflow job for this annotation

GitHub Actions / release

Field '_activitySource' should not begin with an underscore (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1309.md) [/home/runner/work/kafkaflow/kafkaflow/src/KafkaFlow.Abstractions/KafkaFlow.Abstractions.csproj]
using System.Reflection;

Check warning on line 2 in src/KafkaFlow.Abstractions/ActivitySourceAccessor.cs

View workflow job for this annotation

GitHub Actions / Test deployment

Using directive should appear within a namespace declaration (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1200.md)

namespace KafkaFlow
{
/// <summary>
/// ActivitySource properties
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/KafkaFlow/ActivityFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace KafkaFlow
{
internal class ActivityFactory : IActivityFactory
internal class ActivityFactory

Check warning on line 5 in src/KafkaFlow/ActivityFactory.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/KafkaFlow/ActivityFactory.cs#L5

Add a 'protected' constructor or the 'static' keyword to the class declaration.
{
public Activity Start(string topicName, ActivityOperationType activityOperationType, ActivityKind activityKind)
public static Activity Start(string topicName, ActivityOperationType activityOperationType, ActivityKind activityKind)
{
var activityName = !string.IsNullOrEmpty(topicName) ? $"{topicName} {activityOperationType}" : activityOperationType.ToString().ToLower();

Expand Down
1 change: 0 additions & 1 deletion src/KafkaFlow/Configuration/KafkaConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public KafkaConfiguration Build()
.AddSingleton<IConsumerAccessor>(new ConsumerAccessor())
.AddSingleton<IConsumerManagerFactory>(new ConsumerManagerFactory())
.AddSingleton<IClusterManagerAccessor, ClusterManagerAccessor>()
.AddSingleton<IActivityFactory, ActivityFactory>()
.AddSingleton(r =>
{
var logHandler = r.Resolve<ILogHandler>();
Expand Down
4 changes: 1 addition & 3 deletions src/KafkaFlow/Consumers/ConsumerWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ internal class ConsumerWorker : IConsumerWorker
private readonly IMiddlewareExecutor middlewareExecutor;
private readonly ILogHandler logHandler;
private readonly GlobalEvents globalEvents;
private readonly IActivityFactory activityFactory;

private readonly Channel<ConsumeResult<byte[], byte[]>> messagesBuffer;

Expand All @@ -39,7 +38,6 @@ public ConsumerWorker(
this.logHandler = logHandler;
this.messagesBuffer = Channel.CreateBounded<ConsumeResult<byte[], byte[]>>(consumer.Configuration.BufferSize);
this.globalEvents = this.dependencyResolver.Resolve<GlobalEvents>();
this.activityFactory = this.dependencyResolver.Resolve<IActivityFactory>();
}

public int Id { get; }
Expand Down Expand Up @@ -109,7 +107,7 @@ public void OnTaskCompleted(Action handler)

private async Task ProcessMessageAsync(ConsumeResult<byte[], byte[]> message, CancellationToken cancellationToken)
{
var activity = this.activityFactory.Start(message.Topic, ActivityOperationType.Process, ActivityKind.Consumer);
var activity = ActivityFactory.Start(message.Topic, ActivityOperationType.Process, ActivityKind.Consumer);

try
{
Expand Down
9 changes: 0 additions & 9 deletions src/KafkaFlow/IActivityFactory.cs

This file was deleted.

6 changes: 2 additions & 4 deletions src/KafkaFlow/Producers/MessageProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ internal class MessageProducer : IMessageProducer, IDisposable
private readonly IProducerConfiguration configuration;
private readonly MiddlewareExecutor middlewareExecutor;
private readonly GlobalEvents globalEvents;
private readonly IActivityFactory activityFactory;

private readonly object producerCreationSync = new();

Expand All @@ -27,7 +26,6 @@ public MessageProducer(
this.configuration = configuration;
this.middlewareExecutor = new MiddlewareExecutor(configuration.MiddlewaresConfigurations);
this.globalEvents = this.dependencyResolver.Resolve<GlobalEvents>();
this.activityFactory = this.dependencyResolver.Resolve<IActivityFactory>();
}

public string ProducerName => this.configuration.Name;
Expand All @@ -43,7 +41,7 @@ public async Task<DeliveryResult<byte[], byte[]>> ProduceAsync(

using var scope = this.dependencyResolver.CreateScope();

var activity = this.activityFactory.Start(topic, ActivityOperationType.Publish, ActivityKind.Producer);
var activity = ActivityFactory.Start(topic, ActivityOperationType.Publish, ActivityKind.Producer);

var messageContext = this.CreateMessageContext(topic, messageKey, messageValue, headers);

Expand Down Expand Up @@ -106,7 +104,7 @@ public void Produce(
{
var scope = this.dependencyResolver.CreateScope();

var activity = this.activityFactory.Start(topic, ActivityOperationType.Publish, ActivityKind.Producer);
var activity = ActivityFactory.Start(topic, ActivityOperationType.Publish, ActivityKind.Producer);

var messageContext = this.CreateMessageContext(topic, messageKey, messageValue, headers);

Expand Down

0 comments on commit 9b9bb1b

Please sign in to comment.