V
V
Vlad2021-09-15 15:11:36
.NET
Vlad, 2021-09-15 15:11:36

How to organize the dispatcher and connection queue?

I can't figure out how best to write the application logic. I conditionally have a server that I want to connect to via REST in multiple threads. But the server can support only 4 sessions from one account at the same time. Created a fifth - one of the first four will be killed. Some requests are simple and fast, (sent a request) -> (read the response), others are slow (sent a request to complete the task) -> (checked the status of the task with the next request) -> (if ok, then sent the request and received a response). I suspect that some kind of dispatcher with a connection pool and (possibly) a request queue is needed here. But I don’t know if this will be a good solution, and whether it can be done better .. Again, it’s not clear whether to store a pool and take httpClient from it, or store the number of available (remaining) connections in a variable that will be locked upon access..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-09-15
@vabka

The request queue can be implemented via System.Threading.Channels.
To prevent sessions from falling off, run exactly four tasks that will rake up the channel.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question