การรวมสปริงสำหรับ sftp

ฉันจะย้ายไฟล์จากระบบโลคัลไปยัง FTP ระยะไกลโดยใช้อะแดปเตอร์ SFTP ได้อย่างไร ฉันกำลังดูตัวอย่างต่างๆ และทุกคนพูดถึงการคัดลอกไฟล์จาก FTP ระยะไกลไปยังเครื่องท้องถิ่น

ฉันต้องการย้ายไฟล์จากเครื่องท้องถิ่นไปยังโฟลเดอร์ระบบระยะไกล

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
xmlns:file="http://www.springframework.org/schema/integration/file"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/integration
    http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/integration/sftp
    http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-    2.2.xsd
    http://www.springframework.org/schema/integration/file
    http://www.springframework.org/schema/integration/file/spring-integration-file-2.2.xsd">

<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="localhost"/>
<property name="user" value="user01"/>
<property name="password" value="abc123"/>
<property name="port" value="990"/>
</bean>

<int:channel id="sftpChannel"/>

<file:inbound-channel-adapter directory="#{T(System).getProperty('java.io.tmpdir')}" id="fileInbound"
                          channel="sftpChannel" filename-pattern="*.xml">
<int:poller fixed-rate="1000" max-messages-per-poll="100"/>
</file:inbound-channel-adapter>

<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter" session-factory="sftpSessionFactory"
                               channel="sftpChannel" charset="UTF-8" remote-directory="/"
                               remote-file-separator="/"/>

</beans>

<file:outbound-channel-adapter id="moveProcessedFile"
    channel="sftpChannel"
    directory="file:#{configurationService.configuration.getProperty('acal.jde.publish.folder')}/processed"
    delete-source-files="true" order="2" />

ฉันลองแล้ว แต่ไม่สามารถย้ายไฟล์ไปยังโฟลเดอร์ที่ประมวลผลได้


person sree    schedule 24.09.2013    source แหล่งที่มา
comment
คุณต้องเพียง outbound-channel-adapter เพื่อใส่ไฟล์ไปที่ SFTP คุณใช้อะไรเพื่อใส่เพย์โหลดของคุณไปที่ inputChannel   -  person Dmitry Kuskov    schedule 24.09.2013
comment
BTW คุณสามารถดูตัวอย่างที่วางไฟล์ไว้ใน dir ระยะไกลผ่าน SFTP ที่นี่   -  person Dmitry Kuskov    schedule 24.09.2013
comment
@Dmitry ดังนั้นฉันต้องกำหนดเฉพาะอะแดปเตอร์ช่องสัญญาณขาออกเท่านั้นหรือไม่ ถ้าเป็นเช่นนั้นฉันจะกำหนดค่าโฟลเดอร์ในเครื่องที่ต้องการเลือกไฟล์ได้อย่างไร   -  person sree    schedule 24.09.2013
comment
คุณไม่ได้ระบุสิ่งนี้ใน outbound-channel-adapter คุณระบุเฉพาะช่องสัญญาณเข้าเท่านั้น และวิธีการใส่ข้อมูลในช่องนี้ขึ้นอยู่กับคุณ: คุณสามารถสร้างเชนที่จะอ่านไดเร็กทอรีในเครื่องและเขียนเพย์โหลดไปที่ inputChannel หรือคุณสามารถอ่านไฟล์และวางเป็นเพย์โหลดด้วยตนเองในงาน corn และตัวเลือกอื่น ๆ อีกมากมาย คุณควรตัดสินใจว่าตัวเลือกใดที่เหมาะกับคุณที่สุด ในลิงก์ที่ฉันให้ไว้ด้านบน MessageChannel.send ถูกเรียกอย่างชัดเจนและได้รับอินสแตนซ์ของช่องจากบริบทของแอป - นั่นก็เป็นตัวเลือกเช่นกัน   -  person Dmitry Kuskov    schedule 24.09.2013
comment
@Dmitry ขอบคุณสำหรับอินพุต ฉันเพิ่มช่องสัญญาณและอ่านไฟล์แล้วเรียกว่าการกำหนดค่า outbound-channel-adapter.edit ด้านบน แต่ไฟล์ยังคงไม่เคลื่อนไหว คุณช่วยฉันหน่อยได้ไหม   -  person sree    schedule 24.09.2013
comment
ทำไมคุณถึงมี sftpSessionFactory เป็น channel ใน inbound-channel-adapter ควรกำหนดช่องทางข้อความที่จะส่งต่อเพย์โหลดไป ดังนั้นในกรณีของคุณดูเหมือนว่าควรจะเป็น publishToSFTPChannel แล้วทำไมถึงใช้ publish-subscribe-channel? ช่องทางแบบจุดต่อจุดธรรมดาก็น่าจะเพียงพอแล้ว   -  person Dmitry Kuskov    schedule 24.09.2013


