apache-kafkawcf-bindingcorewcf

Is CoreWCF supports KafkaBinding?


Is CoreWCF supports KafkaBinding ? Is yes - Can someone please share the steps I need to follow in client side ? I could not able to find a way to create channel factory for Kafka Binding and make server calls ?

Channel factory should be created for Kafka binding and able to make server calls


Solution

  • I think it supports KafkaBinding.

    1.There is a package for it on Nuget

    CoreWCF.Kafka

    2.Binding generation and service injection can refer to the following code:

    var binding = new KafkaBinding(KafkaDeliverySemantics.AtMostOnce)
    {
        AutoOffsetReset = AutoOffsetReset.Earliest,
        GroupId = "my-group"
    };
    var customBinding = new CustomBinding(binding);
    KafkaTransportBindingElement transport = customBinding.Elements.Find<KafkaTransportBindingElement>();
    transport.Debug = "all";
    
    var builder = WebApplication.CreateBuilder();
    builder.Services.AddServiceModelServices().AddQueueTransport()
    
    var app = builder.Build();
    
    app.UseServiceModel(serviceBuilder => 
    {
        services.AddService<Service>();
        services.AddServiceEndpoint<Service, IService>(new CoreWCF.Kafka.KafkaBinding
        {
            AutoOffsetReset = AutoOffsetReset.Earliest,
            DeliverySemantics = KafkaDeliverySemantics.AtMostOnce,
            GroupId = "my-consumer-group"
        }, $"net.kafka://localhost:9092/my-topic");
    });
    
    CoreWCF.ServiceModel.Channels.KafkaBinding kafkaBinding = new();
    var factory = new System.ServiceModel.ChannelFactory<IService>(kafkaBinding,
        new System.ServiceModel.EndpointAddress(new Uri($"net.kafka://localhost:9092/my-topic")));
    IService channel = factory.CreateChannel();
    await channel.CallServiceAsync(name);