![]() | 1 Graves OP 感觉像是 netty 绑定端口的时候阻塞了主线程,导致 springboot 到达不了启动 tomcat 内置容器的那一步 |
![]() | 2 Graves OP 这里 netty 的作用我用来做 udp 服务器,用到 tomcat 是为了 websocket 服务,需求是有一个 NB 给我轮询发送数据,接受到数据要及时刷新网页渲染 |
3 wbf1013 2019-04-10 23:21:14 +08:00 via Android 直接用 netty 做 websocket 服务不好吗? |
4 soloV2 2019-04-11 01:18:12 +08:00 via iPhone netty 做 websocket 和 http 服务的例子 https://m.gitee.com/geliang/Umsp-netty |
![]() | 5 sutra 2019-04-11 07:09:44 +08:00 把整个 org.spring....boot 的日志打开成 INFO 甚至 ALL 级别再看看日志。 |
![]() | 6 MoHen9 2019-04-11 07:49:43 +08:00 via Android 创建 Netty 服务时,在子线程创建,或者不调用 closeFuture 方法去阻塞 |
7 hantsy 209-04-11 08:00:43 +08:00 直接用 Netty 做 HTTP 服务器就完事了,Spring 5 现在支持 Reactive 编程,Spring Boot 中添加 spring-boot-starter-reactive 依赖,默认使用 Netty。 |
![]() | 8 yuyizyk 2019-04-11 09:13:22 +08:00 让你的 netty 在 mvc servlet runner 之后运行就可以了。至于阻塞主线程...至少我当时并不是这个问题 |
9 IamNotShady 2019-04-11 09:22:10 +08:00 升级 spring boot 版本到 2.X 呢? |
![]() | 10 cnsoloer 2019-04-11 10:31:31 +08:00 有像我一样直接用 Netty 做 HTTP,TCP,UDP,Websocket 服务器的吗。 至于 REST,通过注解和正则表达式,做路径和参数匹配到方法。 |
11 ala2008 2019-04-11 11:22:56 +08:00 6 楼加一? |
12 dbpe 2019-04-11 13:23:10 +08:00 直接用 vertx 不好么..../ |
13 xinQing 2019-04-30 10:00:37 +08:00 你是不是启动 netty 阻塞了 main 啊,用一个新的线程启动 netty 就好了。我之前在 spring boot 中集成 netty 做 websocket 聊天,是在 spring 容器刷新后,再用新线程启动 netty 服务。下面的事例代码可以参考下: /** * spring 容器刷新时启动 netty 的 WebSocket 服务 * * Created by xuan on 2018/3/5 */ @Component public class ApplicationRefreshListener implements ApplicationListener<ContextStartedEvent> { private static final Logger LOG = LoggerFactory.getLogger(ApplicationRefreshListener.class); private ExecutorService webSocketSinglePool; @PostConstruct public void setup() { ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() .setNameFormat("webSocketSinglePool-%d").build(); webSocketSinglePool = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); LOG.info("webSocketSinglePool init."); } @Override public void onApplicationEvent(ContextRefreshedEvent event) { runWebSocketServer(event.getApplicationContext()); } private void runWebSocketServer(ApplicationContext applicationContext) { final WebSocketServer webSocketServer = applicationContext.getBean(WebSocketServer.class); webSocketSinglePool.execute(() -> { try { webSocketServer.listenAndServe(); } catch (Exception e) { LOG.error("webSocket listen and serve error.", e); } }); } @PreDestroy public void cleanup() { webSocketSinglePool.shutdown(); LOG.info("webSocketSinglePool destroyed."); } } |