คำตอบ (1)


นี่คือการกำหนดค่าตามของคุณที่ฉันตรวจสอบแล้วว่าใช้งานได้จริง คุณสามารถใช้เป็นจุดเริ่มต้นได้

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:int="http://www.springframework.org/schema/integration"
   xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
   xmlns:file="http://www.springframework.org/schema/integration/file"
   xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration
        http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/integration/sftp
        http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.2.xsd
        http://www.springframework.org/schema/integration/file
        http://www.springframework.org/schema/integration/file/spring-integration-file-2.2.xsd">

<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <property name="host" value="localhost"/>
    <property name="user" value="user01"/>
    <property name="password" value="abc123"/>
    <property name="port" value="990"/>
</bean>

<int:channel id="sftpChannel"/>

<file:inbound-channel-adapter directory="#{T(System).getProperty('java.io.tmpdir')}" id="fileInbound"
                              channel="sftpChannel" filename-pattern="*.xml">
    <int:poller fixed-rate="1000" max-messages-per-poll="100"/>
</file:inbound-channel-adapter>

<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter" session-factory="sftpSessionFactory"
                                   channel="sftpChannel" charset="UTF-8" remote-directory="/"
                                   remote-file-separator="/"/>

</beans>

ปัญหาเกี่ยวกับการกำหนดค่าของคุณ:

  1. คุณใช้ sftpSessionFactory เป็นช่องใน inbound-channel-adapter ควรกำหนดช่องทางข้อความที่จะส่งต่อเพย์โหลดไป ดังนั้นในกรณีของคุณดูเหมือนว่าควรจะเป็น publishToSFTPChannel
  2. publish-subscribe-channel ใช้แทนช่องทางแบบจุดต่อจุดแบบธรรมดา
person Dmitry Kuskov    schedule 24.09.2013
comment
ขอบคุณที่ใช้งานได้สำหรับฉัน จากนั้นฉันก็พยายามย้ายไฟล์ไปยังโฟลเดอร์ที่ประมวลผลแล้ว แต่ไม่สามารถย้ายไฟล์ไปยังโฟลเดอร์ได้ คุณช่วยดูการกำหนดค่าของฉันได้ไหม - person sree; 25.09.2013
comment
ฉันคิดว่าคุณควรสร้างคำถามใหม่ทุกครั้ง และไม่แก้ไขคำถามที่มีอยู่ คุณสามารถจัดการเรื่องนี้ได้หลายวิธี sftpChannel เป็นช่องทางโดยตรงแล้ว จึงมีผู้บริโภคเพียงรายเดียวเท่านั้นที่สามารถใช้งานได้ ตัวอย่างเช่น คุณสามารถสร้างตัวแยกสัญญาณหรือเราเตอร์เพื่อส่งข้อความถึงคุณไปยังช่องต่างๆ สำหรับอะแดปเตอร์แต่ละตัวได้ นอกจากนี้ publish-subscribe-channel อาจมีประโยชน์สำหรับคุณในตอนนี้ด้วย คุณสามารถอ่านไฟล์ในเครื่องได้ จากนั้นไฟล์จะถูกส่งเป็นเพย์โหลดไปยังทั้ง SFTP และอะแดปเตอร์ขาออกของไฟล์ - person Dmitry Kuskov; 25.09.2013
comment
เป็น int:channel id=sftpChannel เป็นค่าเริ่มต้นหรือเหมือนกับว่าฉันอาจมี int:channel id=_rd - person rd_; 07.08.2019