Spring Integration file-outbound-channel-adaptor :Lab-4

We will

  • Create and test an inbound file adapter.
  • Create and test an outbound file adapter

Before we start we already explore adapters. we have already used adapters in the first lab.
You used Standard Input and Standard Output adapters to bring String data into the
message channel and print it to the Console view

Here we will only be using file-outbound-channel-adapter channel in place of stdout-channel-adapter which we have used in previous labs(Channel labs)

spring-integration-file-outbound-channel-adapter.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"	xmlns:int="http://www.springframework.org/schema/integration"	xmlns:int-file="http://www.springframework.org/schema/integration/file"	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 	xmlns:int-stream="http://www.springframework.org/schema/integration/stream"	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/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd	http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">	<int-stream:stdin-channel-adapter id="producer" channel="messageChannel" />	<int-file:outbound-channel-adapter channel="messageChannel" id="consumer-file-adapter" directory="/Users/dpq/Desktop/techWorrk/fileOutbound" />			<int:poller id="defaultPoller" default="true"		max-messages-per-poll="5" fixed-rate="200" />	<!-- a pub/sub message channel -->	<int:channel id="messageChannel" />          </beans>

Main container loader class which will load all the beans

Startup.java

import org.springframework.context.support.ClassPathXmlApplicationContext;public class Startup {	@SuppressWarnings({ "resource", "unused" })	// @SuppressWarnings({ "resource" })	public static void main(String[] args) {		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(				"/META-INF/spring/spring-integration-file-outbound-channel-adapter.xml");		while (true) {		}			}}

Output:

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Contanier started…..
deepak

Once you run this channel , there will be msg with text deepak inside fileOutbound folder which is file out-bound channel

Popular posts from this blog

Window function in PySpark with Joins example using 2 Dataframes (inner join)

Complex SQL: fetch the users who logged in consecutively 3 or more times (lead perfect example)

Credit Card Data Analysis using PySpark (how to use auto broadcast join after disabling it)