1 Star 3 Fork 1

zone.suplog/suplog-spring-boot-starter-rpc-rabbitmq

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

SuplogRpc

轻配置 敏捷部署 代码无侵入 自定义扩展

介绍

SuplogRpc是借力于RabbitMQ、RocketMQ、Kafka等市面上常用中间件的强大通信能力而生的低配置、轻量级rpc框架,性能上取决于mq产品在性能瓶颈方面的优化,功能上依附于mq产品的负载均衡、消息幂等、消息事务等特性。 依附mq好处是其自身的功能特性可以满足rpc框架在使用过程中需要的大部分的基础功能。

另外,每家公司的技术选型都会因为业务的特殊性而有差别,所列的rabbitmq、rocketmq、kafka等可能不是所有项目都采用。 所以suplog-rpc顺便提供了丰富的spi接口,开发者在使用该框架的过程中,可基于spi规范自由定制rpc通信框架,实现适配自己项目架构的rpc。

有各种问题欢迎随时拍砖,热烈欢迎有兴趣的小伙伴参与贡献~

为什么要写这个框架

我喜欢轻便、简洁、实用和自由的代码编辑模式。

在轻便、简洁、实用方面,SpringCloud、Dubbo在相反的方向渐行渐远,大部分功能我们可能都不会用到, 但带来的配置繁琐,部署、学习和维护成本高都是必须淌过的大江大河。

换句话说,这些含着金汤匙的rpc框架,它们各自孵化于全球排名前列的互联网公司,拥有天然的高并发、大数据场景, 必须要考虑CAP,性能瓶颈,可插拔,大量灵活的配置等等,方方面面都必须考虑全面,不可能再做到轻和简。

它们是为大公司而生的,并不适合并发量不高,但业务迭代快,需要快速部署、可扩展、边界清晰的业务系统设计的中小型公司。

本框架使用常用消息中间件作rpc通信层,开箱即用,微服务化,低配置,快速部署,代码无侵入性,并沿用了Seata提供的分布式事务解决方案。

用Seata这方面,因为事务也是日常必须用到的。 把顺便用到的消息中间件、事务调整成一个适合生产的RPC,也是顺水推舟的体现。 把刚需搭配精尽其用,我认为是借力打力,一物多用,不重复造轮子。这也是我对轻便、简洁和实用的理解。

不用再额外考虑rpc的种种诸如: 服务副本是不是一致?脑裂了怎么办?主从选举该用什么算法?rpc路由该怎么分配权重?请求链路是不是幂等? 把这些问题交给mq中间件就行了,事实上它们都已经解决了。

本项目计划将支持rabbitmq、rocketmq、kafka。 所有的维护难题都转移至消息中间件层面,不再为繁重的rpc注册中心、多如牛毛的组件配置而烦恼。 配置简单,天然适配spring开发环境,部署即用,没有额外的注册中心之类的。

在自由方面,在实现功能的同时,也抽象出了丰富的spi接口。开发者在了解了框架的运行原理后, 可根据自身情况,自定义rpc的通信和路由,在spi接口的规范下,开发一款适合自己的rpc框架。

开发计划

  • 适配RabbitMQ 已支持
  • 适配RocketMQ 开发中
  • 适配KafkaMQ规划中
  • 适配Http规划中
  • 适配Netty规划中

示例下载

消费端: rpc-client(服务调用方)

服务端: rpc-service-impl(业务包)、rpc-service(暴露接口包)

git clone https://gitee.com/suplog-rpc/suplog-spring-boot-starter-rpc-example.git

快速启动

基于Rabbit-MQ
下载仓库
- spi基础包(属于suplog-spring-boot-starter-rpc-rabbitmq的依赖包)
git clone https://gitee.com/suplog-rpc/suplog-rpc-spi.git
- 适配rabbitmq模式的suplog-rpc
 git clone https://gitee.com/suplog-rpc/suplog-spring-boot-starter-rpc-rabbitmq.git
部署本地仓库(以上两个包按先后顺序install)
 mvn clean install
部署消费端(rpc-client)
1. 引入dependency
    <-- RPC服务 -->
    <dependency>
        <groupId>zone.suplog</groupId>
        <artifactId>suplog-spring-boot-starter-rpc-rabbitmq</artifactId>
        <version>0.0.1</version>
    </dependency>
    <-- 某业务生产端服务接口 -->
    <dependency>
         <groupId>com.example</groupId>
         <artifactId>rpc-service</artifactId>
         <version>0.0.1-SNAPSHOT</version>
    </dependency>
2. application.yml配置
spring:
    application:
      name: rpc-client
    rabbitmq:
      host: localhost
      port: 5672
      username: root
      password: 123456
    suplog-rpc:
      rabbit-mq:
        # 服务消费配置
        consumer:
            # 消费服务所用交换机需要和服务注册为同一交换机
            exchange: exchange-rpc
            # 最大连接超时时间,默认5000毫秒
            max-conn-timeout: 3000
