Streams
Most programs use data in one form or another, whether it is as input, output, or both. To bring data into a program, a Java program opens a stream to a data source, such as a file or remote socket, and reads the information serially. Spring Integration provides two adapters for reading from streams. They are:
- org.springframework.integration.stream.ByteStreamReadingMessageSource for reading byte stream
- org.springframework.integration.stream.CharacterStreamReadingMessageSource for reading character stream
Listing 22-38 below shows maven dependency required for integrating streams using Spring Integration.
Listing 22-38. Maven dependency required
1 2 3 4 5 6 7 8 9 |
<dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-stream</artifactId> <version>${spring-integration-version}</version> </dependency> |
Listing 22-39 below shows configuration of main Spring Integration namespace and stream related namespace in the Spring configuration file (stream-integration-context.xml).
Listing 22-39. Spring Integration Namespace declaration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?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:stream="http://www.springframework.org/schema/integration/stream" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.1.xsd"> … </beans> |
Listing 22-40 below shows configuration of a basic stream adapter, both byte and character in the Spring configuration file (stream-integration-context.xml). Note that Spring Integration for stream doesn’t support namespace support for declaring these stream beans in the Spring configuration file.
Listing 22-40. Byte and Character stream bean configuration in Spring configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<beans …> … <!—Byte reading stream --> <bean class="org.springframework.integration.stream.ByteStreamReadingMessageSource"> <constructor-arg ref="inputStream"/> <property name="bytesPerMessage" value="4096"/> </bean> <!—Character reading stream --> <bean> <constructor-arg ref="reader"/> </bean> … </beans> |
For reading stream from system’s STDIN and for writing stream into system’s STDOUT, Spring Integration provides adapters and also has namespace support as well, as shown in Listing 22-41 below.
Listing 22-41. Declaring stdin and stdout stream adapters in Spring configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<beans …> … <int:channel id="inputChannel"/> <stream:stdin-channel-adapter id="stdinAdapter" channel="inputChannel"/> <stream:stdout-channel-adapter id="stdoutAdapter" channel="inputChannel" append-newline="true"/> … </beans> |
Page Visitors: 13059

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
Hi,
Thanks for this blog and information sharing!
I have one question from Spring Integration. Just thought of checking with you.
I have SimplewebserviceOutBoundGateway. I need to send a document / attachment to the webservice. How will i achieve that?
This is my current gateway configuration:
Please let me know, if you can throw some light in this area.
Thanks in Advance!
Hi,
Thank you for your information sharing.
I have one doubt,could you please suggest me the correct frameworks to address that issue.
My requirement is I would like to get and process files using spring and camel.
Thanks,
Madhu