Applying backpressure to a flow by blocking in the MessageEventHandler
I have a few days of free time and so I am developing a new branch of my Solace subscriber wrapper library. I thought I'd play with exposing the message stream as an
I decided to use a
System.Threading.Channels.Channel with a bounded capacity for this. The idea is to (usually) quickly let the message event handler post to the channel even if the subscriber processing is occasionally a bit tardy. However, there may be times when bursty message rates cause the channel buffer to fill up. In those cases I want to apply back pressure to the solace components.
One way I could do this would be to actually disconnect the flow when the local buffer is full and reconnect once it has drained, but this seems like an expensive proposition that would require a lot of additional code. As an alternative, I was wondering what would happen if the message event handler simply blocked. To be clear, this would be an "atypical" situation, the idea would not be to block except in cases where the subscriber's message processing is itself slowed down unexpectedly.
In other words, what if the message event handler is:
// buffer is the Channel (_, args) => buffer.Writer.WriteAsync(args, ct).AsTask().Wait()
Channel in this way would cause this function to hang if the channel buffer is full.
Will this in fact apply back pressure through the solace components, or does the library spin off invocation to the threadpool (in which case this could result in threadpool exhaustion in extreme cases)?
I believe I could also partly manage this via the guaranteed message window size and max delivered unacked messages, but If I want to allow subscribers to have some control over their own buffers without exposing too much of the solace internal machinery, this question still arises.
As a corollary, I'm curious about the
AckTimerInMsecs flow property. Is this the maximum amount of time the broker will wait for acknowledgement of a message before deciding it needs to be redelivered? Buecase 1000 milliseconds is awfully short if I want to be able to do any kind of processing before acknowledgement.