Springのコンポーネントから構成でSFTPアウトバウンドゲートウェイ操作を呼び出す方法

Dec 18 2020

ここを見てみましたが、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

これは、統合チャネルに関する私の知識/理解の問題だと思います。Beanが不足している可能性がありますが、ここでの私の主な目標は、ファイルサーバーを継続的にポーリングするのではなく、現在使用しているインバウンドチャネルアダプターを置き換えてアドホックにファイルを要求することです。

回答

1 ArtemBilan Dec 18 2020 at 02:34

はい、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