在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:baffalotech开源软件地址:https://gitee.com/9123/baffalotech开源软件介绍:BaffaloTech Integration简介随着微服务的兴起,越来越多的项目采用微服务架构,而其中很大一部分是采用spring cloud全家桶实现。另外一方面,这些项目不同程度的是需要第三方系统的接入。这些对接方式可能80%以上都是基于http、webservice、tcp协议;安全认证方式也不尽相同。BaffaoTech Integration是基于Netty开发的、可以作为Spring Boot内嵌服务器的NIO高性能Servlet容器,可以和SpringCloud无缝集成。 特点
平台架构与Mule比较
使用添加依赖 <dependency> <groupId>com.baffalotech</groupId> <artifactId>baffalotech-integration-http</artifactId> <version>1.0.5</version></dependency> 启用集成容器,在启动类中添加EnableNettyServerContainer,会默认创建一个http connector @EnableNettyServerContainer 默认的http端口使用方式跟普通的Spring Boot完全一样。 新增http端口:添加NettyServerConnector的Bean就可以了 @Autowiredprivate NettyHttpServerConnectorFactory nettyHttpServerConnectorFactory;.....@Beanpublic Connector createNettyHttpConnector(){ return nettyHttpServerConnectorFactory.createNettyHttpServerConnector("test",8081);} 给NettyServerConector添加Filter或者Servlet,需要给servlet或者Filter指定ConnectorName @Bean()public ServletRegistrationBean cxfServlet() { ServletRegistrationBean<Servlet> test = new ServletRegistrationBean(NettyProxyServlet.createNettyProxyServlet("test", new CXFServlet()), "/soap-api/*"); test.addInitParameter("bus", "testws"); test.setOrder(1121); return test;}@Beanpublic FilterRegistrationBean tracerFilter(TracingFilter httpTraceFilter) { FilterRegistrationBean<Filter> tracerFilterRegistrationBean = new FilterRegistrationBean<Filter>(); tracerFilterRegistrationBean.setFilter(NettyProxyFilter.createNettyProxyFilter("test", httpTraceFilter)); tracerFilterRegistrationBean.addUrlPatterns("/*"); tracerFilterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE+200); return tracerFilterRegistrationBean;} 创建TCP Connector @Bean public Connector createTCPConnector() { TCPProtocal inTcpProtocal = new TCPProtocal(); inTcpProtocal.addField(new FixedLengthField("name",null, 4)); inTcpProtocal.addField(new LengthField("length",0, 4)); return nettyTCPFixedLengthServerConnectorFactory.create("hbnx", 8082, inTcpProtocal, inTcpProtocal, new TCPRequestHanlder() { @Override public void handle(TCPRequest tcpRequest, TCPResponse tcpResponse) { // TODO Auto-generated method stub tcpResponse.setData((new Date()).toString().getBytes()); } }); } 给TCPConnector添加Connector,例如一下代码给tcp添加Zipkin支持,具体需要参考Demo中的zipkin包 @Bean public TCPHandler tcpTracingHandler(HttpTracing httpTracing) { TCPHandler tcpHandler = TCPTracingHandler.create(httpTracing); tcpHandler.setName("hbnx"); return tcpHandler; } 鸣谢Netty对servlet的支持是来至于github的wangzihaogithub的工程:https://github.com/wangzihaogithub/netty-servlet |
请发表评论