netty - Spring boot camel tcp configuration options - Stack Overflow

admin2025-05-02  2

I am using spring boot camel for managing the tcp connections. I want to add configurations for setting max concurrent connections, and connection time out for tcp connections. Could someone guide me with the same.

Attaching the sample code for reference

@Override
    public void configure() throws Exception {
        // Define the TCP server route
        try {

            onException(IOException.class)
                    .handled(true)  // Mark the exception as handled
                    .log("IOException (likely channel closed): ${exception.message}")
                    .to("mock:error");

            onException(ClosedChannelException.class)
                    .handled(true)  // Mark the exception as handled
                    .log("Channel closed by client: ${exception.message}")
                    .to("mock:error");

            onException(SocketException.class)
                    .handled(true)  // Mark the exception as handled
                    .log("Client closed the TCP connection: ${exception.message}")
                    .to("mock:handled");

            from("netty:tcp://" + host + ":" + port + "?connectTimeout=50").to(
                            "micrometer:timer:simple.timer?action=start")
                    .routeConfigurationId("tcpServerRoute")
                    .log(LoggingLevel.DEBUG, "Received message: ${body}")
                    .process(customMessageProcessor).transform()
                    .simple("${body}")  // Optionally transform or process the message
                    .to("micrometer:counter:simple.counter")
                    .to("micrometer:timer:simple.timer?action=stop").to("log:received-tcp");
        } catch (Exception exception) {
            appLog.error("Error occured while performing the tcp operation:{} ",
                    exception.getMessage(), exception);
        }

    }


pom file


    <dependency>
      <groupId>org.apache.camel.springboot</groupId>
      <artifactId>camel-spring-boot-starter</artifactId>
      <version>4.8.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel.springboot</groupId>
      <artifactId>camel-netty-starter</artifactId>
      <version>4.8.2</version>
    </dependency>

I tried to configure IdleStateHandler but not working as expected. Request anyone have prior experience on this.

转载请注明原文地址:http://www.anycun.com/QandA/1746121898a91974.html