22 Star 47 Fork 10

felly822 / antenna

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Antenna-logoAntenna-框架介绍

简介

Antenna——一款简单的点对点服务治理框架,同时它也可以作为一款灵活小巧的MVC开发框架。
该框架总体逻辑架构如下:
Antenna-架构
自底向上分别为:数据层、服务层、配置层、接入层。

  • 数据层:用于持久化配置、日志、分析数据、缓存等
  • 服务层:提供业务逻辑等服务的实现,分为三大类:基础服务类、工具服务类、业务服务类。
  • 配置层:本框架提供配置 对外暴露的接口、可调用的接口以及一些规则的配置,比如接口暴露策略、通讯协议、白名单、重试策略、加密策略、认证策略、日志框架、异常处理策略、接口路由配置。
  • 接入层:本框架的暴露给外部的接口以及实现,包含接入和输出管理,同时也提供了容器的管理和支持,出口即接口调用,入口即接口受理。

功能介绍

  • 统一的服务受理、服务调用抽象。
  • 提供统一的传输认证和加密。
  • 提供访问者并发控制。
  • 统一的异步日志记录。
  • 统一并封装了请求输入和输出。
  • 对正在进行的访问可控。
  • 针对调用者,提供重试机制。
  • 提供统一的异常处理机制。
  • 提供统一的请求过滤功能。
  • 通过配置,提供灵活的功能扩展。
  • 提供简单的监控功能,包括访问者进程、调用统计、日志跟踪等。

如果您的团队处在这种境况,那么本框架可能非常适合您!

  • 线上存在多应用服务,同时多应用之间需要通过接口相互通讯,若引入dubbo、springcloud可能技术成本又太高,若想简单的进行服务治理,那么antenna可能是一个不错的选择。
  • 线上存在多应用服务,同时多应用之间需要通过接口相互通讯,但通讯接口分布在不同的应用中,写法千差万别,处理方式层出不穷,质量得不到统一保障,也无法统一监控分析各个接口的运作成绩。

使用方法

通过maven依赖开发包

 <dependency>
	 <groupId>com.waspring.framework</groupId>
	 <artifactId>antenna-access</artifactId>
	 <version>1.0.0</version>
 </dependency>

提供者使用

若在j2ee容器中

那么在web.xml中添加监听器和服务受理servlet

监听器

            <listener>
		<listener-class>com.waspring.framework.antenna.access.servlet.AntennaListener</listener-class>
	</listener>
	<context-param>
		<param-name>atennaConfigLocation</param-name>
		<param-value>
			classpath://config.xml
		</param-value>
	</context-param>
<context-param>
		<param-name>atennaPropertyLocation</param-name>
		<param-value>
			classpath://root.properties
		</param-value>
	</context-param>
  • 参数atennaConfigLocation为为入口的配置文件,支持协议:classpath://,file://,http://
  • 参数atennaPropertyLocation 为属性配置,主要是指定key,sercret,debug,logdir等参数。
  • 若debug为true,那么传输认证和加密都不生效,即key,sercret配置无效。

Servlet配置

   <servlet>
		<servlet-name>antennaServlet</servlet-name>
		<servlet-class>com.waspring.framework.antenna.access.servlet.AntennaServlet</servlet-class>
		<init-param>
			<param-name>containerId</param-name>
			<param-value>antennaContainer</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>antennaServlet</servlet-name>
		<url-pattern>/antenna</url-pattern>

	</servlet-mapping>

若不在j2ee容器环境

系统启动申请applicaiton,代码如下:

   PropertiesUtil.loadConfig("classpath://root.properties");
		IApplication application = ApplicationUtil.getApplication().setConfigFilePath("classpath://config.xml");
		LifecycleUtils.init(application);

系统关闭的时候调用:

   LifecycleUtils.destory(application);

申请容器

//注意:这里用到的容器名称即主配置文件配置的对应容器ID
IVisitorContainer container = ApplicationUtil.getApplication().applyContainer("antennaContainer");

