How to implement this TCP stream reader in Spring Integration?

codesmith

I would like a Spring Integration implementation of a stream reader. Another application (outside of java) sends streams of data (delimited by dollar-signs) to port 9999. This server listens.

First I made sure the stream was streaming by connecting to it with telnet 127.0.0.1 9999.

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

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();
        }
    }
}

Now, I would like to implement this in Spring Integration framework. I looked at https://github.com/spring-projects/spring-integration-samples/tree/master/basic/tcp-client-server and http://docs.spring.io/autorepo/docs/spring-integration/2.0.0.M3/spring-integration-reference/html/stream.html. However I get confused where to start? What is needed to connect to the sending application? (I'm really new to the Spring Framework.)

The difficulty for me lies in the terminology. Should I create a TCP Inbound gateway? or a receiving channel adapter? or is it outbound because I'm requesting the stream??

EDIT after comments of Gary:

<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" />
Gary Russell

An inbound gateway is used when the server sends a reply to an inbound request. An inbound channel adapter (<int-ip:tcp-inbound-channel-adapter) is for one-way integration only - the client sends data only and does not receive replies.

You would need a server connection factory, configured to use a ByteArraySingleTerminatorSerializer configured with your $ delimiter, in the deserializer property.

Please use the latest documentation not the old version that was in your question.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to implement sticky session in spring-integration tcp gateway?

From Dev

Spring Integration - How to implement an asynchronous TCP Socket requests/responses over the same connection?

From Dev

How to implement Spring Integration Flow to act as a TcpClient

From Java

How to implement MQTT server using Spring Integration?

From Java

How to implement message queue with Spring Integration and MongoDB?

From Java

Spring Integration TCP

From Dev

How to implement multiple Reader using db in Spring Batch

From Java

How to send reply for TCP requests (spring-integration)?

From Dev

How to set up XML marshalling for a TCP server in Spring integration?

From Dev

How to implement distributed lock around poller in Spring Integration using ZooKeeper

From Dev

TCP "proxy" to intercept TCP traffic with Spring integration

From Dev

Implement Keyset paging in a reader for a spring batch job

From Java

How to implement a Java stream?

From Dev

How to implement a writable stream

From Dev

scalaz-stream how to implement `ask-then-wait-reply` tcp client

From Dev

reply timeout in spring integration tcp gateway

From Dev

Spring integration TCP server not receiving messages

From Dev

TCP Client Spring Integration with Java Config

From Java

Spring Integration tcp/ip connection delay

From Dev

Spring integration on reconnect TCP send handshake

From Java

Listen for Spring Integration TCP Connection events

From Dev

Listen on TCP feed with spring-integration

From Java

TCP Client Spring Integration with Legacy Server

From Java

Spring Integration ByteArrayRawSerializer TCP Client Server

From Dev

Spring Integration TCP doesn't send messages

From Dev

Is it possible use custom header in Spring Integration TCP?

From Dev

Spring Integration TCP factory error handling

From Dev

how to implement integration router in java

From Dev

Implement a consumer and producer system using Spring integration

Related Related

  1. 1

    How to implement sticky session in spring-integration tcp gateway?

  2. 2

    Spring Integration - How to implement an asynchronous TCP Socket requests/responses over the same connection?

  3. 3

    How to implement Spring Integration Flow to act as a TcpClient

  4. 4

    How to implement MQTT server using Spring Integration?

  5. 5

    How to implement message queue with Spring Integration and MongoDB?

  6. 6

    Spring Integration TCP

  7. 7

    How to implement multiple Reader using db in Spring Batch

  8. 8

    How to send reply for TCP requests (spring-integration)?

  9. 9

    How to set up XML marshalling for a TCP server in Spring integration?

  10. 10

    How to implement distributed lock around poller in Spring Integration using ZooKeeper

  11. 11

    TCP "proxy" to intercept TCP traffic with Spring integration

  12. 12

    Implement Keyset paging in a reader for a spring batch job

  13. 13

    How to implement a Java stream?

  14. 14

    How to implement a writable stream

  15. 15

    scalaz-stream how to implement `ask-then-wait-reply` tcp client

  16. 16

    reply timeout in spring integration tcp gateway

  17. 17

    Spring integration TCP server not receiving messages

  18. 18

    TCP Client Spring Integration with Java Config

  19. 19

    Spring Integration tcp/ip connection delay

  20. 20

    Spring integration on reconnect TCP send handshake

  21. 21

    Listen for Spring Integration TCP Connection events

  22. 22

    Listen on TCP feed with spring-integration

  23. 23

    TCP Client Spring Integration with Legacy Server

  24. 24

    Spring Integration ByteArrayRawSerializer TCP Client Server

  25. 25

    Spring Integration TCP doesn't send messages

  26. 26

    Is it possible use custom header in Spring Integration TCP?

  27. 27

    Spring Integration TCP factory error handling

  28. 28

    how to implement integration router in java

  29. 29

    Implement a consumer and producer system using Spring integration

HotTag

Archive