{"id":15014352,"url":"https://github.com/bdqfork/hamal","last_synced_at":"2025-04-12T07:45:40.573Z","repository":{"id":57719570,"uuid":"242515838","full_name":"bdqfork/Hamal","owner":"bdqfork","description":"A light rpc framework based on netty!","archived":false,"fork":false,"pushed_at":"2020-09-20T13:40:04.000Z","size":271,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T07:45:34.525Z","etag":null,"topics":["netty","rpc","spi"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bdqfork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-23T12:48:34.000Z","updated_at":"2021-07-31T08:53:07.000Z","dependencies_parsed_at":"2022-09-02T12:31:41.391Z","dependency_job_id":null,"html_url":"https://github.com/bdqfork/Hamal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdqfork%2FHamal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdqfork%2FHamal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdqfork%2FHamal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdqfork%2FHamal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bdqfork","download_url":"https://codeload.github.com/bdqfork/Hamal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248537004,"owners_count":21120687,"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","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":["netty","rpc","spi"],"created_at":"2024-09-24T19:45:30.822Z","updated_at":"2025-04-12T07:45:40.553Z","avatar_url":"https://github.com/bdqfork.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"一个基于netty的轻量级rpc框架，使用方式可参考example。\n\n## Features:\n- 基于netty实现rpc协议\n- 支持端到端的rpc调用\n- 支持使用SPI进行功能扩展\n\n## GetStart\n引入依赖\n```groovy\nimplementation \"com.github.bdqfork:hamal-context:0.1.1\"\n```\n定义接口，例如UserService\n```java\npublic interface UserService {\n    User getUser(Long id);\n}\n```\n在服务端实现接口\n```java\npublic class UserServiceImpl implements UserService {\n    @Override\n    public User getUser(Long id) {\n        User user = new User();\n        user.setId(id);\n        user.setUsername(\"testRpc\");\n        user.setPassword(\"testpass\");\n        return user;\n    }\n}\n```\n初始化上下文，启动服务端\n```java\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        ApplicationConfig applicationConfig = new ApplicationConfig(\"127.0.0.1\", 8081, \"rpc\", \"netty\");\n        applicationConfig.setContainer(\"rpc\");\n        applicationConfig.setDirect(true);\n        applicationConfig.setLoadbalancer(\"random\");\n        applicationConfig.setSerilizer(\"hessian\");\n        Bootstrap bootstrap = new Bootstrap(applicationConfig);\n        ServiceConfig\u003cUserService\u003e serviceConfig = new ServiceConfig\u003c\u003e(UserService.class);\n        bootstrap.registerService(new UserServiceImpl(), serviceConfig);\n        bootstrap.open();\n        CountDownLatch latch = new CountDownLatch(1);\n        latch.await();\n    }\n}\n```\n\n客户端同样初始化上下文，但不需要open服务器\n```java\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        ApplicationConfig applicationConfig = new ApplicationConfig(\"127.0.0.1\", 8081, \"rpc\", \"netty\");\n        applicationConfig.setContainer(\"rpc\");\n        applicationConfig.setDirect(true);\n        applicationConfig.setLoadbalancer(\"random\");\n        applicationConfig.setSerilizer(\"hessian\");\n        Bootstrap bootstrap = new Bootstrap(applicationConfig);\n        ReferenceConfig\u003c?\u003e referenceConfig = new ReferenceConfig\u003c\u003e(UserService.class);\n        referenceConfig.setConnections(2);\n\n        UserService userService = (UserService) bootstrap.getProxy(referenceConfig);\n        ThreadPoolExecutor executor = new ThreadPoolExecutor(40, 50, 0, TimeUnit.SECONDS, new ArrayBlockingQueue\u003c\u003e(512),\n                new ThreadPoolExecutor.DiscardPolicy());\n        while (true) {\n            executor.execute(() -\u003e {\n                User user = userService.getUser(1L);\n                System.out.println(user);\n            });\n            try {\n                Thread.sleep(1000);\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n        }\n    }\n}\n```\n\n## 注册中心\n支持使用zookeeper作为注册中心\n```java\nRegistryConfig registryConfig = new RegistryConfig(\"zookeeper\", \"127.0.0.1:8080\");\nBootstrap bootstrap = new Bootstrap(applicationConfig, registryConfig);\n```\n\n## 序列化\n支持hessian和json两种序列号方式\n\n```java\napplicationConfig.setSerilizer(\"hessian\");\n```\nor\n```java\napplicationConfig.setSerilizer(\"json\");\n```\n\n## 协议\n默认使用基于tcp的自定义rpc协议，支持http协议\n```java\nApplicationConfig applicationConfig = new ApplicationConfig(\"127.0.0.1\", 8081, \"http\", \"netty\");\n```\n\n\n## todolist:\n- 实现服务分组功能\n- 实现超时重试策略\n- 实现快速失败策略\n- 实现常见的负载均衡算法\n- 实现Filter\n- 支持异步调用\n- 添加log信息","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdqfork%2Fhamal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbdqfork%2Fhamal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdqfork%2Fhamal/lists"}