如何从侦听器中的服务激活器消息对象获取文件 class
How to get the file from service-activator Message object in listener class
我需要将文件传递到我在 SFTP 路径中接收的服务层。
下面是配置,我看到在我的服务激活器中收到消息,如
GenericMessage [payload=com.jcraft.jsch.ChannelSftp@322906a2,
headers={closableResource=org.springframework.integration.sftp.session.SftpSession@379662a7,
id=704c58e7-1d93-3bef-0330-233c0f9af55c, file_remoteDirectory=/tmp/charge/,
file_remoteFile=Charge.txt, timestamp=1594158522576}]
<bean id="sftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="hostname"/>
<property name="port" value="22"/>
<property name="user" value="vkp"/>
<property name="password" value="1234"/>
<property name="allowUnknownKeys" value="true"/>
</bean>
<int-sftp:inbound-streaming-channel-adapter id="sftpAdapterAutoCreate"
session-factory="sftpSessionFactory"
filename-pattern="*.txt"
channel="receiveChannel"
remote-directory="/tmp/charge/">
</int-sftp:inbound-streaming-channel-adapter>
<int:poller fixed-rate="25000" max-messages-per-poll="1" id="shippingChargePoller" default="true"/>
<int:channel id="receiveChannel">
<int:queue/>
</int:channel>
<int:stream-transformer id="withCharset" charset="UTF-8" input-
channel="receiveChannel" />
<int:service-activator id="FeedListener" input-channel="receiveChannel" method="onMessage">
<bean class="com.listener.ChargeFeedListener"/>
</int:service-activator>
public void onMessage(Message<?> message){
System.out.println(message.toString());
System.out.println( " Received File is "+message.getPayload());
}
但是我没有在 java class 中收到文件。我需要做什么才能获取文件?
请阅读文档:https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-streaming。 <int-sftp:inbound-streaming-channel-adapter>
与文件无关。它确实会为远程条目(可能是 SFTP 上的文件)打开 InputStream
,并让您随心所欲地处理此流。例如(也根据该文档),有一个 StreamTransformer
可以让您将该流读入 byte[]
或字符串(如果您提供 charset
)。如果你真的要处理文件,那么你需要考虑切换到<int-sftp:inbound-channel-adapter>
。那一个拉出远程条目并将其内容存储到本地文件中。然后java.io.File
发送到频道供您考虑。
我想我们已经就您的其他问题与您进行了交谈:。
请让我们知道我们的文档有什么问题让您感到困惑,所以您必须在这里提出这样的问题。
我需要将文件传递到我在 SFTP 路径中接收的服务层。 下面是配置,我看到在我的服务激活器中收到消息,如
GenericMessage [payload=com.jcraft.jsch.ChannelSftp@322906a2,
headers={closableResource=org.springframework.integration.sftp.session.SftpSession@379662a7,
id=704c58e7-1d93-3bef-0330-233c0f9af55c, file_remoteDirectory=/tmp/charge/,
file_remoteFile=Charge.txt, timestamp=1594158522576}]
<bean id="sftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="hostname"/>
<property name="port" value="22"/>
<property name="user" value="vkp"/>
<property name="password" value="1234"/>
<property name="allowUnknownKeys" value="true"/>
</bean>
<int-sftp:inbound-streaming-channel-adapter id="sftpAdapterAutoCreate"
session-factory="sftpSessionFactory"
filename-pattern="*.txt"
channel="receiveChannel"
remote-directory="/tmp/charge/">
</int-sftp:inbound-streaming-channel-adapter>
<int:poller fixed-rate="25000" max-messages-per-poll="1" id="shippingChargePoller" default="true"/>
<int:channel id="receiveChannel">
<int:queue/>
</int:channel>
<int:stream-transformer id="withCharset" charset="UTF-8" input-
channel="receiveChannel" />
<int:service-activator id="FeedListener" input-channel="receiveChannel" method="onMessage">
<bean class="com.listener.ChargeFeedListener"/>
</int:service-activator>
public void onMessage(Message<?> message){
System.out.println(message.toString());
System.out.println( " Received File is "+message.getPayload());
}
但是我没有在 java class 中收到文件。我需要做什么才能获取文件?
请阅读文档:https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-streaming。 <int-sftp:inbound-streaming-channel-adapter>
与文件无关。它确实会为远程条目(可能是 SFTP 上的文件)打开 InputStream
,并让您随心所欲地处理此流。例如(也根据该文档),有一个 StreamTransformer
可以让您将该流读入 byte[]
或字符串(如果您提供 charset
)。如果你真的要处理文件,那么你需要考虑切换到<int-sftp:inbound-channel-adapter>
。那一个拉出远程条目并将其内容存储到本地文件中。然后java.io.File
发送到频道供您考虑。
我想我们已经就您的其他问题与您进行了交谈:
请让我们知道我们的文档有什么问题让您感到困惑,所以您必须在这里提出这样的问题。