3. 消费端处理器配置
```java
  @Configuration
  public class SuplogRpcConfig {

  /**
  * 消费端处理器配置
  */
   @Bean
   public RabbitRpcConsumerProcessor rabbitMQRpcConsumerProcessor() {
       RabbitRpcConsumerProcessor rabbitRpcConsumerProcessor = new RabbitRpcConsumerProcessor();
       return rabbitRpcConsumerProcessor;
   }

}

 4. 注解方式注入客户端协议接口并使用
 ```java
   @RestController
   @RequestMapping("/demo")
   public class DemoController {
   
       @RabbitRpcConsumer
       private DemoService demoService;
   
       @GetMapping({"/print"})
       public String print(String str) {
           return demoService.print(str);
       }
   
       @GetMapping("/println")
       public void println(String str) {
           demoService.println(str);
       }
   }
5. 启动工程
部署服务/生产端(rpc-service-impl)
1. 引入dependency
    <-- RPC服务 -->
    <dependency>
        <groupId>zone.suplog</groupId>
        <artifactId>suplog-spring-boot-starter-rpc-rabbitmq</artifactId>
        <version>0.0.1</version>
    </dependency>
    <-- 本服务对外暴露接口 -->
    <dependency>
         <groupId>com.example</groupId>
         <artifactId>rpc-service</artifactId>
         <version>0.0.1-SNAPSHOT</version>
    </dependency>
2. application.yml配置
spring:
   application:
     name: rpc-service-impl
   rabbitmq:
     host: localhost
     port: 5672
     username: root
     password: 123456
   suplog-rpc:
     rabbit-mq:
       # 服务暴露配置
       provider:
         # 交换机名,负责服务寻找
         exchange: exchange-rpc
         # 服务名,也是队列名
         application-name: ${spring.application.name}
         # rpc最大连接超时时间,默认5000毫秒
         max-conn-timeout: 3000
         # 路由匹配服务根路径键注册,接口根包名和服务所在根包名需一致
         registry-key: com.example.rpcservice.service
         # 以下为接收请求处理所使用线程池配置
         # 核心线程数量,默认8个
         core-pool-size: 8
         # 线程池最大线程数量,默认200个
         max-pool-size: 200
         # 线程池最大线程数量,默认200个
         queue-capacity: 200
         # 超过core-size的那些线程,任务完成后,再经过这个时长(秒)会被结束掉。默认120秒
         keep-alive-seconds: 120
   
   logging.level.zone.suplog.rpc: DEBUG
3. 服务端处理器配置
   @Configuration
   public class SupRpcConfig {
   
       @Bean
       public RabbitRpcProviderProcessor rpcProviderRabbitMQProcessor() {
           return new RabbitRpcProviderProcessor();
       }
   }
 

4.启动

springBoot常规启动

注意事项
  • 配置spring.suplog.rabbit-mq.consumer.exchange交换机名称需要和spring.suplog-rpc.rabbit-mq.provider.exchange 一致,否则会找不到服务。你可以理解为exchange是一个注册中心,如果消费端不在同一个注册中心寻找服务,肯定是无法找到的。
  • 在创建协议接口包时,接口包根包名需要和服务根包名一致。如以上事例中:rpc-service-impl的根包名为com.example.rpcservice ,则配置spring.suplog-rpc.rabbit-mq.provider.registry-keycom.example.rpcservicerpc-service接口包根包名也必须是com.example.rpcservice。 原因是rabbit用做rpc通信层,基于TOPIC模式进行路由寻址服务,routingKey为com.example.rpcservice.#
基于Rocket-MQ

集成中

基于Kafka-MQ

规划中

基于Http

规划中

基于Netty

规划中

关于SPI接口

开发者如需定制适合自己项目架构的rpc服务,例如自家正在用ActivityMQ,那么可以参见https://gitee.com/suplog-rpc/suplog-rpc-spi.git包抽象接口,并参考https://gitee.com/suplog-rpc/suplog-spring-boot-starter-rpc-rabbitmq.git源码的子类实现。

分布式事务

集成中

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.

简介

一款性能上限和可靠性依附于消息中间件的RPC框架。企业生产级百亿PV、高可用、可拓展。理论上并发数量取决于消息中间件的处理能力。部署轻便,开箱即用,支持分布式事务,无需注册中心。基于SpringBoot,代码无侵入性,架构自由组合。 展开 收起
README
Apache-2.0
取消

发行版

暂无发行版

贡献者 (1)

全部

语言

近期动态

接近4年前推送了新的提交到 master 分支,5cc0131...f7dcd3d
接近4年前推送了新的提交到 master 分支,4dea23a...5cc0131
接近4年前推送了新的提交到 master 分支,9755ea3...4dea23a
接近4年前推送了新的提交到 master 分支,24b80c9...9755ea3
接近4年前推送了新的提交到 master 分支,7584cd8...24b80c9
加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/suplog-rpc/suplog-spring-boot-starter-rpc-rabbitmq.git
git@gitee.com:suplog-rpc/suplog-spring-boot-starter-rpc-rabbitmq.git
suplog-rpc
suplog-spring-boot-starter-rpc-rabbitmq
suplog-spring-boot-starter-rpc-rabbitmq
master

搜索帮助