Search code examples
spring-integration

Spring Integration Jdbc StoredProcMessageHandler Pretty Log Procedure Request and Response


Tried enabling DEBUG in CallMetaDataContext, however need to find a way to pretty print the Stored Proc IN and OUT parameter with values. Please suggest

Also, would it be considered OK / acceptable if we use .handle("someBean", "someMethodUsingJdbcTemplate") instead of StoredProcMessageHandler. The reason is former helps me with pretty logging using JdbcTemplate

Pretty Logging using JdbcTemplate:

@PostConstruct
public void init() {

    // @formatter:off
    simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName(STORED_PROC)
                                                    .withoutProcedureColumnMetaDataAccess() // this is optional
                                                    .returningResultSet("REF_CURSOR_NAME_FROM_STORED_PROC", null); // this is optional
    // @formatter:on

    simpleJdbcCall.addDeclaredParameter(new SqlParameter("IN_PARAM_1", Types.VARCHAR));
    simpleJdbcCall.addDeclaredParameter(new SqlParameter("IN_PARAM_2", Types.VARCHAR));
}

private Map<String, Object> constructCallParams(final Object dtoObject) {

    Map<String, Object> callParams = new LinkedHashMap<>();
    callParams.put("IN_PARAM_1", dtoObject.field1());
    callParams.put("IN_PARAM_2", dtoObject.field2());

    return callParams;
}

public Mono<Void> fetch(final String request) {

    Map<String, Object> callParams = constructCallParams(null);

    // @formatter:off
    return Mono.fromCallable(() -> simpleJdbcCall.execute(callParams))
                .subscribeOn(Schedulers.boundedElastic())
                .doOnError(ex -> log.error("{} InParams: {}, Exception: {}", STORED_PROC, callParams, ex.getMessage()))
                .onErrorMap(ApplicationException::new) // optional
                .flatMap(outParams -> {
                    log.info("{} InParams: {}, OutParams: {}", STORED_PROC, callParams, outParams);
                    return Mono.empty();
                });
        // @formatter:on
    }

Solution

  • Yes, you can use a handle() for any custom method invocation - the service activator pattern. A StoredProcMessageHandler is just an out-of-the-box convenient for some use-case a service activator implementation. Please, share with us how you do that pretty logging using JdbcTemplate. Probably something like public StoredProcExecutor(JdbcTemplate jdbcTemplate) { to expose would be enough for you to keep that pretty logging and still use a StoredProcMessageHandler. Feel free to raise a GH issue about this new constructor!