How do I implement a producer inside a web api project
See original GitHub issueDescription
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
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:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Thanks for the info!