How to implement this TCP stream reader in Spring Integration?

I need a w760> integration implementation to read a stream. Another application (outside of java) sends data streams (limited by dollar signs) to port 9999. This server is listening.

At first I made sure that the streaming stream was connected to it using telnet 127.0.0.1 9999.

Then I created a simple java application with the following method. This is working now.

public void readStream() throws IOException{
    Scanner s = null;
    try {
        Socket skt = new Socket("localhost", 9999);
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(
                        skt.getInputStream()));
        s = new Scanner(bufferedReader);
        s.useDelimiter("[$]");
        System.out.println(s);
        while (s.hasNext()) {
            System.out.println("----------------------");
            System.out.println(s.next());
        }
    } finally {
        if (s != null) {
            s.close();
        }
    }
}

Spring . https://github.com/spring-projects/spring-integration-samples/tree/master/basic/tcp-client-server http://docs.spring.io/autorepo/docs/spring-integration/2.0.0.M3/spring-integration-reference/html/stream.html. , ? ? ( Spring Framework.)

. TCP- ? ? , ??

:

<bean class="org.springframework.integration.ip.tcp.serializer.ByteArraySingleTerminatorSerializer" id="deserializer1">
    <constructor-arg type="byte" value="$"/>
</bean>
<int-ip:tcp-connection-factory id="server" type="server" port="9999"
    deserializer="deserializer1"
/>
<int-ip:tcp-inbound-channel-adapter id="adapter" connection-factory="server" request-channel="channel1"/>
<int:channel id="channel1" />
+4
1

, . (<int-ip:tcp-inbound-channel-adapter) - .

factory, ByteArraySingleTerminatorSerializer, $, deserializer.

, , , .

+3

Source: https://habr.com/ru/post/1584432/


All Articles