Spring의 Component에서 Configuration에서 SFTP Outbound Gateway 작업을 호출하는 방법
여기 보았다 여기에 작업에 때 listFiles을 얻을 수 없습니다입니다 :
@Bean
public SessionFactory<LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost("localhost");
factory.setPort(port);
factory.setUser("foo");
factory.setPassword("foo");
factory.setAllowUnknownKeys(true);
factory.setTestSession(true);
return new CachingSessionFactory<LsEntry>(factory);
}
@MessagingGateway
public interface MyGateway {
@Gateway(requestChannel = "sftpChannel")
List<File> listFiles();
}
@Bean
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handler() {
return new SftpOutboundGateway(ftpSessionFactory(), "ls", "'my_remote_dir/'");
}
내 @Component 클래스에 다음이 있습니다.
@Autowired
MyGateway gateway;
public void list(){
List<File> files = gateway.listFiles();
}
이걸 실행하면 오류가 발생합니다. receive is not supported, because no pollable reply channel has been configured
이것이 통합 채널에 대한 지식 / 이해에 문제라고 생각합니다. 아마도 나는 빈을 놓치고 있지만 여기서 나의 주요 목표는 파일 서버를 지속적으로 폴링하는 대신 inboundchannel 어댑터의 현재 사용을 대체하여 파일을 임시로 요청하는 것입니다.
답변
예, Spring Integration Gateway에서 논증없이 언급 된 이야기 는 확실히 당신의 문제와 관련이 있습니다.
List<File> listFiles()
계약이 인수없이 제공 된다는 사실을 놓치고 있으므로 프레임 워크에서 sftpChannel
. 따라서 호출을 시도합니다 receive
. 그러나 귀하 sftpChannel
가 아니기 때문에 PollableChannel
그 오류가 발생했습니다. 어쨌든 그것은 다른 이야기이며 sftpChannel
해당 게이트웨이 계약으로하려고 할 때 메시지를 보낸 후 응답으로 얻고 싶은 것이 아닙니다 .
인수가없는 게이트웨이 계약의 페이로드로 사용할 내용을 더 명확하게 말하면됩니다.
문서에서 더 많은 정보보기 : https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway-calling-no-argument-methods. 는 @Payload
당신을 위해 대답이다. 또는 당신은 지정할 수 있습니다 payloadExpression
그것에 대한 @Gateway
주석 또는 defaultPayloadExpression
온을 @MessagingGateway
.