随后获取提供者访问

        
		IRequest request = ApplicationUtil.instanceServerRequest(container.getId(), request);//这里request也可以自己申请,设置参数isServer=true即可
		IVisitor visitor = null;
		visitor = container.establishVisitor(request);
		//获取结果
        System.out.println(visitor.getResponse());

调用者使用

在j2ee容器中使用

IVisitorContainer container = ApplicationUtil.getApplication().applyContainer("antennaContainer");
///通过bean创建request对象,同样action属性会去路由invoker。
//同时bean有要求,字段只有添加了RequestField注解,才会被映射到request。
		IRequest request = ApplicationUtil.instanceClientRequest(container.getId(), new TestBean());
		IVisitor visitor = null;
		visitor = container.establishVisitor(request);

//获取结果
System.out.println(visitor.getResponse());

不在j2ee容器环境

那么需要在系统启动的时候执行:

   PropertiesUtil.loadConfig("classpath://root.properties");
		IApplication application = ApplicationUtil.getApplication().setConfigFilePath("classpath://config.xml");
		LifecycleUtils.init(application);

系统关闭的时候调用:

   LifecycleUtils.destory(application);

配置文件介绍

antenna的必须配置文件两个,即上面我们看到的config.xml和root.properties,config.xml为容器配置;root.properties为系统初始化配置。

下面是一个config.xml的详细实例

请参考 配置详解

下面是一个root.properties配置的实例

#通讯认证用到key
key=123501
#通讯认证用到的sercret
secret=RTUDUDO0232KDJDU1Ie33IIU3139I
#调试模式,设置为true通讯认证不会开启
debug=true
#默认通讯日志存储目录
logdir=logs

开发第一个demo

请移步 antenn-client 或者 antenn-monitor

框架待改进

  • 服务发现

目前本框架在真正的服务治理上还比较弱,仅仅支持点对点的发现,且依赖于本地的服务配置。

  • 性能与内存消耗

为了提高程序的并发处理能力,当前每次visitor访问都需要反射创建provider或者invoker来处理业务逻辑,执行效率和内存上都会打折扣。
我们可以参考servlet的架构思路优化,即处理程序只创建一次,访问方法保证线程安全。

  • 异常处理机制

目前异常方面会被吃掉很多,没有逐级上浮,虽然可以通过log跟踪,我们希望还是能从用户端直接判断大部分异常场景!

  • 配置管理

目前通过xml配置受理者和调用者,同时要在应用启动的时候指定容器,配置起来其实挺繁琐,我们希望通过注解等方式来简化配置!
另外当前也不支持动态配置,可以使用第三方全局一致性服务来实现。

  • 传输认证与加密

本框架虽然支持认证与加密,但有以下两个缺陷,一方面在传输数据量较大场景效率很低下,另一方面认证机制依赖双方的本地化配置,安全性和可维护下大大折扣。
当前可以通过扩展request对象解决,比如采用第三方认证中心。

  • 通讯日志

本框架通讯日志默认采用异步队列本地文件存储,在真正的正式环境中,我们一般不会这么做,基本上会采用第三方的存储服务,可以通过扩展:IQueueTaskHander来实现。

  • 重试机制

目标重试机制实现主要是通过第三方框架guava-retrying实现,进行了简单封装,使用变得简单,同时扩展能力缺被削弱了。

  • 补偿机制

这里的补偿主要是指当一次调用失败后,然后刚好服务重启,是否要进行重试的机制,目前框架并未支持。可以考虑请求前持久化等方案!

详细开发引导请见:开发手册

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Antenna——一款简单的点对点服务治理框架,同时它也可以作为一款灵活小巧的MVC开发框架。 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/felly822/antenna.git
git@gitee.com:felly822/antenna.git
felly822
antenna
antenna
master

搜索帮助

14c37bed 8189591 565d56ea 8189591