स्प्रिंग में घटक से कॉन्फ़िगरेशन में 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 class में यह है:

    @Autowired
    MyGateway gateway;

    public void list(){
        List<File> files = gateway.listFiles();
    }

जब मैं इसे चलाता हूं, मुझे एक त्रुटि मिलती है receive is not supported, because no pollable reply channel has been configured

मुझे लगता है कि यह मेरी जानकारी / एकीकरण चैनलों की समझ है। शायद मुझे एक बीन की याद आ रही है, लेकिन यहां मेरा मुख्य लक्ष्य इनबॉर्बनेल एडाप्टर के मेरे वर्तमान उपयोग को बदलने के लिए है ताकि फाइलरवर को लगातार मतदान करने के बजाय फाइल तदर्थ का अनुरोध किया जा सके।

जवाब

1 ArtemBilan Dec 18 2020 at 02:34

हां, बिना किसी तर्क के स्प्रिंग इंटीग्रेशन गेटवे में वर्णित कहानी निश्चित रूप से आपकी समस्या से संबंधित है।

आप इस तथ्य को याद कर रहे हैं कि 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