2

I have a situation when I receive messages from a 3rd party system, that guarantees delivery of the messages. In order to do that it requires the client to acknowledge each received message. An example of such system might be RibbitMQ.

Now, I know that there is the backpressure mechanism in Monix's Observables, which immediately makes me want to use it for acknowledging messages. In other words, I want to create an observable, such that when onNext returns Ack.Continue, I acknowledge that message to the external system. Bellow is the simple outline of my idea.

Observable.create[Event](OverflowStrategy.Fail(100)) { downstram =>
  externaSystem.subscribe { event =>
    downstram.onNext(event).onComplete {
      case Success(Ack.Continue) => externaSystem.acknowledge(event)
      case _ => externaSystem.reset(event)
    }
  }
  Cancelable { () => externaSystem.stop() }
}

The whole idea, of course, is to avoid losing any of the messages and only acknowledge them when an observer actually returns Ack.Continue. However, I noticed several cases, when Monix takes care of managing backpressure of an observable, for example, when I multicast, share etc. the observers. In that case the original observable receives Ack.Continue without waiting for the intended subscriber's response.

That all brought me to the question if actually acknowledging the messages on the 3rd party side system using Monix backpressure mechanism as at all a good idea, and if so, are there any cautions I need to be aware of (like not to multicast such an observer)

I will appreciate any help and thank you very much for advance.

Andrew Slabko
  • 690
  • 8
  • 15
  • 1
    You can't really use back pressure for that purpose. Back pressure only manages the content of the pipeline up to the next stage where the back pressure regime changes. To properly acknowledge a message to your supplier, you have to understand what it means by "delivered". – Bob Dalgleish Jun 19 '18 at 16:32

0 Answers0