I am working to build a producer..consumer pattern using .NET reactive. Producer reads messages from Kafka message bus. Once the message is read, it needs to be handed over to the consumer to process the message.
I was able to do that using .NET reactive extensions (observable and observer). However, I will like to handle a scenario where the messages are read faster from the bus and consumer is falling behind. I will like the observable to react to back-pressure i.e. if observable indicates that it is still processing earlier messages, slow down the observable.
// Create a subject of my custom object and make it observable
private readonly Subject<MyMessage> messageSubject = new Subject<MyMessage>();
messageSubject.AsObservable();
// add observer to the subject
_onMessageObservable.ObserveOn(NewThreadScheduler.Default)
// On receive of message, notify the observer
messageSubject.OnNext(msg.Value);