sizovs / PipelinR

PipelinR is a lightweight command processing pipeline ❍ ⇢ ❍ ⇢ ❍ for your Java awesome app.
https://github.com/sizovs/PipelinR
MIT License
420 stars 59 forks source link

Question: Using Pipeline within a handler to call another handler? #31

Closed david-randoll closed 1 year ago

david-randoll commented 1 year ago

Is possible from a Command.Handler to inject Pipeline and to call another handler?

I am using Spring boot.

david-randoll commented 1 year ago

After 5 hours, I going to answer my own question to yes.

The below broke my code. I was passing in JPA Entity here that has one too many relationships and thru object mapper a stack overflow error was thrown.

@Component
@Order(1)
@Slf4j
class LoggingMiddleware implements Command.Middleware {
    @Override
    public <R, C extends Command<R>> R invoke(C command, Next<R> next) {
        var requestJsonString = objectMapper.valueToTree(command).toString();
        var commandName = command.getClass().getName();
        log.info("Start {}: {}", commandName, requestJsonString);

        R response = next.invoke();

        var responseJsonString = objectMapper.valueToTree(response).toString();
        log.info("End {}: {}", commandName, responseJsonString);

        return response;
    }
}

Love this library. Coming from .NET makes it tolerable to work with Java haha.