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

[Host.Kafka] Kafka consumers started twice on Host.Run #213

Closed
mib85 opened this issue Feb 19, 2024 · 3 comments · Fixed by #215
Closed

[Host.Kafka] Kafka consumers started twice on Host.Run #213

mib85 opened this issue Feb 19, 2024 · 3 comments · Fixed by #215

Comments

@mib85
Copy link

mib85 commented Feb 19, 2024

Hello,

I'm noticing unexpected behavior when using SlimMessageBus.Host.Kafka with .NET Generic Host.

When I run this code

using Microsoft.Extensions.Hosting;
using SlimMessageBus.Host;
using SlimMessageBus.Host.Kafka;

namespace SlimMessageBusTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Host.CreateDefaultBuilder(args)
                .ConfigureServices((_, services) =>
                {
                    services.AddSlimMessageBus(mbb =>
                    {
                        mbb.WithProviderKafka(cfg => cfg.BrokerList = "localhost:9092");
                    });
                })
                .Build()
                .Run();
        }
    }
}

I get this output on Console

info: SlimMessageBus.Host.Kafka.KafkaMessageBus[0]
      Creating producers
info: SlimMessageBus.Host.MessageBusBase[0]
      Starting consumers for Main bus...
info: SlimMessageBus.Host.MessageBusBase[0]
      Starting consumers for Main bus...
info: SlimMessageBus.Host.MessageBusBase[0]
      Creating consumers
info: SlimMessageBus.Host.MessageBusBase[0]
      Creating consumers
info: SlimMessageBus.Host.MessageBusBase[0]
      Started consumers for Main bus
info: SlimMessageBus.Host.MessageBusBase[0]
      Started consumers for Main bus
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production

It seems that the consumers are started twice.
I don't know if this is normal/managed behavior or if I should use a different configuration.

This is my csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.2" />
    <PackageReference Include="SlimMessageBus.Host.Kafka" Version="2.2.2" />
  </ItemGroup>
</Project>

I also noticed that when updating Microsoft.Extensions.Hosting.WindowsServices to version 8.0.0 this behavior does not occur and the consumers are started only once.

@zarusz
Copy link
Owner

zarusz commented Feb 19, 2024

Thanks for raising. Sounds like this is a bug. Let me try to replicate and look into this.

@zarusz zarusz changed the title Kafka consumers started twice on Host.Run [Host.Kafka] Kafka consumers started twice on Host.Run Feb 22, 2024
zarusz added a commit that referenced this issue Feb 28, 2024
Signed-off-by: Tomasz Maruszak <maruszaktomasz@gmail.com>
zarusz added a commit that referenced this issue Feb 28, 2024
Signed-off-by: Tomasz Maruszak <maruszaktomasz@gmail.com>
zarusz added a commit that referenced this issue Feb 28, 2024
Upgrade to latest libs
Adjust logging when starting consumers

Signed-off-by: Tomasz Maruszak <maruszaktomasz@gmail.com>
zarusz added a commit that referenced this issue Feb 29, 2024
Upgrade to latest libs
Adjust logging when starting consumers

Signed-off-by: Tomasz Maruszak <maruszaktomasz@gmail.com>
@zarusz
Copy link
Owner

zarusz commented Feb 29, 2024

hey @mib85 please check version 2.2.3 - it should be resolved. Please let me know if any issues. Thanks!

@mib85
Copy link
Author

mib85 commented Feb 29, 2024

Hi @zarusz. I did some tests and everything seems fine. Thank you very much!

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 a pull request may close this issue.

2 participants