GH-2062 Add logic to log an error for reactive functions

Resolves #2062
This commit is contained in:
Oleg Zhurakousky
2020-12-07 16:25:00 +01:00
parent 6f867ad87f
commit 3244fc5274
2 changed files with 20 additions and 0 deletions

View File

@@ -472,6 +472,9 @@ public class FunctionConfiguration {
}
outputChannel.send((Message) message);
}
}).doOnError(e -> {
logger.error("Failure was detected during execution of the reactive function '" + functionDefinition + "'");
((Throwable) e).printStackTrace();
});
}
if (!function.isConsumer()) {

View File

@@ -909,6 +909,20 @@ public class ImplicitFunctionBindingTests {
}
@Test
public void testGh2062() {
System.clearProperty("spring.cloud.function.definition");
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
TestChannelBinderConfiguration.getCompleteConfiguration(ReactiveFunctionConfiguration.class))
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false",
"--spring.cloud.function.definition=echo")) {
InputDestination inputDestination = context.getBean(InputDestination.class);
String jsonPerson = "error";
inputDestination.send(MessageBuilder.withPayload(jsonPerson.getBytes()).build());
// there is really nothing to assert other then check the logs for stack trace and error message
}
}
@SuppressWarnings("rawtypes")
@Test
@@ -1181,6 +1195,9 @@ public class ImplicitFunctionBindingTests {
public Function<Flux<String>, Flux<String>> echo() {
return flux -> flux.map(value -> {
System.out.println("echo value reqctive " + value);
if (value.equals("error")) {
throw new RuntimeException("intentional");
}
return value;
});
}