Spring Integration outbound FTP append to existing file - spring

I want to use the outbound FTP channel adapter to APPEND to an existing remote file. However, it looks like the adapter only support the PUT command?
Does anyone know if this is possible with Spring Integration?

Appending to remote files is not currently available out of the box, but it would be a good addition, please open a JIRA New Feature Issue.
However, all is not lost, you can use a <service-activator/> to invoke a bean that creates an FTPClient object, using its appendFile() method.

Related

Spring Integration to poll folder and call REST with file contents

The use case is that I need to poll a folder on a remote server, and if a new file is copied to that folder, I need to call a REST get API with the file contents. The REST API will process the file contents using Spring batch.
I am trying to use Spring boot integration for that purpose but having issues finding my way. Is Spring Integration best suited for this purpose? If yes, can I have a simple example of just the Spring Integration picking up the file and calling the REST API?
Or can I simply use the Java Watcher service?
Not clear what is your remote folder, but you can't use Java WatchService for that purpose anyway. Typically the remote directory is on an (S)FTP. Spring Integration provides channel adapters to poll such a remote directory under the mentioned protocol.
See more info in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/ftp.html#ftp-inbound
You probably don't need to have a local copy of a remote service, then you can consider to use a streaming channel adapter instead: https://docs.spring.io/spring-integration/docs/current/reference/html/ftp.html#ftp-streaming
As far as a file content is emitted into a channel configured in that channel adapter, you can use an HTTP Outbound Channel Adapter to call some REST API: https://docs.spring.io/spring-integration/docs/current/reference/html/http.html#http-outbound
You can investigate samples project for some inspiration: https://github.com/spring-projects/spring-integration-samples

Spring batch FTP file

I am using Spring Batch ItemReader to read data from a database and then using FlatFileItemWriter to write the data to a file.
Once the data is written to a file, I need this specific file to be transferred to an FTP server. Can I do this via Spring Batch or should I use Spring Integration? Could you please also provide an example?
There is nothing wrong in combining both frameworks. They really work together smoothly.
Since you say that you already have a Spring Batch ItemReader and your OK writing into a file using FlatFileItemWriter, so you are have way out for your whole solution.
In the end you can use a Providing Feedback with Informational Messages to get a file and send it to FTP using Spring Integration FTP Outbound Channel adapter.
See more info in Spring Batch Docs: https://docs.spring.io/spring-batch/4.2.x/reference/html/spring-batch-integration.html#providing-feedback-with-informational-messages
And in Spring Integration about FTP support: https://docs.spring.io/spring-integration/docs/current/reference/html/#ftp

Spring integration : handle a File given in arguments

I have an existing Spring Integration app, which handle files coming from FTP with InboundChannelAdapter. I want to plug Spring boot to this app to use it now like this :
java -jar app.jar <filetohandlepath>
So, the application start with this command, and stop at the end of the treatment. But my question is how can I run my existing channels (ServiceActivator) to give this file to handle ?
I can use an InboundChannelAdapter, but I think the poller can be a problem
Maybe a Gateway ? But I don't think this can be a solution
Or I need to build and send a Message manually ?
What about Spring Boot, to handle the argument ? I need to build the message into the main method, or in an other class with a scan ?
I just need to know the best way to design my app.
Your FTP Inbound Channel Adapter polls remote file to local files and sends them as payload of messages into some channel for the mentioned Service Activator. Of course you can send message manually to the same channel with the payload accepted by that Service Activator subscriber. Yes, you can use #MessagingGateway to separate Messaging concern from your code. Or you can just rely on the MessagingTemplate and its convertAndSend() API. Any convenient way for you is acceptable: https://docs.spring.io/spring-integration/docs/5.0.4.RELEASE/reference/html/messaging-endpoints-chapter.html#gateway
As for Spring Boot and command line arguments, you definitely can take a look into the CommandLineRunner: https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/#boot-features-command-line-runner

Spring Integration. Unknown host and tcp-connection-factory

I'm implementing the TCP client using the Spring Integration.
The requirements are:
1. Through the UDP connection (from somewhere) receive the ip or host address of the TCP server.
2. Open TCP connection to the server, to the destination host from previous step and send some business data to this server.
I use the Spring Integration framework, version "2.2.0.RELEASE", and the problem is that in the default configuration of the tcp-connection-factory the host attribute should be "hardcoded" in xml. For example:
<ip:tcp-connection-factory id="client" type="client" host="localhost" port="1234" single-use="true"/>
The question is how to avoid the static definition of the destination host in application context, and be able to 'lazy' initialise the tcp-connection-factory when the destination host will be known.
I know that this flow could be easily implemented by the standard Network APIs of Java, and the question is specific about the Spring-Integration API
At this time, the configuration is static.
You could however use a similar technique to that used in the dynamic ftp sample which configures ftp outbound adapters at runtime.
As far as <int-ip:tcp-connection-factory> provides some instance of AbstractConnectionFactory. And from other side <int-ip:tcp-outbound-channel-adapter> applies that instance via connection-factory, so, there is no stops to implement your own RoutingConnectionFactory.
The implementation may rely on some value from ThreadLocal. The idea is here:
https://github.com/spring-projects/spring-amqp/blob/master/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractRoutingConnectionFactory.java,
https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java
It's not currently possible/easy - even if you customize or extend the class for tcp-connection-factory to be able to connect to changing hosts. There is an open new feature request in JIRA to provide this functionality.

Can someone explain MQSeries file based JNDI for remote client JMS access

I've been searching extensively for a description of how to set up JMS access from a remote client to a file based JNDI MQ Series provider without success.
My JMS client works Ok on the same Linux machine as my MQSeries 7.5 server using file based JNDI.
How does one set up a remote client to use file based JNDI? Is it even possible or must one use LDAP?
I've seen hints that one should be able to have a remote client but nothing very clear.
I'm using Spring JMSTemplate which uses a provider url. On the same machine my Tomcat context.xml file uses a file: fileName url which, as I say, works ok collocated with the MQSeries server.
Thanks
Not a problem. If you are using a File based JNDI then you just need to add a QCF that contains the appropriate information for the remote queue manager. i.e. hostname, port # and channel name
DEFINE QCF(myQCF) QMANAGER(MQWT1) CHANNEL(TEST.CHL) HOSTNAME(22.22.22.22) PORT(1414) TRANSPORT(CLIENT) FAILIFQUIESCE(YES)
I was assuming that there was more than there is to file based JNDI. All it is is reading a property file. Using the "file"" url format allows you to read remote files.

Resources