{"action":"created","issue":{"url":"https://api.github.com/repos/reactor/reactor-core/issues/73","repository_url":"https://api.github.com/repos/reactor/reactor-core","labels_url":"https://api.github.com/repos/reactor/reactor-core/issues/73/labels{/name}","comments_url":"https://api.github.com/repos/reactor/reactor-core/issues/73/comments","events_url":"https://api.github.com/repos/reactor/reactor-core/issues/73/events","html_url":"https://github.com/reactor/reactor-core/issues/73","id":151147586,"number":73,"title":"Ability to signal error upstream (nack) without cancelling/completing","user":{"login":"dfeist","id":380765,"avatar_url":"https://avatars.githubusercontent.com/u/380765?v=3","gravatar_id":"","url":"https://api.github.com/users/dfeist","html_url":"https://github.com/dfeist","followers_url":"https://api.github.com/users/dfeist/followers","following_url":"https://api.github.com/users/dfeist/following{/other_user}","gists_url":"https://api.github.com/users/dfeist/gists{/gist_id}","starred_url":"https://api.github.com/users/dfeist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dfeist/subscriptions","organizations_url":"https://api.github.com/users/dfeist/orgs","repos_url":"https://api.github.com/users/dfeist/repos","events_url":"https://api.github.com/users/dfeist/events{/privacy}","received_events_url":"https://api.github.com/users/dfeist/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-26T14:19:27Z","updated_at":"2016-04-26T14:58:14Z","closed_at":null,"body":"Often when processing streams of messages from an external source there is a need to ack/nack the message.  When using a blocking API execution stack return implies you can ack and an exception being thrown (depending on type potentially) typically implies you need to nack.\r\n\r\nWhen using using a reactive API it is much harder to determine when to ack/nack and I don't see any way in which the framework (reactor) helps with this, neither how I'd go about doing it myself really.  \r\n\r\nTake this example:\r\n`JMS.queue(\"in\").map(msg -> processMsg(msg)).consume(System.out::println)`\r\n\r\nIf `processMsg` fails with an exception processing should not continue and the message should not be printed to the console, and at the same time this message should be nacked by the `JMS.queue` publisher.\r\n\r\nDiscussed a couple of options with @smaldini , but none of them ideal or even easily workable.. \r\n\r\n1. **Use Value<T> holder for success/error value**.  This approach isn't suitable because the next subscriber will be notified and this conflicts with the requirement above.\r\n\r\n2. **Use `Exceptions.bubble(e)`.** This may work, but has a number of significant concerns:\r\n i) Throwing exceptions upstream like this is really reserved for fatal exceptions only\r\n ii) This approach requires the use of try/catch blocks and is not a programming model that is really compatible with everything else.\r\niii) What happens wen there are thread boundaries.\r\niv) https://github.com/reactor/reactor-core/issues/74\r\n\r\n3. **Use a ErrorHandler within Message**\r\nA more manual approach is to pass a ErrorHandler within the message being processed which is invoked on error. But this has it's own issues:\r\n i) If errors aren't thrown as exception then onNext() returning cannot be used to ack, so CompletionHandler is needed rather than ErrorHandler.\r\nii) How/when is onSucess() invoked? would need to add something non-transparent to the end of the stream to do this.\r\niii) How/when is onError() invoked? Can't just do it at the end of stream..\r\n"},"comment":{"url":"https://api.github.com/repos/reactor/reactor-core/issues/comments/214773204","html_url":"https://github.com/reactor/reactor-core/issues/73#issuecomment-214773204","issue_url":"https://api.github.com/repos/reactor/reactor-core/issues/73","id":214773204,"user":{"login":"akarnokd","id":1269832,"avatar_url":"https://avatars.githubusercontent.com/u/1269832?v=3","gravatar_id":"","url":"https://api.github.com/users/akarnokd","html_url":"https://github.com/akarnokd","followers_url":"https://api.github.com/users/akarnokd/followers","following_url":"https://api.github.com/users/akarnokd/following{/other_user}","gists_url":"https://api.github.com/users/akarnokd/gists{/gist_id}","starred_url":"https://api.github.com/users/akarnokd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akarnokd/subscriptions","organizations_url":"https://api.github.com/users/akarnokd/orgs","repos_url":"https://api.github.com/users/akarnokd/repos","events_url":"https://api.github.com/users/akarnokd/events{/privacy}","received_events_url":"https://api.github.com/users/akarnokd/received_events","type":"User","site_admin":false},"created_at":"2016-04-26T14:58:14Z","updated_at":"2016-04-26T14:58:14Z","body":"The problem is you have a per-value lifecycle and Reactive-Streams can't deal with it. The same issue appears with pooled ByteBuffers in I/O libraries where someone has to release the buffer once all stages have processed it and goes \"out of scope\".\r\n\r\nThe closest thing is what I call `umap` in Reactive-IO where you provide a transform for some upstream sequence and all participating object's lifecycle ends when the transformation terminates. In this context, you'd have:\r\n\r\n```java\r\nFlux<Void> JMS.queue(String topic, Function<Flux<Message>, Publisher<?>> umap);\r\n```\r\n\r\n(Note, however, that fatal exceptions break this too.)"}}