Channel Adapter

채널 μ–΄λŒ‘ν„°λŠ” 단일 λ°œμ‹ μž λ˜λŠ” μˆ˜μ‹ μžλ₯Ό λ©”μ‹œμ§€ 채널에 μ—°κ²°ν•  수 있게 ν•΄μ£ΌλŠ” λ©”μ‹œμ§€ μ—”λ“œν¬μΈνŠΈμ΄λ‹€.

Configuring An Inbound Channel Adapter

μΈλ°”μš΄λ“œ 채널 μ–΄λŒ‘ν„° μš”μ†Œ(μžλ°” κ΅¬μ„±μ˜ SourcePollingChannelAdapter)λŠ” Spring 관리 객체의 λͺ¨λ“  λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜κ³  λ©”μ„œλ“œμ˜ 좜λ ₯을 Message둜 λ³€ν™˜ν•œ ν›„ null이 μ•„λ‹Œ λ°˜ν™˜ 값을 MessageChannel둜 보낼 수 μžˆμŠ΅λ‹ˆλ‹€.

μ–΄λŒ‘ν„°μ˜ ꡬ독이 ν™œμ„±ν™”λ˜λ©΄ pollerλŠ” μ†ŒμŠ€μ—μ„œ λ©”μ‹œμ§€ μˆ˜μ‹ μ„ μ‹œλ„ν•©λ‹ˆλ‹€.

pollerλŠ” 제곡된 ꡬ성에 따라 TaskScheduler둜 μ˜ˆμ•½λ©λ‹ˆλ‹€

κ°œλ³„ 채널 μ–΄λŒ‘ν„°μ— λŒ€ν•œ 폴링 간격 λ˜λŠ” cron ν‘œν˜„μ‹μ„ κ΅¬μ„±ν•˜λ €λ©΄ fixed-rate λ˜λŠ” cronκ³Ό 같은 일정 속성 쀑 ν•˜λ‚˜μ™€ ν•¨κ»˜ poller μš”μ†Œλ₯Ό μ œκ³΅ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λ‹€μŒ μ˜ˆμ—μ„œλŠ” 두 개의 μΈλ°”μš΄λ“œ 채널 μ–΄λŒ‘ν„° μΈμŠ€ν„΄μŠ€λ₯Ό μ •μ˜ν•©λ‹ˆλ‹€.

@Bean
public IntegrationFlow source1() {
    return IntegrationFlow.from(() -> new GenericMessage<>(...),
                             e -> e.poller(p -> p.fixedRate(5000)))
                ...
                .get();
}

@Bean
public IntegrationFlow source2() {
    return IntegrationFlow.from(() -> new GenericMessage<>(...),
                             e -> e.poller(p -> p.cron("30 * 9-17 * * MON-FRI")))
                ...
                .get();
}

Configuring An Outbound Channel Adapter

outbound-channel-adapter μš”μ†Œ(Java κ΅¬μ„±μš© @ServiceActivator)λŠ” ν•΄λ‹Ή μ±„λ„λ‘œ μ „μ†‘λœ λ©”μ‹œμ§€μ˜ νŽ˜μ΄λ‘œλ“œμ™€ ν•¨κ»˜ ν˜ΈμΆœλ˜μ–΄μ•Ό ν•˜λŠ” POJO μ†ŒλΉ„μž λ©”μ„œλ“œμ— MessageChannel을 μ—°κ²°ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.

λ‹€μŒ μ˜ˆλŠ” μ•„μ›ƒλ°”μš΄λ“œ 채널 μ–΄λŒ‘ν„°λ₯Ό μ •μ˜ν•˜λŠ” 방법을 λ³΄μ—¬μ€λ‹ˆλ‹€.

@Bean
public IntegrationFlow outboundChannelAdapterFlow(MyPojo myPojo) {
    return f -> f
             .handle(myPojo, "handle");
}

μ‘°μ • 쀑인 채널이 PollableChannel인 경우 λ‹€μŒ μ˜ˆμ œμ™€ 같이 poller ν•˜μœ„ μš”μ†Œ(@ServiceActivator의 @Poller ν•˜μœ„ 주석)λ₯Ό μ œκ³΅ν•΄μ•Ό ν•©λ‹ˆλ‹€.

public class MyPojo {

    @ServiceActivator(channel = "channel1", poller = @Poller(fixedRate = "3000"))
    void handle(Object payload) {
        ...
    }

}

Channel Adapter Expressions and Scripts

λ‹€λ₯Έ λ§Žμ€ Spring 톡합 ꡬ성 μš”μ†Œμ™€ λ§ˆμ°¬κ°€μ§€λ‘œ <inbound-channel-adapter>및 <outbound-channel-adapte>도 SpEL ν‘œν˜„μ‹ 평가λ₯Ό μ§€μ›ν•©λ‹ˆλ‹€.

Last updated

Was this helpful?