복붙노트

[SPRING] 주석 통합 코드를 사용하는 Spring Integration Executor 채널

SPRING

주석 통합 코드를 사용하는 Spring Integration Executor 채널

내 시스템 다이어그램이 첨부됩니다.

시스템 다이어그램

어떻게 작동 하는가 :

스프링 통합 흐름은 C : \의 json 파일에서 입력을 읽고 다음 두 가지 작업을 수행합니다.

중요도 :

나는 상점을 비즈니스 로직 (사용자에게 인쇄 / 통지)과 독립적으로 DB 플로우에 포함 시키길 원한다. 즉, DB 예외 / DB 성공은 사용자에게 영향을 미치지 않아야한다.

마찬가지로 사용자에게 db flow에 영향을 미치지 않아야 함을 알립니다.

내가 브라우징했고 다른 스레드에 'DB에 저장'을 위임하기 위해 executor 채널을 사용해야한다는 것을 알았습니다.

실행 채널에 대한 코드 샘플을 찾을 수 없습니다. 다른 모든 클래스는 주석을 기반으로하므로 ANNOTATION 기반 코드 만 필요합니다.

필요한 항목 : ExecutorChannel의 코드 샘플 - 주석 기반.

코드 2 (파일에서 json을 읽고이를 DB, 사용자 정의 비즈니스 로직으로 전송)

@Bean
public IntegrationFlow readFromJSONFile() {
    return IntegrationFlows
            .from("/path/to/File")
            .transform("Transformer to convert to Bean")
            .wireTap(
                    flow -> flow.handle(msg -> logger
                            .info("Message sent to common channel: " + msg.getPayload())))
                            .channel("Common Channel Name")
                            .get();
    }

코드 내부 4 :

@Bean
    public IntegrationFlow sendToDb() {

    return IntegrationFlows
            .from("Common Channel Name")
            .handle("DAO Impl to store into DB") // I THINK THE MESSAGE SHOULD BE SENT TO AN EXECUTOR CHANNEL TO PROCESS ON A SEPARATE THREAD
            .get();
    }

코드 내부 5 :

@Bean
public IntegrationFlow sendToBusinessLogictoNotifyUser() {

    return IntegrationFlows
            .from("Common Channel Name")
            .handle("Business Logic Class name")
                            .get();
    }       

현재 동작 : DB 예외가있는 경우 알림 사용자도 실패합니다. 대신 나는 그것이 조용히 기록되기를 원한다.

해결법

  1. ==============================

    1.단순히 ExecutorChannel이 필요하지 않습니다. 단순히 pub / sub 채널에서 ignoreFailures를 true로 설정하면됩니다.

    단순히 ExecutorChannel이 필요하지 않습니다. 단순히 pub / sub 채널에서 ignoreFailures를 true로 설정하면됩니다.

    /**
     * Specify whether failures for one or more of the handlers should be
     * ignored. By default this is <code>false</code> meaning that an Exception
     * will be thrown whenever a handler fails. To override this and suppress
     * Exceptions, set the value to <code>true</code>.
     * @param ignoreFailures true if failures should be ignored.
     */
    public void setIgnoreFailures(boolean ignoreFailures) {
    

    DB 저장소에서 예외를 기록하거나 처리하려는 경우 DB 저장소를 수행하는 구성 요소에 ExpressionEvaluatingRequesthandlerAdvice를 추가 할 수 있습니다.

    ExecutorChannel이 실제로 필요한 경우 참조 설명서의 DSL 섹션에 예제가 있습니다.

    .channel(MessageChannels.executor("executorChannel", this.taskExecutor))
    
  2. from https://stackoverflow.com/questions/50535484/spring-integration-executor-channel-using-annotations-code-sample by cc-by-sa and MIT license