@ComponentpublicclassRabbitmqConfig{privatefinalstaticStringmessage="web.socket.message";privatefinalstaticStringmessages="send.socket.message";@BeanpublicQueuequeueMessage(){returnnewQueue(RabbitmqConfig.message);}@BeanpublicQueuequeueMessages(){returnnewQueue(RabbitmqConfig.messages);}@BeanTopicExchangeexchange(){returnnewTopicExchange("exchange");}@BeanBindingbindingExchangeMessage(QueuequeueMessage,TopicExchangeexchange){returnBindingBuilder.bind(queueMessage).to(exchange).with("web.#");}@BeanBindingbindingExchangeMessages(QueuequeueMessages,TopicExchangeexchange){returnBindingBuilder.bind(queueMessages).to(exchange).with("send.#");}}ServerBootstrapbootstrap=newServerBootstrap().group(bossGroup,workGroup).channel(NioServerSocketChannel.class).childHandler(newServerChannelInitializer()).localAddress(socketAddress)//设置队列大小.option(ChannelOption.SO_BACKLOG,1024)//两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文.childOption(ChannelOption.SO_KEEPALIVE,true);//绑定端口,开始接收进来的连接完整代码,下载有详细说明,使用于长报文通讯,将报文长度截取一定字节发送,便于网速传输中丢包
1