Comments (5)
The consumer and producers both keep consistent connections to the kafka servers at all times. This means you will have to store them statically and then broker requests from the website through these static objects. You don't specify what you are trying to do with your MVC project, but there are some other REST based versions of the driver out there that you can reference.
from kafka-net.
Hi Jroland,
I am facing similar problem. If I try to copy code from program.cs (that calls SendMessageAsync on producer object) from console app to 'any web app (be it asp.net or mvc)', it does not work. How can i make it work?
Could you please elaborate the proposed solution 'storing producer/consumers in static objects' in web context.
Thanks In Advance
Balesh Kumar
from kafka-net.
Hi,
I had same problem using library in web-app but managed to get it done.
here is extract from link http://msdn.microsoft.com/en-us/magazine/jj991977.aspx
The root cause of this deadlock is due to the way await handles contexts. By default, when an incomplete Task is awaited, the current “context” is captured and used to resume the method when the Task completes. This “context” is the current SynchronizationContext unless it’s null, in which case it’s the current TaskScheduler. GUI and ASP.NET applications have a SynchronizationContext that permits only one chunk of code to run at a time. When the await completes, it attempts to execute the remainder of the async method within the captured context. But that context already has a thread in it, which is (synchronously) waiting for the async method to complete. They’re each waiting for the other, causing a deadlock.
Note that console applications don’t cause this deadlock. They have a thread pool SynchronizationContext instead of a one-chunk-at-a-time SynchronizationContext, so when the await completes, it schedules the remainder of the async method on a thread pool thread. The method is able to complete, which completes its returned task, and there’s no deadlock. This difference in behavior can be confusing when programmers write a test console program, observe the partially async code work as expected, and then move the same code into a GUI or ASP.NET application, where it deadlocks.
Basically in public async Task<List> SendMessageAsync(......) function
change the context inside this function using following call.
await Task.FromResult(1).ConfigureAwait(continueOnCapturedContext: false);
function run asynchronously, this get me working.
Thanks
Atul.
from kafka-net.
What LoonaA wrote sounds great, and sounds like a solution to a specific async threading issue with a web project. However I want to reiterate my comment above. There is significant overhead in connecting to the kafka server and establishing a connection. You should not create a new producer and consumer for each web call. A static (singleton) producer and consumer should be created and then all calls from the web should be brokered through this object.
from kafka-net.
Hi Jroland,
I am facing similar problem. If I try to copy code from program.cs how can i use in asp.net context.
Could you please elaborate the proposed solution 'storing producer/consumers in web context.
Thanks & Regards
Nagendra Singh
from kafka-net.
Related Issues (20)
- kafka-net for .NET Core HOT 2
- Max message size 4096 bytes? HOT 1
- OOM error
- Current development status ? HOT 1
- Does this library already contain support for Kafka Streams introduced in Kafka 0.10 HOT 1
- Send producer problem when the service broker is offline HOT 1
- Kafka-net Producer hangs When Sending Inside ArcMap
- Best way to persist and start from a Offset HOT 1
- "This protocol version is not supported." HOT 1
- Is it possible to alter the Whitelist while consuming messages?
- Can i use this library for open tracing using zipkin
- I am getting KafkaNet.Protocol.ResponseTimeoutException when sending data to kafka topic.Is there any way to overcome this issue?
- SendMessageAsync of Producer not completing
- hotspot issue with sendMessageAsync on partition level HOT 1
- It cannot connect to the localhost:9092
- kafka-net .Net Core version HOT 1
- How to List all Topics
- Support of StreamsAPI or connector API
- Buffer underrun. Increasing buffer size
- Kafka Cluster Issue when API Version =1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kafka-net.