question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I implement a producer inside a web api project

See original GitHub issue

Description

I am trying to implement a producer inside a .NET framework WebAPI project. I found one of the threads #360 where I found a solution.

public class KafkaClient : IKafkaClient
{
    private Producer<string, string> producer;

    public KafkaClient(IConfiguration globalconf)
    {
        var config = new Dictionary<string, object>
        {
            { "bootstrap.servers", "http://localhost:9092" }
        };

        producer = new Producer<string, string>(config, new StringSerializer(Encoding.UTF8), new StringSerializer(Encoding.UTF8));
    }

    public async Task<Message<string, string>> Produce(string key, string val)
    {
        var resp = await producer.ProduceAsync("QuoteTest", key, val);
        return resp;
    }
}

Now when I call the produce method from the action method using await producer.Produce("hello1", "world1") It takes a long time and then returns a “Local: Message timed out” error. However this exact same piece of code works when I use it in a .NET Console app. I have tried implementing this in .NET Core 2.0 WebAPI project but I face the same issue. Here is the response object from the Produce method image

How to reproduce

Implement the above code snippet inside a .NET framework/Core 2.0 WebAPI project and call the method from an action.

Checklist

Please provide the following information:

  • Confluent.Kafka nuget version: 0.116
  • Apache Kafka version: 2.12-2.2.0
  • Client configuration: .NET framework WebAPI project
  • Operating system: Win 10

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mhowlettcommented, Apr 1, 2019

it would be a good feature for us to do a runtime check for this. note that kafka has a custom binary protocol, doesn’t use http.

0reactions
souptikmakarovcommented, Apr 2, 2019

Thanks for the info!

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Simple Organization for ASP.NET Web API Producer/ ...
Building the MVC API Client​​ RestRequest request = new RestRequest("users/all"); This line creates a RestRequest object which is pointed at the ...
Read more >
Working with Apache Kafka in ASP.NET 6 Core
In the “Create a new project” window, select “ASP.NET Core Web API” and click Next to move on. Specify the project name as...
Read more >
.Net Core - C# Web API with Apache Kafka Integration
Create a .NET Core console application on an existing/new solution and add a class Class “MyKafkaConsumer”; Nuget install “Confluent.
Read more >
Tutorial: Create a web API with ASP.NET Core
From the File menu, select New > Project. · Enter Web API in the search box. · Select the ASP.NET Core Web API...
Read more >
Building Real-time Streaming Applications Using .NET ...
Step 4: Use Confluent's “Producer” class to connect and produce messages to KAFKA.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found