NettyConfig.java 922 B

1234567891011121314151617181920212223242526272829
  1. package com.zhentao.config;
  2. import io.netty.bootstrap.ServerBootstrap;
  3. import io.netty.channel.ChannelOption;
  4. import io.netty.channel.nio.NioEventLoopGroup;
  5. import io.netty.channel.socket.nio.NioServerSocketChannel;
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.context.annotation.Bean;
  8. import org.springframework.context.annotation.Configuration;
  9. /**
  10. * Netty服务器配置类
  11. */
  12. @Configuration
  13. public class NettyConfig {
  14. @Value("${netty.port:8888}")
  15. private int port;
  16. @Bean
  17. public ServerBootstrap serverBootstrap() {
  18. ServerBootstrap bootstrap = new ServerBootstrap();
  19. bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup())
  20. .channel(NioServerSocketChannel.class)
  21. .option(ChannelOption.SO_BACKLOG, 128)
  22. .childOption(ChannelOption.SO_KEEPALIVE, true);
  23. return bootstrap;
  24. }
  25. }