├── .gitignore ├── .project ├── LICENSE ├── README.md ├── broker ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── cn │ │ │ │ └── dbw │ │ │ │ ├── Boot.java │ │ │ │ ├── container │ │ │ │ ├── ClusterTopicHoder.java │ │ │ │ ├── MemoryTopicHoder.java │ │ │ │ ├── TopicBroadcastable.java │ │ │ │ ├── TopicHolder.java │ │ │ │ └── TopicManager.java │ │ │ │ ├── server │ │ │ │ ├── BrokeServer.java │ │ │ │ ├── HttpServer.java │ │ │ │ ├── MessageConsumerImpl4Server.java │ │ │ │ ├── Server.java │ │ │ │ └── handler │ │ │ │ │ ├── AuthenticationHandler.java │ │ │ │ │ ├── ChanelInitializerHandler.java │ │ │ │ │ ├── IdleStateTrigger.java │ │ │ │ │ ├── MessageEncoder.java │ │ │ │ │ ├── MessageProcessHandler.java │ │ │ │ │ ├── MessageToPoDecoder.java │ │ │ │ │ ├── TopicManagerHandler.java │ │ │ │ │ └── http │ │ │ │ │ └── HttpHandler.java │ │ │ │ └── zk │ │ │ │ └── ZkRegister.java │ │ └── resources │ │ │ ├── config.properties │ │ │ └── log4j.properties │ └── test │ │ └── java │ │ └── broker │ │ └── Test.java ├── vincent_player_debug.log ├── vincent_player_debug.log.2019-01-03 ├── vincent_player_debug.log.2019-01-07 └── vincent_player_error.log ├── client ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── cn │ │ │ │ └── dbw │ │ │ │ ├── api │ │ │ │ ├── Authable.java │ │ │ │ └── PubAndSubClient.java │ │ │ │ ├── client │ │ │ │ ├── ChannelHolder.java │ │ │ │ ├── Client.java │ │ │ │ ├── MessageConsumerImpl4Client.java │ │ │ │ ├── NettyClient.java │ │ │ │ ├── NettyClusterPubAndSubClient.java │ │ │ │ ├── NettyPubAndSubClient.java │ │ │ │ ├── SubRecorder.java │ │ │ │ ├── handler │ │ │ │ │ ├── IdleStateTrigger.java │ │ │ │ │ ├── MessageEncoder.java │ │ │ │ │ ├── MessageProcessHandler.java │ │ │ │ │ └── MessageToPoDecoder.java │ │ │ │ └── listener │ │ │ │ │ └── ConnectionListener.java │ │ │ │ ├── event │ │ │ │ ├── EventBus.java │ │ │ │ └── Handler.java │ │ │ │ └── zk │ │ │ │ └── ZKReceiver.java │ │ └── resources │ │ │ └── log4j.properties │ └── test │ │ └── java │ │ └── client │ │ ├── KafkaDeSerialization.java │ │ ├── KafkaPublisherTest.java │ │ ├── KafkaReciverTest.java │ │ ├── KafkaSerialization.java │ │ ├── Test2.java │ │ ├── TestBroad.java │ │ ├── TestClient.java │ │ ├── TestHttp.java │ │ ├── TestMsg.java │ │ └── TestPublish.java ├── vincent_player_debug.log ├── vincent_player_debug.log.2018-12-28 ├── vincent_player_error.log └── vincent_player_error.log.2018-12-28 ├── netty-common ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ └── java │ └── cn │ └── dbw │ ├── config │ ├── ConfigFactory.java │ ├── FuncodeEnum.java │ ├── PropertyConfigFactory.java │ ├── ServerConfig.java │ └── ZkConstants.java │ ├── disruptor │ ├── DisruptorBoot.java │ ├── MessageConsumer.java │ ├── MessageProducer.java │ └── RingBufferWorkerPoolFactory.java │ ├── dto │ └── Message.java │ ├── exception │ └── IllegalDataHeaderException.java │ ├── po │ ├── LastLoginRecord.java │ ├── MessageWrapper.java │ └── NoticResult.java │ └── util │ ├── DateUtils.java │ ├── MD5Util.java │ ├── PropertyUtil.java │ ├── SerializationUtil.java │ └── StringTools.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | 11 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 12 | !/.mvn/wrapper/maven-wrapper.jar 13 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | netty-pubsub 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 s6056826 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # netty-pubsub 2 | 3 | #### 介绍 4 | 百万级高性能分布式发布订阅系统,基于nio,netty开发,无锁并发,充分发挥cpu极限, 5 | 该项目已自带心跳检测功能,断线自动重连,非常稳定。 6 | 注意该项目软件编码为GBK,导入的时候一定要看清项目编码格式。 7 | 8 | #### 软件架构 9 | 软件架构说明 10 | 11 | netty+zookeeper+disruptor分布式发布订阅系统 12 | 13 | 14 | #### 安装教程 15 | 16 | 1. xxxx 17 | 2. xxxx 18 | 3. xxxx 19 | 20 | #### 使用说明 21 | 22 | 1. broker启动 运行boot类 23 | 2. client 有订阅者和发布者,具体代码可以在test中有测试用例 24 | 3. 现阶段分布式还没发布,需要测试的可以有单机版,切换单机版,需要在resouces下的config.properties的enableCluster=false 25 | 26 | 27 | #### 代码用例 28 | 29 | 1.broker启动src/main/java 下的 Boot.java 30 | 31 | 2.client测试 32 | ``` 33 | //创建客户端 34 | NettyPubAndSubClient client = NettyPubAndSubClient.getInstance(); 35 | //客户端连接 36 | client.connect("127.0.0.1",9999); 37 | //传入订阅主题,和监听器 38 | client.subscribe("mm", new SubscribListener() { 39 | @Override 40 | public void subOk(Message message) { 41 | System.out.println("订阅成功"); 42 | } 43 | @Override 44 | public void msgActive(Message message) { 45 | try { 46 | System.out.println("收到消息mm:"+new String(message.getData(),"utf-8")); 47 | } catch (UnsupportedEncodingException e) { 48 | // TODO Auto-generated catch block 49 | e.printStackTrace(); 50 | } 51 | } 52 | }); 53 | //接收广播 54 | client.acceptBraodCast(new SubscribListener() { 55 | @Override 56 | public void msgActive(Message message) { 57 | try { 58 | System.out.println("接收广播消息:"+new String(message.getData(),"utf-8")); 59 | } catch (UnsupportedEncodingException e) { 60 | // TODO Auto-generated catch block 61 | e.printStackTrace(); 62 | } 63 | } 64 | }); 65 | //发布消息 66 | client.publish("mm", "哈哈"); 67 | //发送广播 68 | client.broadcast("hello 广播"); 69 | //优雅关闭 70 | client.shutdown(); 71 | ``` 72 | 73 | 74 | #### 参与贡献 75 | 76 | 1. Fork 本仓库 77 | 2. 新建 Feat_xxx 分支 78 | 3. 提交代码 79 | 4. 新建 Pull Request 80 | -------------------------------------------------------------------------------- /broker/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /broker/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | broker 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /broker/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java/cn/dbw/server/handler/IdleStateTrigger.java=UTF-8 3 | encoding//src/main/resources/config.properties=UTF-8 4 | encoding//src/main/resources/log4j.properties=UTF-8 5 | -------------------------------------------------------------------------------- /broker/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /broker/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /broker/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | cn.dbw 5 | netty-pubsub 6 | 0.0.1-SNAPSHOT 7 | 8 | broker 9 | netty-broker 10 | 11 | 12 | 13 | 14 | io.netty 15 | netty-all 16 | 17 | 18 | 19 | 20 | com.google.protobuf 21 | protobuf-java 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.objenesis 32 | objenesis 33 | 34 | 35 | 36 | 37 | com.dyuproject.protostuff 38 | protostuff-core 39 | 40 | 41 | com.dyuproject.protostuff 42 | protostuff-runtime 43 | 44 | 45 | 46 | 47 | com.alibaba 48 | fastjson 49 | 50 | 51 | 52 | log4j 53 | log4j 54 | 55 | 56 | 57 | cn.dbw 58 | netty-common 59 | 0.0.1-SNAPSHOT 60 | 61 | 62 | 63 | org.jodd 64 | jodd-all 65 | 66 | 67 | 68 | org.apache.zookeeper 69 | zookeeper 70 | 71 | 72 | 73 | com.github.sgroschupf 74 | zkclient 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | maven-assembly-plugin 83 | 84 | false 85 | 86 | jar-with-dependencies 87 | 88 | 89 | 90 | 91 | cn.dbw.Boot 92 | 93 | 94 | 95 | 96 | 97 | make-assembly 98 | package 99 | 100 | assembly 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/Boot.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/Boot.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/container/ClusterTopicHoder.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/container/ClusterTopicHoder.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/container/MemoryTopicHoder.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/container/MemoryTopicHoder.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/container/TopicBroadcastable.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.container; 2 | 3 | import cn.dbw.config.FuncodeEnum; 4 | import cn.dbw.util.MD5Util; 5 | 6 | public interface TopicBroadcastable { 7 | 8 | final byte [] BROAD_TOPIC=MD5Util.getPwd(FuncodeEnum.MESSAGE_BROAD.name().concat("$")).substring(0, 12).getBytes(); 9 | 10 | void brodcast(byte[] data); 11 | } 12 | -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/container/TopicHolder.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/container/TopicHolder.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/container/TopicManager.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.container; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | import cn.dbw.config.FuncodeEnum; 7 | import cn.dbw.dto.Message; 8 | import cn.dbw.util.MD5Util; 9 | import cn.dbw.util.StringTools; 10 | import io.netty.channel.Channel; 11 | 12 | public class TopicManager implements TopicHolder ,TopicBroadcastable{ 13 | 14 | private TopicHolder topicHolder; 15 | 16 | public TopicManager(TopicHolderType topicHolderType) { 17 | switch (topicHolderType) { 18 | case MemoryTopicHolder: 19 | topicHolder=MemoryTopicHoder.getInstance(); 20 | break; 21 | } 22 | } 23 | 24 | public void publish(byte[] topic,byte[] data){ 25 | Set set = topicHolder.getTopic(topic); 26 | if(set!=null&&set.size()>0){ 27 | set.parallelStream().forEach((c)->{ 28 | c.writeAndFlush(new Message(FuncodeEnum.MESSAGE_SEND, (byte)1, topic,data.length, data)); 29 | }); 30 | } 31 | } 32 | 33 | @Override 34 | public void remove(byte[] topic) { 35 | topicHolder.remove(topic); 36 | 37 | } 38 | 39 | @Override 40 | public void remove(byte[] topic, Channel channel) { 41 | topicHolder.remove(topic,channel); 42 | } 43 | 44 | @Override 45 | public void subscribe(byte[] topic, Channel channel) { 46 | topicHolder.subscribe(topic, channel); 47 | } 48 | 49 | @Override 50 | public Set getTopic(byte[] topic) { 51 | return topicHolder.getTopic(topic); 52 | } 53 | 54 | @Override 55 | public Map> getTopicContainner() { 56 | return topicHolder.getTopicContainner(); 57 | } 58 | 59 | 60 | public static enum TopicHolderType{ 61 | MemoryTopicHolder; 62 | } 63 | 64 | 65 | @Override 66 | public void remove(Channel channel) { 67 | topicHolder.remove(channel); 68 | } 69 | 70 | @Override 71 | public void brodcast(byte[] data) { 72 | publish(TopicBroadcastable.BROAD_TOPIC,data); 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/BrokeServer.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/server/BrokeServer.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/HttpServer.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/server/HttpServer.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/MessageConsumerImpl4Server.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/server/MessageConsumerImpl4Server.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/Server.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.server; 2 | 3 | public interface Server { 4 | 5 | 6 | void start(); 7 | 8 | void stop(); 9 | 10 | 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/handler/AuthenticationHandler.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/server/handler/AuthenticationHandler.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/handler/ChanelInitializerHandler.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/server/handler/ChanelInitializerHandler.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/handler/IdleStateTrigger.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.server.handler; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | import cn.dbw.server.BrokeServer; 6 | import cn.dbw.util.DateUtils; 7 | import io.netty.channel.ChannelHandlerContext; 8 | import io.netty.channel.ChannelInboundHandlerAdapter; 9 | import io.netty.channel.SimpleChannelInboundHandler; 10 | import io.netty.handler.timeout.IdleStateEvent; 11 | 12 | public class IdleStateTrigger extends ChannelInboundHandlerAdapter { 13 | 14 | private final Logger LOGGER=Logger.getLogger(IdleStateTrigger.class); 15 | 16 | 17 | @Override 18 | public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { 19 | if(evt instanceof IdleStateEvent){ 20 | IdleStateEvent event= (IdleStateEvent) evt; 21 | switch (event.state()){ 22 | case READER_IDLE: 23 | //服务端触发事件,说明客户端已经掉线,关闭失效连接 24 | LOGGER.error("【客户端已断开】"+ctx.channel().remoteAddress()+" "+DateUtils.getCurrentDateTime()); 25 | ctx.close(); 26 | break; 27 | } 28 | } 29 | super.userEventTriggered(ctx, evt); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/handler/MessageEncoder.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.server.handler; 2 | 3 | import cn.dbw.dto.Message; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.channel.ChannelHandlerContext; 6 | import io.netty.handler.codec.MessageToByteEncoder; 7 | 8 | public class MessageEncoder extends MessageToByteEncoder { 9 | 10 | @Override 11 | protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) throws Exception { 12 | out.writeByte(msg.getBODY_HEAD()); 13 | out.writeByte(msg.getFunCode().getCode()); 14 | out.writeByte(msg.getIsHaveTopic()); 15 | if(msg.getIsHaveTopic()==1){ 16 | out.writeInt(msg.getBodyLength()+12); 17 | out.writeBytes(msg.getTopic()); 18 | }else{ 19 | out.writeInt(msg.getBodyLength()); 20 | } 21 | out.writeBytes(msg.getData()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/handler/MessageProcessHandler.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/server/handler/MessageProcessHandler.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/handler/MessageToPoDecoder.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/server/handler/MessageToPoDecoder.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/handler/TopicManagerHandler.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/server/handler/TopicManagerHandler.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/server/handler/http/HttpHandler.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/server/handler/http/HttpHandler.java -------------------------------------------------------------------------------- /broker/src/main/java/cn/dbw/zk/ZkRegister.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/src/main/java/cn/dbw/zk/ZkRegister.java -------------------------------------------------------------------------------- /broker/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | 2 | #服务器配置 3 | [server] 4 | host=127.0.0.1 5 | port=9999 6 | retryCount=20 7 | connectTimeout=10 8 | enableCluster=false 9 | 10 | #zookeeper配置 11 | [zkServer] 12 | servers=127.0.0.1:2181 13 | sessionTimeout=10000 14 | rootPath=/broker_active -------------------------------------------------------------------------------- /broker/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | ### 设置### 2 | log4j.rootLogger = info,stdout,D,E 3 | 4 | ### 输出信息到控制抬 ### 5 | log4j.appender.stdout = org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target = System.out 7 | log4j.appender.stdout.layout = org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n 9 | 10 | ### 输出DEBUG 级别以上的日志文件设置 ### 11 | log4j.appender.D = org.apache.log4j.DailyRollingFileAppender 12 | log4j.appender.D.File = vincent_player_debug.log 13 | log4j.appender.D.Append = true 14 | log4j.appender.D.Threshold = DEBUG 15 | log4j.appender.D.layout = org.apache.log4j.PatternLayout 16 | log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n 17 | 18 | ### 输出ERROR 级别以上的日志文件设置 ### 19 | log4j.appender.E = org.apache.log4j.DailyRollingFileAppender 20 | log4j.appender.E.File = vincent_player_error.log 21 | log4j.appender.E.Append = true 22 | log4j.appender.E.Threshold = ERROR 23 | log4j.appender.E.layout = org.apache.log4j.PatternLayout 24 | log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n -------------------------------------------------------------------------------- /broker/src/test/java/broker/Test.java: -------------------------------------------------------------------------------- 1 | 2 | package broker; 3 | 4 | import cn.dbw.config.FuncodeEnum; 5 | 6 | public class Test { 7 | 8 | public static void main(String[] args) { 9 | String a="a"; 10 | System.out.println(a.getBytes().length); 11 | System.out.println("{asd".startsWith("{")); 12 | 13 | System.out.println(FuncodeEnum.MESSAGE_BROAD.name()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /broker/vincent_player_debug.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/vincent_player_debug.log -------------------------------------------------------------------------------- /broker/vincent_player_debug.log.2019-01-03: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/vincent_player_debug.log.2019-01-03 -------------------------------------------------------------------------------- /broker/vincent_player_debug.log.2019-01-07: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/vincent_player_debug.log.2019-01-07 -------------------------------------------------------------------------------- /broker/vincent_player_error.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/broker/vincent_player_error.log -------------------------------------------------------------------------------- /client/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /client/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | client 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /client/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /client/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | cn.dbw 5 | netty-pubsub 6 | 0.0.1-SNAPSHOT 7 | 8 | client 9 | 10 | 11 | 12 | 13 | io.netty 14 | netty-all 15 | 16 | 17 | 18 | 19 | com.google.protobuf 20 | protobuf-java 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.objenesis 31 | objenesis 32 | 33 | 34 | 35 | 36 | com.dyuproject.protostuff 37 | protostuff-core 38 | 39 | 40 | com.dyuproject.protostuff 41 | protostuff-runtime 42 | 43 | 44 | 45 | 46 | com.alibaba 47 | fastjson 48 | 49 | 50 | 51 | org.jodd 52 | jodd-all 53 | 54 | 55 | log4j 56 | log4j 57 | 58 | 59 | 60 | cn.dbw 61 | netty-common 62 | 0.0.1-SNAPSHOT 63 | 64 | 65 | 66 | 67 | org.apache.zookeeper 68 | zookeeper 69 | 70 | 71 | 72 | com.github.sgroschupf 73 | zkclient 74 | 75 | 76 | 77 | org.apache.kafka 78 | kafka-clients 79 | 0.11.0.0 80 | 81 | 82 | 83 | 84 | 85 | 86 | maven-assembly-plugin 87 | 88 | false 89 | 90 | jar-with-dependencies 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | make-assembly 99 | package 100 | 101 | assembly 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/api/Authable.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/api/Authable.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/api/PubAndSubClient.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/api/PubAndSubClient.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/ChannelHolder.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.client; 2 | 3 | import io.netty.channel.Channel; 4 | 5 | public class ChannelHolder { 6 | 7 | private volatile static Channel channel; 8 | 9 | public static Channel getChannel() { 10 | while(channel==null){}; 11 | return channel; 12 | } 13 | 14 | public static void setChannel(Channel chan) { 15 | channel = chan; 16 | } 17 | 18 | 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/Client.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.client; 2 | 3 | public interface Client { 4 | 5 | void start(); 6 | 7 | void stop(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/MessageConsumerImpl4Client.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/client/MessageConsumerImpl4Client.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/NettyClient.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/client/NettyClient.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/NettyClusterPubAndSubClient.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.client; 2 | 3 | import cn.dbw.api.PubAndSubClient; 4 | 5 | public class NettyClusterPubAndSubClient implements PubAndSubClient { 6 | 7 | 8 | @Override 9 | public void subscribe(String topic, SubscribListener subscribListener) { 10 | // TODO Auto-generated method stub 11 | 12 | } 13 | 14 | @Override 15 | public void unsubscribe(String topic) { 16 | // TODO Auto-generated method stub 17 | 18 | } 19 | 20 | @Override 21 | public void publish(String topic, String str) { 22 | // TODO Auto-generated method stub 23 | 24 | } 25 | 26 | @Override 27 | public void broadcast(String data) { 28 | // TODO Auto-generated method stub 29 | 30 | } 31 | 32 | @Override 33 | public void connect(String host, Integer port) { 34 | // TODO Auto-generated method stub 35 | 36 | } 37 | 38 | 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/NettyPubAndSubClient.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/client/NettyPubAndSubClient.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/SubRecorder.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/client/SubRecorder.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/handler/IdleStateTrigger.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/client/handler/IdleStateTrigger.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/handler/MessageEncoder.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/client/handler/MessageEncoder.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/handler/MessageProcessHandler.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/client/handler/MessageProcessHandler.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/handler/MessageToPoDecoder.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/client/handler/MessageToPoDecoder.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/client/listener/ConnectionListener.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/client/listener/ConnectionListener.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/event/EventBus.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/event/EventBus.java -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/event/Handler.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.event; 2 | 3 | import cn.dbw.config.FuncodeEnum; 4 | import cn.dbw.dto.Message; 5 | 6 | public abstract class Handler { 7 | 8 | 9 | public void sendMsg(Message obj,FuncodeEnum funcodeEnum){ 10 | onMsg(obj, funcodeEnum); 11 | } 12 | 13 | 14 | public abstract void onMsg(Message obj,FuncodeEnum funcodeEnum); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /client/src/main/java/cn/dbw/zk/ZKReceiver.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/main/java/cn/dbw/zk/ZKReceiver.java -------------------------------------------------------------------------------- /client/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | 2 | log4j.rootLogger = info,stdout 3 | 4 | log4j.appender.stdout = org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.Target = System.out 6 | log4j.appender.stdout.layout = org.apache.log4j.PatternLayout 7 | log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n 8 | 9 | 10 | -------------------------------------------------------------------------------- /client/src/test/java/client/KafkaDeSerialization.java: -------------------------------------------------------------------------------- 1 | package client; 2 | 3 | import java.util.Map; 4 | 5 | import org.apache.kafka.common.serialization.Deserializer; 6 | 7 | import cn.dbw.util.SerializationUtil; 8 | 9 | public class KafkaDeSerialization implements Deserializer { 10 | 11 | @Override 12 | public void configure(Map configs, boolean isKey) { 13 | // TODO Auto-generated method stub 14 | 15 | } 16 | 17 | @Override 18 | public TestMsg deserialize(String topic, byte[] data) { 19 | // TODO Auto-generated method stub 20 | if(data!=null&&data.length>0) 21 | return SerializationUtil.deserialize(data, TestMsg.class); 22 | else return null; 23 | } 24 | 25 | @Override 26 | public void close() { 27 | // TODO Auto-generated method stub 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /client/src/test/java/client/KafkaPublisherTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/test/java/client/KafkaPublisherTest.java -------------------------------------------------------------------------------- /client/src/test/java/client/KafkaReciverTest.java: -------------------------------------------------------------------------------- 1 | package client; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collection; 5 | import java.util.Properties; 6 | 7 | import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; 8 | import org.apache.kafka.clients.consumer.ConsumerRecord; 9 | import org.apache.kafka.clients.consumer.ConsumerRecords; 10 | import org.apache.kafka.clients.consumer.KafkaConsumer; 11 | import org.apache.kafka.common.TopicPartition; 12 | 13 | public class KafkaReciverTest { 14 | 15 | public static void main(String[] args) { 16 | Properties properties = new Properties(); 17 | properties.put("bootstrap.servers", "127.0.0.1:9092"); 18 | properties.put("group.id", "group-3"); 19 | properties.put("enable.auto.commit", "true"); 20 | properties.put("auto.commit.interval.ms", "1000"); 21 | properties.put("auto.offset.reset", "earliest"); 22 | properties.put("session.timeout.ms", "30000"); 23 | properties.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); 24 | properties.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); 25 | //properties.put("value.deserializer", "client.KafkaDeSerialization"); 26 | KafkaConsumer kafkaConsumer = new KafkaConsumer<>(properties); 27 | kafkaConsumer.subscribe(Arrays.asList("HelloWorld")); 28 | while (true) { 29 | ConsumerRecords records = kafkaConsumer.poll(100); 30 | if(records.count()>0) 31 | for (ConsumerRecord record : records) { 32 | System.out.printf("offset = %d, value = %s", record.offset(), record.value()); 33 | System.out.println(); 34 | } 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /client/src/test/java/client/KafkaSerialization.java: -------------------------------------------------------------------------------- 1 | package client; 2 | 3 | import java.util.Map; 4 | 5 | import org.apache.kafka.common.serialization.Serializer; 6 | 7 | import cn.dbw.util.SerializationUtil; 8 | 9 | public class KafkaSerialization implements Serializer { 10 | 11 | @Override 12 | public void configure(Map configs, boolean isKey) { 13 | // TODO Auto-generated method stub 14 | 15 | } 16 | 17 | @Override 18 | public byte[] serialize(String topic, TestMsg data) { 19 | return SerializationUtil.serialize(data); 20 | } 21 | 22 | @Override 23 | public void close() { 24 | // TODO Auto-generated method stub 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /client/src/test/java/client/Test2.java: -------------------------------------------------------------------------------- 1 | package client; 2 | 3 | public class Test2 { 4 | public static void main(String[] args) { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /client/src/test/java/client/TestBroad.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/test/java/client/TestBroad.java -------------------------------------------------------------------------------- /client/src/test/java/client/TestClient.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/test/java/client/TestClient.java -------------------------------------------------------------------------------- /client/src/test/java/client/TestHttp.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/test/java/client/TestHttp.java -------------------------------------------------------------------------------- /client/src/test/java/client/TestMsg.java: -------------------------------------------------------------------------------- 1 | package client; 2 | 3 | import java.io.Serializable; 4 | 5 | public class TestMsg implements Serializable{ 6 | 7 | /** 8 | * 9 | */ 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Integer id; 13 | 14 | private String msg; 15 | 16 | public Integer getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Integer id) { 21 | this.id = id; 22 | } 23 | 24 | public String getMsg() { 25 | return msg; 26 | } 27 | 28 | public void setMsg(String msg) { 29 | this.msg = msg; 30 | } 31 | 32 | public TestMsg(Integer id, String msg) { 33 | super(); 34 | this.id = id; 35 | this.msg = msg; 36 | } 37 | 38 | 39 | public TestMsg() { 40 | // TODO Auto-generated constructor stub 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "TestMsg [id=" + id + ", msg=" + msg + "]"; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /client/src/test/java/client/TestPublish.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/src/test/java/client/TestPublish.java -------------------------------------------------------------------------------- /client/vincent_player_debug.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/vincent_player_debug.log -------------------------------------------------------------------------------- /client/vincent_player_debug.log.2018-12-28: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/vincent_player_debug.log.2018-12-28 -------------------------------------------------------------------------------- /client/vincent_player_error.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/vincent_player_error.log -------------------------------------------------------------------------------- /client/vincent_player_error.log.2018-12-28: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/client/vincent_player_error.log.2018-12-28 -------------------------------------------------------------------------------- /netty-common/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /netty-common/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | netty-common 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /netty-common/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java/cn/dbw/util/SerializationUtil.java=UTF-8 3 | -------------------------------------------------------------------------------- /netty-common/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /netty-common/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /netty-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | cn.dbw 5 | netty-pubsub 6 | 0.0.1-SNAPSHOT 7 | 8 | netty-common 9 | 10 | 11 | 12 | org.objenesis 13 | objenesis 14 | 15 | 16 | 17 | 18 | com.dyuproject.protostuff 19 | protostuff-core 20 | 21 | 22 | com.dyuproject.protostuff 23 | protostuff-runtime 24 | 25 | 26 | 27 | org.jodd 28 | jodd-all 29 | 30 | 31 | 32 | 33 | io.netty 34 | netty-all 35 | 36 | 37 | 38 | com.bfxy 39 | disruptor-netty-com 40 | 41 | 42 | -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/config/ConfigFactory.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.config; 2 | 3 | public interface ConfigFactory { 4 | 5 | String filaPath="config.properties"; 6 | 7 | ServerConfig getConfig(String filePath); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/config/FuncodeEnum.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/config/FuncodeEnum.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/config/PropertyConfigFactory.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/config/PropertyConfigFactory.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/config/ServerConfig.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/config/ServerConfig.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/config/ZkConstants.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.config; 2 | 3 | public class ZkConstants { 4 | 5 | public static final String ZK_ROOT_PATH="/broker_active"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/disruptor/DisruptorBoot.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/disruptor/DisruptorBoot.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/disruptor/MessageConsumer.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.disruptor; 2 | 3 | import java.util.UUID; 4 | 5 | import com.lmax.disruptor.WorkHandler; 6 | 7 | import cn.dbw.po.MessageWrapper; 8 | 9 | public abstract class MessageConsumer implements WorkHandler { 10 | 11 | protected String consumerId=UUID.randomUUID().toString(); 12 | 13 | 14 | public String getConsumerId() { 15 | return consumerId; 16 | } 17 | 18 | public void setConsumerId(String consumerId) { 19 | this.consumerId = consumerId; 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/disruptor/MessageProducer.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/disruptor/MessageProducer.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/disruptor/RingBufferWorkerPoolFactory.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/disruptor/RingBufferWorkerPoolFactory.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/dto/Message.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/dto/Message.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/exception/IllegalDataHeaderException.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/exception/IllegalDataHeaderException.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/po/LastLoginRecord.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/po/LastLoginRecord.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/po/MessageWrapper.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/po/MessageWrapper.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/po/NoticResult.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.po; 2 | 3 | public class NoticResult { 4 | // 5 | // private String msg; 6 | // private 7 | 8 | } 9 | -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/util/DateUtils.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/util/DateUtils.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/util/MD5Util.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s6056826/netty-pubsub/ef18f171216308173149a7036399153a8a023e98/netty-common/src/main/java/cn/dbw/util/MD5Util.java -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/util/PropertyUtil.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.util; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.util.HashMap; 7 | 8 | import jodd.props.Props; 9 | import jodd.props.PropsEntries; 10 | 11 | public class PropertyUtil { 12 | 13 | public static HashMap load() throws IOException{ 14 | Props props = new Props(); 15 | HashMap hashMap = new HashMap<>(); 16 | InputStream in=PropertyUtil.class.getClassLoader().getResourceAsStream("config.properties"); 17 | props.load(in); 18 | PropsEntries entries = props.entries(); 19 | entries.forEach((r)->{ 20 | hashMap.put(r.getKey(), r.getValue()); 21 | }); 22 | return hashMap; 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/util/SerializationUtil.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.util; 2 | 3 | 4 | import com.dyuproject.protostuff.LinkedBuffer; 5 | import com.dyuproject.protostuff.ProtostuffIOUtil; 6 | import com.dyuproject.protostuff.Schema; 7 | import com.dyuproject.protostuff.runtime.RuntimeSchema; 8 | import org.objenesis.Objenesis; 9 | import org.objenesis.ObjenesisStd; 10 | 11 | import java.util.Map; 12 | import java.util.concurrent.ConcurrentHashMap; 13 | 14 | 15 | 16 | /** 17 | * 序列化工具类(基于 Protostuff 实现) 18 | * 19 | * @author huangyong 20 | * @since 1.0.0 21 | */ 22 | public class SerializationUtil { 23 | 24 | private static Map, Schema> cachedSchema = new ConcurrentHashMap<>(); 25 | 26 | private static Objenesis objenesis = new ObjenesisStd(true); 27 | 28 | private SerializationUtil() { 29 | } 30 | 31 | /** 32 | * 序列化(对象 -> 字节数组) 33 | */ 34 | @SuppressWarnings("unchecked") 35 | public static byte[] serialize(T obj) { 36 | Class cls = (Class) obj.getClass(); 37 | LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE); 38 | try { 39 | Schema schema = getSchema(cls); 40 | return ProtostuffIOUtil.toByteArray(obj, schema, buffer); 41 | } catch (Exception e) { 42 | throw new IllegalStateException(e.getMessage(), e); 43 | } finally { 44 | buffer.clear(); 45 | } 46 | } 47 | 48 | /** 49 | * 反序列化(字节数组 -> 对象) 50 | */ 51 | public static T deserialize(byte[] data, Class cls) { 52 | try { 53 | T message = objenesis.newInstance(cls); 54 | Schema schema = getSchema(cls); 55 | ProtostuffIOUtil.mergeFrom(data, message, schema); 56 | return message; 57 | } catch (Exception e) { 58 | throw new IllegalStateException(e.getMessage(), e); 59 | } 60 | } 61 | 62 | @SuppressWarnings("unchecked") 63 | private static Schema getSchema(Class cls) { 64 | Schema schema = (Schema) cachedSchema.get(cls); 65 | if (schema == null) { 66 | schema = RuntimeSchema.createFrom(cls); 67 | cachedSchema.put(cls, schema); 68 | } 69 | return schema; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /netty-common/src/main/java/cn/dbw/util/StringTools.java: -------------------------------------------------------------------------------- 1 | package cn.dbw.util; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | 5 | public class StringTools { 6 | 7 | 8 | public static String toStrUTF(byte[] data){ 9 | if(null!=data){ 10 | try { 11 | return new String(data,"utf-8"); 12 | } catch (UnsupportedEncodingException e) { 13 | // TODO Auto-generated catch block 14 | e.printStackTrace(); 15 | } 16 | } 17 | return null; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | cn.dbw 4 | netty-pubsub 5 | 0.0.1-SNAPSHOT 6 | pom 7 | 一个基于netty的发布订阅 8 | 9 | 10 | 11 | 12 | 13 | 14 | io.netty 15 | netty-all 16 | 4.0.24.Final 17 | 18 | 19 | 20 | 21 | com.google.protobuf 22 | protobuf-java 23 | 3.3.0 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.objenesis 34 | objenesis 35 | 2.1 36 | 37 | 38 | 39 | 40 | com.dyuproject.protostuff 41 | protostuff-core 42 | 1.0.9 43 | 44 | 45 | com.dyuproject.protostuff 46 | protostuff-runtime 47 | 1.0.9 48 | 49 | 50 | 51 | 52 | com.alibaba 53 | fastjson 54 | 1.2.4 55 | 56 | 57 | 58 | org.jodd 59 | jodd-all 60 | 5.0.6 61 | 62 | 63 | 64 | log4j 65 | log4j 66 | 1.2.17 67 | 68 | 69 | 70 | org.apache.zookeeper 71 | zookeeper 72 | 3.4.9 73 | 74 | 75 | 76 | com.github.sgroschupf 77 | zkclient 78 | 0.1 79 | 80 | 81 | 82 | 83 | com.bfxy 84 | disruptor-netty-com 85 | 0.0.1-SNAPSHOT 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-compiler-plugin 95 | 3.1 96 | 97 | 1.8 98 | 1.8 99 | 100 | 101 | 102 | 103 | 104 | broker 105 | client 106 | netty-common 107 | 108 | --------------------------------------------------------------------------------