{"id":18849619,"url":"https://github.com/chinalhr/gungnir","last_synced_at":"2025-07-28T22:34:47.823Z","repository":{"id":119150807,"uuid":"115726823","full_name":"ChinaLHR/Gungnir","owner":"ChinaLHR","description":"Gungnir是一个基于Spring，Netty，Zookeeper的轻量级分布式RPC服务框架","archived":false,"fork":false,"pushed_at":"2023-10-11T20:57:39.000Z","size":292,"stargazers_count":10,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-14T08:57:59.389Z","etag":null,"topics":["java","netty","rpc","rpc-framework","spring-boot","zookeeper"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChinaLHR.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-12-29T14:01:45.000Z","updated_at":"2022-08-03T07:01:13.000Z","dependencies_parsed_at":"2025-04-14T08:54:31.439Z","dependency_job_id":null,"html_url":"https://github.com/ChinaLHR/Gungnir","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ChinaLHR/Gungnir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChinaLHR%2FGungnir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChinaLHR%2FGungnir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChinaLHR%2FGungnir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChinaLHR%2FGungnir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChinaLHR","download_url":"https://codeload.github.com/ChinaLHR/Gungnir/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChinaLHR%2FGungnir/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267598226,"owners_count":24113624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","netty","rpc","rpc-framework","spring-boot","zookeeper"],"created_at":"2024-11-08T03:21:21.543Z","updated_at":"2025-07-28T22:34:47.805Z","avatar_url":"https://github.com/ChinaLHR.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003ccenter\u003eGungnir\u003c/center\u003e\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/ChinaLHR/Gungnir/blob/master/LICENSE)\n[![Build Status](https://travis-ci.org/ChinaLHR/Gungnir.svg?branch=master)](https://travis-ci.org/ChinaLHR/Gungnir)\n\n**⚠ 本项目已停止维护更新**\t\n\n## Gungnir简介\n- gungnir-rpc:基于Spring、Netty、Zookeeper，是一个轻量级的分布式RPC服务框架\n\n### 特征\n- 基于zookeeper的服务注册与服务发现\n- 服务端支持多种序列化协议：Hessian、Kryo、Protobuf\n- 服务端支持多种软负载均衡策略：轮询、随机、加权轮询、加权随机、一致性哈希\n- 整合Spring Boot，支持使用注解与XML进行服务的发布与引入\n- 服务端支持Filter机制，基于guava RateLimit实现服务限流，支持自定义Filter\n- 服务端支持Listener机制，提供beforeInvoker，afterInvoker\n- 基于Netty IdleStateHandler实现Ping-Pong心跳重连机制\n- 客户端服务消费者异步调用服务，支持自定义Netty Channel Queue大小\n\n### 实现\n- 服务的发布与服务的引入\n发布：GungnirServerFactory通过实现ApplicationContextAware接口，利用setApplicationContext达到对当前程序的GService的获取，用ServiceName-Object来维护GService集合\u003cbr/\u003e\n引入：GungnirClientProxy通过实现FactoryBean接口，再调用服务时\n\n### 使用\n\n- 服务提供者\n\n①配置服务提供者属性\n\n\t@Configuration\n\tpublic class BeanConfig {\n\t\n\t    @Bean\n\t    public GungnirServerFactory getGungnirServerFactory(){\n\t        GungnirServerFactory serverFactory = new GungnirServerFactory();\n\t        //配置server address\n\t        serverFactory.setIp(\"127.0.0.1\");\n\t        serverFactory.setPort(8000);\n\t        //配置序列化协议\n\t        serverFactory.setSerializer(\"protostuff\");\n\t        return serverFactory;\n\t    }\t\n\t}\n\n②配置服务提供者\n    \n\t//@GService 服务发布注解\n\t//value：服务发布接口 version：版本 groupName：分组 weight：权重 maxConcurrent:服务限流/秒\n\t@GService(value = IDataService.class, version = \"1.0.0\", groupName = \"dev\", weight = 10,maxConcurrent = 10)\n\tpublic class DataServiceImpl implements IDataService{\n\n\t    @Override\n\t    public String helloWorld() {\n\t        String s = \"Gungnir Hello World by 8000\";\n\t        return s;\n\t    }\n\t}\n\n③配置服务提供者Filter\n\n\t//GFilter 服务提供者Filter order：顺序值\n\t@GFilter(order = 10)\n\tpublic class ProviderFilterOrder10 implements ProviderFilter {\n\t    @Override\n\t    public GResponse invoke(FilterInvoker filterInvoker, GRequest gRequest) {\n\t        System.out.println(\"Filter======10=========\");\n\t        return filterInvoker.invoker(gRequest);\n\t    }\n\t}\n\n④配置服务提供者Listener\n\n\t@GServiceListener(value = IDataService.class, version = \"1.0.0\")\n\tpublic class DataServiceListener implements ProviderInvokerListener {\n\t\n\t    @Override\n\t    public void beforeInvoker(GRequest request) {\n\t        System.out.println(\"IDataService beforeInvoker\");\n\t    }\n\t\n\t    @Override\n\t    public void afterInvoker(GRequest request) {\n\t        System.out.println(\"IDataService afterInvoker\");\n\t    }\n\t}\n\n- 服务消费者\n\n① 配置服务消费者属性\n\t\n\t@Configuration\n\tpublic class BeanConfig {\t\n\t\n\t    @Bean\n\t    public GungnirClientProxy getGungnirClientProxy(){\n\t        GungnirClientProxy iDataServicce = new GungnirClientProxy();\n\t        iDataServicce.setSerializer(\"protostuff\");\n\t        iDataServicce.setIclass(IDataService.class);\n\t        iDataServicce.setVersion(\"1.0.0\");\n\t        iDataServicce.setTimeoutMillis(5000);\n\t        iDataServicce.setGroupName(\"dev\");\n\t        iDataServicce.setLoadBalance(\"random\");\n\t        return iDataServicce;\n\t    }\n\t}\n\n②通过@Autowired引入服务提供者使用\n\t\n\t@Autowired\n    private IDataService iDataService;\n\n- Zookeeper与Netty配置\n\n在Resources中建立gungnir.properties文件进行配置\n\t\n        zkAddress=127.0.0.1:2181\n        zkSession_TimeOut=5000\n        zkConnection_TimeOut=1000\n        netChannelSize=5\n\n### 使用参考\n\n[https://github.com/ChinaLHR/Gungnir/tree/master/gungnir-rpc-example](https://github.com/ChinaLHR/Gungnir/tree/master/gungnir-rpc-example)\n\n## TODO\n\n- [ ] 增加服务治理功能，如：服务下线，服务依赖关系分析...\n- [ ] 增加熔断降级机制\n- [ ] 对Gungnir进行性能测试\n- [ ] 优化服务消费者进行服务调用的异步逻辑\n- [ ] Spring boot start 支持\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinalhr%2Fgungnir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchinalhr%2Fgungnir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinalhr%2Fgungnir/lists"}