I recently wanted to add a new behavior in my project that uses spring-kafka. The idea is really simple : App1 create a new scenario name “SCENARIO_1” and publish this string in the topic “NEW_SCENARIO” App1 publish some message on topic “APP2-SCENARIO_1” and “APP3-SCENARIO_1” App2 (group-id=app2) listens on NEW_SCENARIO and creates a new consumer<Object,String> listening on a new topic “APP2-SCENARIO_1”
Tag: consumer
incompatible types: bad return type in lambda expression | void is not a functional interface
I am going through Java 8 Feature and using Jshell to explore it. I tried to run the below command: But it failed with the below error: I didn’t get exactly what’s the issue Consumer takes one argument and return nothing. Same I am doing here by passing 1 arg str and printing. So what’s the issue with this syntax.
How to throw an Exception in a Consumer Java 8
Is there any way to throw an Exception while using a consumer in java 8? For example: This gives me a compiler error saying: Unhandled exception type Exception What is the correct way to throw an exception in this case? Answer Since Exception and its subclass (other than RuntimeException) are checked Exception and in lambda, you can’t throw checked exception.
Does the JDK provide a dummy consumer?
I have a need in a block of code to consume ‘n’ items from a stream then finish, in essence: In my situation, I can’t change the signature to return Stream<T> and simply return stream.skip(n); I have to actually throw away some elements from the stream (not simple logic) – to be ready for a down stream consumer which doesn’t