说明
官方网文档:https://docs.cometd.org/current5/reference/#_java_oort
原理就是,各个服务端,定义了一个客户端,伪装成正常连接 与server建立websocket链接,并订阅指定channel消息,这个客户端就是oort,server收到消息就会转发给oort客户端,oort客户端再广播出去
这里我们主要看OortStaticConfigServlet静态初始化
基本配置
server1
<servlet> <servlet-name>oort</servlet-name> <servlet-class>org.cometd.oort.OortStaticConfigServlet</servlet-class> <!--当前及诶单服务的ip端口,客户端需要链接到当前节点--> <init-param> <param-name>oort.url</param-name> <param-value>http://localhost:8081/cometd-demo-5.0.13-SNAPSHOT/cometd</param-value> </init-param> <!--内部维护的其他集群节点信息--> <init-param> <param-name>oort.cloud</param-name> <param-value>http://localhost:8082/cometd-demo-5.0.13-SNAPSHOT/cometd</param-value> </init-param>
<!--需要转发的channal消息-> <init-param> <param-name>oort.channels</param-name> <param-value>/chat/*,/members/*</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet>
server2
<servlet> <servlet-name>oort</servlet-name> <servlet-class>org.cometd.oort.OortStaticConfigServlet</servlet-class> <init-param> <param-name>oort.url</param-name> <param-value>http://localhost:8082/cometd-demo-5.0.13-SNAPSHOT/cometd</param-value> </init-param> <init-param> <param-name>oort.cloud</param-name> <param-value>http://localhost:8081/cometd-demo-5.0.13-SNAPSHOT/cometd</param-value> </init-param> <init-param> <param-name>oort.channels</param-name> <param-value>/chat/*,/members/*</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet>