├── website
├── static
│ ├── .nojekyll
│ └── img
│ │ ├── favicon.ico
│ │ ├── docusaurus.png
│ │ ├── servicepuls.png
│ │ ├── logo.svg
│ │ └── undraw_docusaurus_tree.svg
├── babel.config.js
├── src
│ ├── pages
│ │ ├── markdown-page.md
│ │ ├── index.module.css
│ │ └── index.js
│ ├── components
│ │ └── HomepageFeatures
│ │ │ ├── styles.module.css
│ │ │ └── index.js
│ └── css
│ │ └── custom.css
├── blog
│ ├── 2021-08-26-welcome
│ │ ├── docusaurus-plushie-banner.jpeg
│ │ └── index.md
│ ├── 2019-05-28-first-blog-post.md
│ ├── authors.yml
│ ├── 2021-08-01-mdx-blog-post.mdx
│ └── 2019-05-29-long-blog-post.md
├── .gitignore
├── docs
│ └── intro.md
├── sidebars.js
├── README.md
├── package.json
└── docusaurus.config.js
├── dashboard
├── src
│ ├── style.css
│ ├── vite-env.d.ts
│ ├── assets
│ │ └── servicePlus.jpg
│ ├── style
│ │ ├── variable.scss
│ │ └── index.scss
│ ├── main.ts
│ ├── App.vue
│ ├── pages
│ │ ├── ServiceDetail
│ │ │ ├── mock.js
│ │ │ ├── components
│ │ │ │ ├── MethodCard.vue
│ │ │ │ └── MethodDrawer.vue
│ │ │ ├── result.json
│ │ │ └── index.vue
│ │ └── Applist
│ │ │ ├── components
│ │ │ └── AppItem.vue
│ │ │ └── index.vue
│ └── route
│ │ └── index.ts
├── .vscode
│ └── extensions.json
├── public
│ └── servicePlus.jpg
├── .eslintrc.js
├── tsconfig.node.json
├── vite.config.ts
├── .gitignore
├── index.html
├── README.md
├── package.json
└── tsconfig.json
├── storage
├── src
│ ├── main
│ │ ├── resources
│ │ │ ├── store.properties
│ │ │ └── log4j2.xml
│ │ └── java
│ │ │ └── org
│ │ │ └── serviceplus
│ │ │ └── storage
│ │ │ ├── api
│ │ │ ├── AbstractStorage.java
│ │ │ ├── StorageApi.java
│ │ │ ├── StorageManager.java
│ │ │ └── RocksDbStorage.java
│ │ │ ├── service
│ │ │ ├── StorageServiceManager.java
│ │ │ └── StorageKvService.java
│ │ │ ├── StorageStartUp.java
│ │ │ └── server
│ │ │ ├── StorageGrpcServer.java
│ │ │ └── StorageGrpcServerBuilder.java
│ └── test
│ │ └── java
│ │ └── org
│ │ └── serviceplus
│ │ └── storage
│ │ └── RocksDbStorageApiTest.java
└── pom.xml
├── serviceplus-spring-boot-starter
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── spring.factories
│ │ └── java
│ │ └── org
│ │ └── serviceplus
│ │ └── springboot
│ │ └── starter
│ │ ├── SpRegisterAutoConfiguration.java
│ │ └── SpRegisterScanner.java
└── pom.xml
├── broker
├── src
│ ├── main
│ │ ├── resources
│ │ │ ├── application.properties
│ │ │ └── log4j2.xml
│ │ └── java
│ │ │ └── org
│ │ │ └── serviceplus
│ │ │ └── broker
│ │ │ ├── model
│ │ │ ├── vo
│ │ │ │ ├── ParamInfoVO.java
│ │ │ │ ├── BrokerApplicationVO.java
│ │ │ │ └── BrokerServiceVO.java
│ │ │ ├── Response.java
│ │ │ ├── request
│ │ │ │ └── ServiceInvokeRequest.java
│ │ │ ├── BrokerApplicationInfo.java
│ │ │ └── BrokerService.java
│ │ │ ├── kv
│ │ │ ├── storage
│ │ │ │ ├── KvStorageClientFactory.java
│ │ │ │ └── KvStorageClient.java
│ │ │ ├── controller
│ │ │ │ └── KvController.java
│ │ │ └── service
│ │ │ │ └── BrokerKvStorageService.java
│ │ │ ├── util
│ │ │ ├── EnvUtil.java
│ │ │ ├── ApplicationContextUtil.java
│ │ │ └── ResponseUtil.java
│ │ │ ├── BrokerApplication.java
│ │ │ ├── enums
│ │ │ └── ErrorCode.java
│ │ │ ├── server
│ │ │ ├── BrokerServiceManager.java
│ │ │ ├── BrokerGrpcServerStartUp.java
│ │ │ ├── BrokerGrpcServer.java
│ │ │ └── BrokerGrpcServerBuilder.java
│ │ │ ├── exception
│ │ │ ├── BrokerException.java
│ │ │ └── GlobalExceptionHandler.java
│ │ │ └── register
│ │ │ ├── storage
│ │ │ ├── BrokerRegisterStorageCenterFactory.java
│ │ │ ├── ApplicationRegisterStorageCenter.java
│ │ │ ├── ServiceRegisterStorageCenter.java
│ │ │ ├── MemoryServiceRegisterStorageCenter.java
│ │ │ └── MemoryApplicationRegisterStorageCenter.java
│ │ │ ├── service
│ │ │ ├── BrokerServiceRegisterService.java
│ │ │ └── RegisterUnifiedProcessingCenter.java
│ │ │ └── controller
│ │ │ └── BrokerRegisterController.java
│ └── test
│ │ └── java
│ │ └── org
│ │ └── serviceplus
│ │ └── broker
│ │ └── kv
│ │ └── storage
│ │ └── BrokerApplicationTests.java
├── .gitignore
└── pom.xml
├── common
├── src
│ └── main
│ │ ├── proto
│ │ ├── KvService.proto
│ │ └── SpServiceRegister.proto
│ │ └── java
│ │ └── org
│ │ └── serviceplus
│ │ └── common
│ │ ├── constant
│ │ ├── EnvironmentConstant.java
│ │ └── ResponseCodeConstant.java
│ │ └── utils
│ │ └── NetworkUtils.java
└── pom.xml
├── .gitignore
├── .github
└── workflows
│ ├── test-deploy.yml
│ └── deploy.yml
├── README.md
├── client
├── src
│ └── main
│ │ └── java
│ │ └── org
│ │ └── serviceplus
│ │ └── client
│ │ ├── ApplicationTypeEnum.java
│ │ ├── register
│ │ ├── RegisterClient.java
│ │ └── DefaultRegisterClient.java
│ │ ├── kv
│ │ ├── KvClient.java
│ │ └── DefaultKvClient.java
│ │ ├── annotation
│ │ └── SpRegister.java
│ │ ├── model
│ │ ├── SpApplication.java
│ │ └── SpService.java
│ │ ├── exception
│ │ └── ClientException.java
│ │ └── ServicePlusFactory.java
└── pom.xml
├── pom.xml
└── LICENSE
/website/static/.nojekyll:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dashboard/src/style.css:
--------------------------------------------------------------------------------
1 | @import "normalize.css";
2 |
--------------------------------------------------------------------------------
/storage/src/main/resources/store.properties:
--------------------------------------------------------------------------------
1 | rocksdb.path=rocksdb
--------------------------------------------------------------------------------
/dashboard/src/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/dashboard/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["Vue.volar"]
3 | }
4 |
--------------------------------------------------------------------------------
/website/static/img/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/li-xiao-shuang/serviceplus/HEAD/website/static/img/favicon.ico
--------------------------------------------------------------------------------
/dashboard/public/servicePlus.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/li-xiao-shuang/serviceplus/HEAD/dashboard/public/servicePlus.jpg
--------------------------------------------------------------------------------
/website/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3 | };
4 |
--------------------------------------------------------------------------------
/website/static/img/docusaurus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/li-xiao-shuang/serviceplus/HEAD/website/static/img/docusaurus.png
--------------------------------------------------------------------------------
/website/static/img/servicepuls.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/li-xiao-shuang/serviceplus/HEAD/website/static/img/servicepuls.png
--------------------------------------------------------------------------------
/dashboard/src/assets/servicePlus.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/li-xiao-shuang/serviceplus/HEAD/dashboard/src/assets/servicePlus.jpg
--------------------------------------------------------------------------------
/dashboard/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: [
3 | "plugin:vue/vue3-essential",
4 | // 可能还有其他配置
5 | ],
6 | // 其他配置...
7 | };
8 |
--------------------------------------------------------------------------------
/website/src/pages/markdown-page.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Markdown page example
3 | ---
4 |
5 | # Markdown page example
6 |
7 | You don't need React to write simple standalone pages.
8 |
--------------------------------------------------------------------------------
/website/blog/2021-08-26-welcome/docusaurus-plushie-banner.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/li-xiao-shuang/serviceplus/HEAD/website/blog/2021-08-26-welcome/docusaurus-plushie-banner.jpeg
--------------------------------------------------------------------------------
/serviceplus-spring-boot-starter/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | org.serviceplus.springboot.starter.SpRegisterAutoConfiguration
3 |
--------------------------------------------------------------------------------
/dashboard/src/style/variable.scss:
--------------------------------------------------------------------------------
1 | $body-background-color: #fff;
2 |
3 | $text-color: black;
4 |
5 | $color1: #ffe74c;
6 | $color2: #ff5964;
7 | $color3: #ffffff;
8 | $color4: #35a7ff;
9 |
10 | $divider-color: #e5e6eb;
11 |
--------------------------------------------------------------------------------
/dashboard/src/main.ts:
--------------------------------------------------------------------------------
1 | import { createApp } from "vue";
2 | import "./style.css";
3 | import App from "./App.vue";
4 | import router from "./route";
5 |
6 | import "@/style/index.scss";
7 |
8 | createApp(App).use(router).mount("#app");
9 |
--------------------------------------------------------------------------------
/website/src/components/HomepageFeatures/styles.module.css:
--------------------------------------------------------------------------------
1 | .features {
2 | display: flex;
3 | align-items: center;
4 | padding: 2rem 0;
5 | width: 100%;
6 | }
7 |
8 | .featureSvg {
9 | height: 200px;
10 | width: 200px;
11 | }
12 |
--------------------------------------------------------------------------------
/broker/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8080
2 | server.servlet.context-path=/serviceplus
3 | spring.application.name=serviceplus
4 |
5 | serviceplus.broker.grpc.port=8766
6 | serviceplus.storage.port=8866
7 | serviceplus.storage.host=127.0.0.1
--------------------------------------------------------------------------------
/dashboard/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
--------------------------------------------------------------------------------
/dashboard/tsconfig.node.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "composite": true,
4 | "skipLibCheck": true,
5 | "module": "ESNext",
6 | "moduleResolution": "bundler",
7 | "allowSyntheticDefaultImports": true,
8 | "strict": true
9 | },
10 | "include": ["vite.config.ts"]
11 | }
12 |
--------------------------------------------------------------------------------
/website/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependencies
2 | /node_modules
3 |
4 | # Production
5 | /build
6 |
7 | # Generated files
8 | .docusaurus
9 | .cache-loader
10 |
11 | # Misc
12 | .DS_Store
13 | .env.local
14 | .env.development.local
15 | .env.test.local
16 | .env.production.local
17 |
18 | npm-debug.log*
19 | yarn-debug.log*
20 | yarn-error.log*
21 |
--------------------------------------------------------------------------------
/dashboard/vite.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "vite";
2 | import vue from "@vitejs/plugin-vue";
3 |
4 | import path from "path";
5 |
6 | // https://vitejs.dev/config/
7 | export default defineConfig({
8 | plugins: [vue()],
9 | resolve: {
10 | alias: {
11 | "@": path.resolve(__dirname, "./src"),
12 | },
13 | },
14 | });
15 |
--------------------------------------------------------------------------------
/broker/src/test/java/org/serviceplus/broker/kv/storage/BrokerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package org.serviceplus.broker.kv.storage;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class BrokerApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/dashboard/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/website/docs/intro.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_position: 1
3 | ---
4 |
5 |
6 |
7 | Service Plus
8 |
9 |
10 | Service Plus 致力于打造一个分布式、强一致性 服务+ 的一站式解决方案。用作于分布式 K/V 存储系统、服务注册与发现、服务配置中心、分布式锁等。 目前处于个人研发阶段,现阶段适用于探索、研究。感兴趣的朋友可以与我交流一起共建。如果你想关注这个项目的进展,欢迎 star、fork、watch 三连!!!
--------------------------------------------------------------------------------
/dashboard/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | ServicePlus
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/dashboard/src/pages/ServiceDetail/mock.js:
--------------------------------------------------------------------------------
1 | export default new Array(10).fill("").map((item, index) => ({
2 | id: index,
3 | beanName: `firstConfigBean${index}`,
4 | methodDesc: `firstConfigBean${index}描述`,
5 | methodSignature: `firstConfigBean${index}签名`,
6 | params: new Array(3).fill("").map((item, i) => ({
7 | type: `firstConfigBean${i}参数${index}类型`,
8 | desc: `firstConfigBean${i}参数${index}描述`,
9 | })),
10 | }));
11 |
--------------------------------------------------------------------------------
/common/src/main/proto/KvService.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | option java_package = "org.serviceplus.store.proto";
3 |
4 | message KvRequest{
5 | string key = 1;
6 | string value = 2;
7 | }
8 |
9 | message KvResponse{
10 | string data = 1;
11 | string errorCode = 2;
12 | string errorMessage = 3;
13 | }
14 |
15 | service KvService{
16 | rpc put(KvRequest) returns (KvResponse);
17 | rpc get(KvRequest) returns (KvResponse);
18 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 | *.iml
22 |
23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24 | hs_err_pid*
25 |
26 | .idea
27 | rocksdb
28 | */target
29 | logs
--------------------------------------------------------------------------------
/website/blog/2019-05-28-first-blog-post.md:
--------------------------------------------------------------------------------
1 | ---
2 | slug: first-blog-post
3 | title: First Blog Post
4 | authors:
5 | name: Gao Wei
6 | title: Docusaurus Core Team
7 | url: https://github.com/wgao19
8 | image_url: https://github.com/wgao19.png
9 | tags: [hola, docusaurus]
10 | ---
11 |
12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
13 |
--------------------------------------------------------------------------------
/website/src/pages/index.module.css:
--------------------------------------------------------------------------------
1 | /**
2 | * CSS files with the .module.css suffix will be treated as CSS modules
3 | * and scoped locally.
4 | */
5 |
6 | .heroBanner {
7 | padding: 4rem 0;
8 | text-align: center;
9 | position: relative;
10 | overflow: hidden;
11 | }
12 |
13 | @media screen and (max-width: 996px) {
14 | .heroBanner {
15 | padding: 2rem;
16 | }
17 | }
18 |
19 | .buttons {
20 | display: flex;
21 | align-items: center;
22 | justify-content: center;
23 | }
24 |
--------------------------------------------------------------------------------
/website/blog/authors.yml:
--------------------------------------------------------------------------------
1 | endi:
2 | name: Endilie Yacop Sucipto
3 | title: Maintainer of Docusaurus
4 | url: https://github.com/endiliey
5 | image_url: https://github.com/endiliey.png
6 |
7 | yangshun:
8 | name: Yangshun Tay
9 | title: Front End Engineer @ Facebook
10 | url: https://github.com/yangshun
11 | image_url: https://github.com/yangshun.png
12 |
13 | slorber:
14 | name: Sébastien Lorber
15 | title: Docusaurus maintainer
16 | url: https://sebastienlorber.com
17 | image_url: https://github.com/slorber.png
18 |
--------------------------------------------------------------------------------
/broker/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/website/blog/2021-08-01-mdx-blog-post.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | slug: mdx-blog-post
3 | title: MDX Blog Post
4 | authors: [slorber]
5 | tags: [docusaurus]
6 | ---
7 |
8 | Blog posts support [Docusaurus Markdown features](https://docusaurus.io/docs/markdown-features), such as [MDX](https://mdxjs.com/).
9 |
10 | :::tip
11 |
12 | Use the power of React to create interactive blog posts.
13 |
14 | ```js
15 |
16 | ```
17 |
18 |
19 |
20 | :::
21 |
--------------------------------------------------------------------------------
/dashboard/src/route/index.ts:
--------------------------------------------------------------------------------
1 | import { createWebHistory, createRouter } from "vue-router";
2 |
3 | import AppList from "@/pages/Applist/index.vue";
4 |
5 | import ServiceDetail from "@/pages/ServiceDetail/index.vue";
6 |
7 | const routes = [
8 | {
9 | path: "/",
10 | redirect: "/appList",
11 | },
12 | {
13 | path: "/appList",
14 | component: AppList,
15 | },
16 | {
17 | path: "/serviceDetail",
18 | component: ServiceDetail,
19 | },
20 | ];
21 |
22 | const router = createRouter({
23 | history: createWebHistory(),
24 | routes,
25 | });
26 |
27 | export default router;
28 |
--------------------------------------------------------------------------------
/dashboard/src/style/index.scss:
--------------------------------------------------------------------------------
1 | @import "./variable.scss";
2 |
3 | /* 在线链接服务仅供平台体验和调试使用,平台不承诺服务的稳定性,企业客户需下载字体包自行发布使用并做好备份。 */
4 | @font-face {
5 | font-family: "阿里巴巴普惠体 2.0 45 Light";
6 | font-weight: 300;
7 | src: url("//at.alicdn.com/wf/webfont/M4emtpjKRE0Q/GR7GLdyE20MS.woff2")
8 | format("woff2"),
9 | url("//at.alicdn.com/wf/webfont/M4emtpjKRE0Q/Ot26ILNa6Hyf.woff")
10 | format("woff");
11 | font-display: swap;
12 | }
13 |
14 | html,
15 | body,
16 | #app {
17 | height: 100%;
18 | }
19 |
20 | body {
21 | background-color: $body-background-color;
22 | color: $text-color;
23 | font-family: "阿里巴巴普惠体 2.0 45 Light";
24 | }
25 |
--------------------------------------------------------------------------------
/.github/workflows/test-deploy.yml:
--------------------------------------------------------------------------------
1 | name: Test deployment
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - master
7 | # 如果你想要进一步定义触发条件、路径等,可以查看文档
8 | # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
9 |
10 | jobs:
11 | test-deploy:
12 | name: Test deployment
13 | runs-on: ubuntu-latest
14 | steps:
15 | - uses: actions/checkout@v2
16 | - uses: actions/setup-node@v3
17 | with:
18 | node-version: 18
19 | cache: npm
20 |
21 | - name: Install dependencies
22 | run: npm ci
23 | - name: Test build website
24 | run: npm run build
--------------------------------------------------------------------------------
/dashboard/README.md:
--------------------------------------------------------------------------------
1 | # Vue 3 + TypeScript + Vite
2 |
3 | This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `
26 |
27 |
38 |
--------------------------------------------------------------------------------
/common/src/main/java/org/serviceplus/common/constant/EnvironmentConstant.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.common.constant;
17 |
18 | /**
19 | * @author lixiaoshuang
20 | */
21 | public class EnvironmentConstant {
22 | public static final String APPLICATION_NAME = "spring.application.name";
23 | public static final String SERVER_PORT = "server.port";
24 | }
25 |
--------------------------------------------------------------------------------
/client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | serviceplus
7 | org.serviceplus
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | serviceplus-client
13 |
14 |
15 | 8
16 | 8
17 | UTF-8
18 |
19 |
20 |
21 |
22 | org.serviceplus
23 | serviceplus-common
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/model/vo/ParamInfoVO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.model.vo;
17 |
18 | import lombok.Data;
19 |
20 | /**
21 | * @author lixiaoshuang
22 | */
23 | @Data
24 | public class ParamInfoVO {
25 | /**
26 | * 参数名称
27 | */
28 | private String paramName;
29 | /**
30 | * 参数类型
31 | */
32 | private String paramType;
33 | }
34 |
--------------------------------------------------------------------------------
/common/src/main/java/org/serviceplus/common/constant/ResponseCodeConstant.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.common.constant;
17 |
18 | /**
19 | * @author lixiaoshuang
20 | */
21 | public class ResponseCodeConstant {
22 | public static final int OK = 200;
23 | public static final int BAD_REQUEST = 400;
24 | public static final int NOT_FOUND = 404;
25 | public static final int INTERNAL_SERVER_ERROR = 500;
26 | }
27 |
--------------------------------------------------------------------------------
/storage/src/main/java/org/serviceplus/storage/api/AbstractStorage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.serviceplus.storage.api;
18 |
19 | /**
20 | * @author lixiaoshuang
21 | */
22 | public abstract class AbstractStorage implements StorageApi {
23 |
24 | /**
25 | * 初始化存储插件
26 | */
27 | protected abstract void init();
28 |
29 | /**
30 | * 关闭存储插件
31 | */
32 | protected abstract void close();
33 | }
34 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/kv/storage/KvStorageClientFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.kv.storage;
17 |
18 | /**
19 | * @author lixiaoshuang
20 | */
21 | public class KvStorageClientFactory {
22 |
23 | public static KvStorageClient createKvStorageClient() {
24 | KvStorageClient kvStorageClient = new KvStorageClient();
25 | kvStorageClient.init();
26 | return kvStorageClient;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/model/Response.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.model;
17 |
18 | import lombok.AllArgsConstructor;
19 | import lombok.Data;
20 | import lombok.NoArgsConstructor;
21 |
22 | /**
23 | * @author lixiaoshuang
24 | */
25 | @Data
26 | @NoArgsConstructor
27 | @AllArgsConstructor
28 | public class Response {
29 |
30 | private int code;
31 |
32 | private String message;
33 |
34 | private T data;
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/storage/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | serviceplus
7 | org.serviceplus
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | serviceplus-storage
13 |
14 |
15 | 8
16 | 8
17 |
18 |
19 |
20 |
21 |
22 | org.rocksdb
23 | rocksdbjni
24 |
25 |
26 | org.serviceplus
27 | serviceplus-common
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/client/src/main/java/org/serviceplus/client/register/RegisterClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.client.register;
17 |
18 | import org.serviceplus.client.model.SpApplication;
19 | import org.serviceplus.client.model.SpService;
20 |
21 | import java.util.List;
22 |
23 | /**
24 | * @author lixiaoshuang
25 | */
26 | public interface RegisterClient {
27 | /**
28 | * 应用服务注册
29 | *
30 | * @param spApplication 应用信息
31 | */
32 | void register(SpApplication spApplication);
33 | }
34 |
--------------------------------------------------------------------------------
/website/src/css/custom.css:
--------------------------------------------------------------------------------
1 | /**
2 | * Any CSS included here will be global. The classic template
3 | * bundles Infima by default. Infima is a CSS framework designed to
4 | * work well for content-centric websites.
5 | */
6 |
7 | /* You can override the default Infima variables here. */
8 | :root {
9 | --ifm-color-primary: #2e8555;
10 | --ifm-color-primary-dark: #29784c;
11 | --ifm-color-primary-darker: #277148;
12 | --ifm-color-primary-darkest: #205d3b;
13 | --ifm-color-primary-light: #33925d;
14 | --ifm-color-primary-lighter: #359962;
15 | --ifm-color-primary-lightest: #3cad6e;
16 | --ifm-code-font-size: 95%;
17 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1);
18 | }
19 |
20 | /* For readability concerns, you should choose a lighter palette in dark mode. */
21 | [data-theme='dark'] {
22 | --ifm-color-primary: #25c2a0;
23 | --ifm-color-primary-dark: #21af90;
24 | --ifm-color-primary-darker: #1fa588;
25 | --ifm-color-primary-darkest: #1a8870;
26 | --ifm-color-primary-light: #29d5b0;
27 | --ifm-color-primary-lighter: #32d8b4;
28 | --ifm-color-primary-lightest: #4fddbf;
29 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);
30 | }
31 |
--------------------------------------------------------------------------------
/client/src/main/java/org/serviceplus/client/kv/KvClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.client.kv;
17 |
18 | /**
19 | * @author lixiaoshuang
20 | */
21 | public interface KvClient {
22 | /**
23 | * 存储 K/V 数据
24 | *
25 | * @param key key
26 | * @param value value
27 | * @return 是否存储成功
28 | */
29 | boolean put(String key, String value);
30 |
31 | /**
32 | * 获取指定 key 的 value
33 | *
34 | * @param key key
35 | * @return key 对应的 value
36 | */
37 | String get(String key);
38 | }
39 |
--------------------------------------------------------------------------------
/client/src/main/java/org/serviceplus/client/annotation/SpRegister.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.client.annotation;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * 用于标记需要注册的服务
22 | *
23 | * @author lixiaoshuang
24 | */
25 | @Target(ElementType.METHOD)
26 | @Retention(RetentionPolicy.RUNTIME)
27 | @Documented
28 | public @interface SpRegister {
29 | /**
30 | * 服务名称
31 | */
32 | String name() default "";
33 |
34 | /**
35 | * 参数描述,多个参数用;分隔.如: 用户名;密码
36 | */
37 | String paramDesc() default "";
38 | }
39 |
--------------------------------------------------------------------------------
/website/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "website",
3 | "version": "0.0.0",
4 | "private": true,
5 | "scripts": {
6 | "docusaurus": "docusaurus",
7 | "start": "docusaurus start",
8 | "build": "docusaurus build",
9 | "swizzle": "docusaurus swizzle",
10 | "deploy": "docusaurus deploy",
11 | "clear": "docusaurus clear",
12 | "serve": "docusaurus serve",
13 | "write-translations": "docusaurus write-translations",
14 | "write-heading-ids": "docusaurus write-heading-ids"
15 | },
16 | "dependencies": {
17 | "@docusaurus/core": "2.0.0-beta.22",
18 | "@docusaurus/preset-classic": "2.0.0-beta.22",
19 | "@mdx-js/react": "^1.6.22",
20 | "clsx": "^1.2.0",
21 | "prism-react-renderer": "^1.3.5",
22 | "react": "^17.0.2",
23 | "react-dom": "^17.0.2"
24 | },
25 | "devDependencies": {
26 | "@docusaurus/module-type-aliases": "2.0.0-beta.22"
27 | },
28 | "browserslist": {
29 | "production": [
30 | ">0.5%",
31 | "not dead",
32 | "not op_mini all"
33 | ],
34 | "development": [
35 | "last 1 chrome version",
36 | "last 1 firefox version",
37 | "last 1 safari version"
38 | ]
39 | },
40 | "engines": {
41 | "node": ">=16.14"
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/model/vo/BrokerApplicationVO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.model.vo;
17 |
18 | import lombok.Data;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * @author lixiaoshuang
24 | */
25 | @Data
26 | public class BrokerApplicationVO {
27 | /**
28 | * 应用名
29 | */
30 | private String applicationName;
31 | /**
32 | * 端口
33 | */
34 | private String applicationPort;
35 | /**
36 | * 应用类型
37 | */
38 | private String applicationType;
39 | /**
40 | * ip列表
41 | */
42 | private List ipList;
43 | }
44 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/util/EnvUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.util;
17 |
18 | import org.springframework.core.env.ConfigurableEnvironment;
19 |
20 | /**
21 | * @author lixiaoshuang
22 | */
23 | public class EnvUtil {
24 |
25 | private static ConfigurableEnvironment environment;
26 |
27 | public static void setEnvironment(ConfigurableEnvironment environment) {
28 | EnvUtil.environment = environment;
29 | }
30 |
31 | public static String getProperty(String key, String defaultValue) {
32 | return environment.getProperty(key, defaultValue);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/BrokerApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.serviceplus.broker;
18 |
19 | import org.springframework.boot.SpringApplication;
20 | import org.springframework.boot.autoconfigure.SpringBootApplication;
21 | import org.springframework.boot.web.servlet.ServletComponentScan;
22 |
23 |
24 | /**
25 | * broker 启动类
26 | *
27 | * @author lixiaoshuang
28 | */
29 | @SpringBootApplication
30 | @ServletComponentScan
31 | public class BrokerApplication {
32 |
33 | public static void main(String[] args) {
34 | SpringApplication.run(BrokerApplication.class, args);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/enums/ErrorCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.enums;
17 |
18 | import lombok.Getter;
19 |
20 | /**
21 | * @author lixiaoshuang
22 | */
23 |
24 | public enum ErrorCode {
25 | /**
26 | * common code
27 | */
28 | SUCCESS(0, "success"),
29 |
30 | FAIL(-1, "fail"),
31 |
32 |
33 | PARAM_ERROR(1001, "param error"),
34 | ;
35 |
36 |
37 | @Getter
38 | private Integer code;
39 |
40 | @Getter
41 | private String message;
42 |
43 | ErrorCode(Integer code, String message) {
44 | this.code = code;
45 | this.message = message;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/model/request/ServiceInvokeRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.model.request;
17 |
18 | import lombok.Data;
19 |
20 | /**
21 | * @author lixiaoshuang
22 | */
23 | @Data
24 | public class ServiceInvokeRequest {
25 | /**
26 | * 服务名
27 | */
28 | private String serviceName;
29 | /**
30 | * 方法名
31 | */
32 | private String methodName;
33 | /**
34 | * 参数
35 | */
36 | private Object[] params;
37 | /**
38 | * 参数类型
39 | */
40 | private String[] paramTypes;
41 | /**
42 | * 返回值类型
43 | */
44 | private String returnType;
45 | }
46 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/model/BrokerApplicationInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.model;
17 |
18 | import lombok.Builder;
19 | import lombok.Data;
20 |
21 | /**
22 | * @author lixiaoshuang
23 | */
24 | @Data
25 | @Builder
26 | public class BrokerApplicationInfo {
27 | /**
28 | * 应用名
29 | */
30 | private String applicationName;
31 | /**
32 | * ip
33 | */
34 | private String applicationIp;
35 | /**
36 | * 端口
37 | */
38 | private String applicationPort;
39 | /**
40 | * 应用类型
41 | *
42 | * @see org.serviceplus.client.ApplicationTypeEnum
43 | */
44 | private String applicationType;
45 | }
46 |
--------------------------------------------------------------------------------
/storage/src/main/java/org/serviceplus/storage/api/StorageApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.serviceplus.storage.api;
18 |
19 | /**
20 | * @author lixiaoshuang
21 | */
22 | public interface StorageApi {
23 |
24 | /**
25 | * 存储 K/V 数据
26 | *
27 | * @param key key
28 | * @param value value
29 | * @return 是否存储成功
30 | */
31 | boolean put(String key, String value);
32 |
33 | /**
34 | * 获取指定 key 的 value
35 | *
36 | * @param key key
37 | * @return key 对应的 value
38 | */
39 | String get(String key);
40 |
41 | /**
42 | * 删除指定 key
43 | *
44 | * @param key key
45 | * @return 是否删除成功
46 | */
47 | boolean delete(String key);
48 | }
49 |
--------------------------------------------------------------------------------
/website/src/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import clsx from 'clsx';
3 | import Link from '@docusaurus/Link';
4 | import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
5 | import Layout from '@theme/Layout';
6 | import HomepageFeatures from '@site/src/components/HomepageFeatures';
7 |
8 | import styles from './index.module.css';
9 |
10 | function HomepageHeader() {
11 | const {siteConfig} = useDocusaurusContext();
12 | return (
13 |
26 | );
27 | }
28 |
29 | export default function Home() {
30 | const {siteConfig} = useDocusaurusContext();
31 | return (
32 |
35 |
36 |
37 |
38 |
39 |
40 | );
41 | }
42 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/server/BrokerServiceManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.server;
17 |
18 | import io.grpc.BindableService;
19 | import lombok.Getter;
20 | import org.serviceplus.broker.kv.service.BrokerKvStorageService;
21 | import org.serviceplus.broker.register.service.BrokerServiceRegisterService;
22 | import org.springframework.stereotype.Component;
23 |
24 | import javax.annotation.Resource;
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | /**
29 | * GRPC绑定服务管理.
30 | *
31 | * @author lixiaoshuang
32 | */
33 | @Getter
34 | @Component
35 | public class BrokerServiceManager {
36 |
37 | @Resource
38 | private List bindableServiceList;
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/serviceplus-spring-boot-starter/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.serviceplus
8 | serviceplus
9 | 1.0.0-SNAPSHOT
10 |
11 |
12 | serviceplus-spring-boot-starter
13 |
14 |
15 | 8
16 | 8
17 | UTF-8
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter
24 |
25 |
26 | org.serviceplus
27 | serviceplus-client
28 |
29 |
30 | org.apache.commons
31 | commons-lang3
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/exception/BrokerException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.exception;
17 |
18 | import lombok.Data;
19 | import lombok.EqualsAndHashCode;
20 |
21 | /**
22 | * @author lixiaoshuang
23 | */
24 | @EqualsAndHashCode(callSuper = true)
25 | @Data
26 | public class BrokerException extends RuntimeException {
27 |
28 | private int errorCode;
29 |
30 | private String errorMessage;
31 |
32 | public BrokerException(String errorMessage) {
33 | super(errorMessage);
34 | }
35 |
36 | public BrokerException(int errorCode, String errorMessage) {
37 | super(errorMessage);
38 | this.errorCode = errorCode;
39 | this.errorMessage = errorMessage;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/broker/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | logs
4 | store.log
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/client/src/main/java/org/serviceplus/client/model/SpApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.client.model;
17 |
18 | import lombok.Data;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * @author lixiaoshuang
24 | */
25 | @Data
26 | public class SpApplication {
27 | /**
28 | * 应用名
29 | */
30 | private String applicationName;
31 | /**
32 | * ip
33 | */
34 | private String applicationIp;
35 | /**
36 | * 端口
37 | */
38 | private String applicationPort;
39 | /**
40 | * 应用类型
41 | *
42 | * @see org.serviceplus.client.ApplicationTypeEnum
43 | */
44 | private String applicationType;
45 | /**
46 | * 服务
47 | */
48 | private List spServices;
49 | }
50 |
--------------------------------------------------------------------------------
/storage/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | logs
4 | store.log
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/client/src/main/java/org/serviceplus/client/exception/ClientException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.client.exception;
17 |
18 | import lombok.Data;
19 | import lombok.EqualsAndHashCode;
20 |
21 | /**
22 | * @author lixiaoshuang
23 | */
24 | @EqualsAndHashCode(callSuper = true)
25 | @Data
26 | public class ClientException extends RuntimeException {
27 |
28 | private int errorCode;
29 |
30 | private String errorMessage;
31 |
32 | public ClientException(String errorMessage) {
33 | this.errorCode = -1;
34 | this.errorMessage = errorMessage;
35 | }
36 |
37 | public ClientException(int errorCode, String errorMessage) {
38 | this.errorCode = errorCode;
39 | this.errorMessage = errorMessage;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/register/storage/BrokerRegisterStorageCenterFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.register.storage;
17 |
18 | /**
19 | * @author lixiaoshuang
20 | */
21 | public class BrokerRegisterStorageCenterFactory {
22 |
23 | /**
24 | * 创建应用注册中心
25 | *
26 | * @return 应用注册中心
27 | */
28 | public static ApplicationRegisterStorageCenter createApplicationRegisterStorageCenter() {
29 | return MemoryApplicationRegisterStorageCenter.getInstance();
30 | }
31 |
32 | /**
33 | * 创建服务注册中心
34 | *
35 | * @return 服务注册中心
36 | */
37 | public static ServiceRegisterStorageCenter createServiceRegisterStorageCenter() {
38 | return MemoryServiceRegisterStorageCenter.getInstance();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/storage/src/main/java/org/serviceplus/storage/service/StorageServiceManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.storage.service;
17 |
18 | import io.grpc.BindableService;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | /**
24 | * 绑定服务注册器.
25 | *
26 | * @author lixiaoshuang
27 | */
28 | public class StorageServiceManager {
29 |
30 | private static final List BINDABLE_SERVICE_LIST = new ArrayList<>();
31 |
32 | public void initialized() {
33 | this.bindService(new StorageKvService());
34 | }
35 |
36 | public void bindService(BindableService bindableService) {
37 | BINDABLE_SERVICE_LIST.add(bindableService);
38 | }
39 |
40 | public static List getBindableServiceList() {
41 | return BINDABLE_SERVICE_LIST;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/model/vo/BrokerServiceVO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.model.vo;
17 |
18 | import lombok.Data;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * @author lixiaoshuang
24 | */
25 | @Data
26 | public class BrokerServiceVO {
27 | /**
28 | * 全类名
29 | */
30 | private String className;
31 | /**
32 | * 简单类名
33 | */
34 | private String simpleClassName;
35 | /**
36 | * 方法名
37 | */
38 | private String methodName;
39 | /**
40 | * 方法描述
41 | */
42 | private String methodDesc;
43 | /**
44 | * 参数信息
45 | */
46 | private List paramInfos;
47 | /**
48 | * 返回值名称
49 | */
50 | private String returnName;
51 | /**
52 | * 返回值类型
53 | */
54 | private String returnType;
55 | }
56 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/register/storage/ApplicationRegisterStorageCenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.register.storage;
17 |
18 | import org.serviceplus.broker.model.BrokerApplicationInfo;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * @author lixiaoshuang
24 | */
25 | public interface ApplicationRegisterStorageCenter {
26 | /**
27 | * 注册应用
28 | *
29 | * @param applicationName 应用名
30 | * @param application 应用
31 | */
32 | void registerApplication(String applicationName, BrokerApplicationInfo application);
33 |
34 | /**
35 | * 获取应用列表
36 | *
37 | * @return 应用列表
38 | */
39 | List getApplicationList();
40 |
41 | /**
42 | * 获取应用ip列表
43 | *
44 | * @param applicationName 应用名
45 | * @return ip列表
46 | */
47 | List getApplicationIps(String applicationName);
48 | }
49 |
--------------------------------------------------------------------------------
/.github/workflows/deploy.yml:
--------------------------------------------------------------------------------
1 | name: Deploy to GitHub Pages
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | # 如果你想要进一步定义触发条件、路径等,可以查看文档
8 | # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
9 | paths:
10 | - '.github/workflows/deploy.yml'
11 | - 'website/**'
12 |
13 | jobs:
14 | deploy:
15 | name: Deploy to GitHub Pages
16 | runs-on: ubuntu-20.04
17 | permissions:
18 | contents: write
19 | defaults:
20 | run:
21 | working-directory: website
22 | steps:
23 | - uses: actions/checkout@v2
24 |
25 | - name: Setup Node
26 | uses: actions/setup-node@v3
27 | with:
28 | node-version: '18'
29 |
30 | - name: Install dependencies
31 | run: npm ci
32 | - name: Build website
33 | run: npm run build
34 |
35 | # 部署到 GitHub Pages 的热门选择:
36 | # 文档:https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus
37 | - name: Deploy to GitHub Pages
38 | uses: peaceiris/actions-gh-pages@v3
39 | with:
40 | github_token: ${{ secrets.GITHUB_TOKEN }}
41 | # 要发布到 `gh-pages` 分支的构建输出:
42 | publish_dir: ./website/build
43 | # 下面两行会将此次部署 commit 的作者设置为官方的
44 | # GH-Actions 机器人:
45 | # https://github.com/actions/checkout/issues/13#issuecomment-724415212
46 | # 如果不设置这两个字段,GH actions 机器人会被默认使用。
47 | # 你可以用自己的用户信息替换它们。
48 | user_name: github-actions[bot]
49 | user_email: 41898282+github-actions[bot]@users.noreply.github.com
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/register/storage/ServiceRegisterStorageCenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.register.storage;
17 |
18 | import org.serviceplus.broker.model.BrokerApplicationInfo;
19 | import org.serviceplus.broker.model.BrokerService;
20 |
21 | import java.util.List;
22 |
23 | /**
24 | * @author lixiaoshuang
25 | */
26 | public interface ServiceRegisterStorageCenter {
27 | /**
28 | * 注册服务
29 | *
30 | * @param applicationInfo 应用信息
31 | * @param service 服务
32 | */
33 | void registerService(BrokerApplicationInfo applicationInfo, BrokerService service);
34 |
35 | /**
36 | * 获取服务
37 | *
38 | * @param applicationName 应用名
39 | * @param applicationIp ip
40 | * @param applicationPort 端口
41 | * @return 服务列表
42 | */
43 | List getService(String applicationName, String applicationIp, String applicationPort);
44 | }
45 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/model/BrokerService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.model;
17 |
18 | import lombok.Data;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * @author lixiaoshuang
24 | */
25 | @Data
26 | public class BrokerService {
27 | /**
28 | * 全类名
29 | */
30 | private String className;
31 | /**
32 | * 简单类名
33 | */
34 | private String simpleClassName;
35 | /**
36 | * 方法描述
37 | */
38 | private String methodDesc;
39 | /**
40 | * 方法名
41 | */
42 | private String methodName;
43 | /**
44 | * 参数名称
45 | */
46 | private List paramNames;
47 | /**
48 | * 参数描述
49 | */
50 | private List paramDesc;
51 | /**
52 | * 参数类型
53 | */
54 | private List paramTypes;
55 | /**
56 | * 返回值名称
57 | */
58 | private String returnName;
59 | /**
60 | * 返回值类型
61 | */
62 | private String returnType;
63 | }
64 |
--------------------------------------------------------------------------------
/client/src/main/java/org/serviceplus/client/ServicePlusFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.client;
17 |
18 | import org.serviceplus.client.register.DefaultRegisterClient;
19 | import org.serviceplus.client.register.RegisterClient;
20 | import org.serviceplus.client.kv.DefaultKvClient;
21 | import org.serviceplus.client.kv.KvClient;
22 |
23 | import java.util.Properties;
24 |
25 | /**
26 | * @author lixiaoshuang
27 | */
28 | public class ServicePlusFactory {
29 | /**
30 | * 创建kv客户端
31 | *
32 | * @param properties 配置文件
33 | * @return kv客户端
34 | */
35 | public static KvClient createKvClient(Properties properties) {
36 | return DefaultKvClient.getInstance(properties);
37 | }
38 |
39 | /**
40 | * 创建注册客户端
41 | *
42 | * @param properties 配置文件
43 | * @return 注册客户端
44 | */
45 | public static RegisterClient createRegisterClient(Properties properties) {
46 | return DefaultRegisterClient.getInstance(properties);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/client/src/main/java/org/serviceplus/client/model/SpService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.client.model;
17 |
18 | import lombok.Builder;
19 | import lombok.Data;
20 |
21 | import java.util.List;
22 |
23 | /**
24 | * @author lixiaoshuang
25 | */
26 | @Data
27 | @Builder
28 | public class SpService {
29 | /**
30 | * 全类名
31 | */
32 | private String className;
33 | /**
34 | * 简单类名
35 | */
36 | private String simpleClassName;
37 | /**
38 | * 方法描述
39 | */
40 | private String methodDesc;
41 | /**
42 | * 方法名
43 | */
44 | private String methodName;
45 | /**
46 | * 参数名称
47 | */
48 | private List paramNames;
49 | /**
50 | * 参数描述
51 | */
52 | private List paramDesc;
53 | /**
54 | * 参数类型
55 | */
56 | private List> paramTypes;
57 | /**
58 | * 返回值名称
59 | */
60 | private String returnNames;
61 | /**
62 | * 返回值类型
63 | */
64 | private Class> returnTypes;
65 | }
66 |
--------------------------------------------------------------------------------
/website/src/components/HomepageFeatures/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import clsx from 'clsx';
3 | import styles from './styles.module.css';
4 |
5 | const FeatureList = [
6 | {
7 | title: '易于使用',
8 | Svg: require('@site/static/img/undraw_docusaurus_mountain.svg').default,
9 | description: (
10 | <>
11 | Service Plus 是微服务一站式解决方案,不依赖第三方存储。可以一站式部署,方便开发运维和使用。
12 | >
13 | ),
14 | },
15 | {
16 | title: '一站式方案',
17 | Svg: require('@site/static/img/undraw_docusaurus_tree.svg').default,
18 | description: (
19 | <>
20 | 用作于分布式 K/V 存储系统、服务注册与发现、服务配置中心、分布式锁等场景解决方案
21 | >
22 | ),
23 | },
24 | {
25 | title: '强一致性',
26 | Svg: require('@site/static/img/undraw_docusaurus_react.svg').default,
27 | description: (
28 | <>
29 | Service Plus 基于 Raft 协议打造一个分布式共识系统,保证每个节点对等。
30 | >
31 | ),
32 | },
33 | ];
34 |
35 | function Feature({Svg, title, description}) {
36 | return (
37 |
38 |
39 |
40 |
41 |
42 |
{title}
43 |
{description}
44 |
45 |
46 | );
47 | }
48 |
49 | export default function HomepageFeatures() {
50 | return (
51 |
52 |
53 |
54 | {FeatureList.map((props, idx) => (
55 |
56 | ))}
57 |
58 |
59 |
60 | );
61 | }
62 |
--------------------------------------------------------------------------------
/serviceplus-spring-boot-starter/src/main/java/org/serviceplus/springboot/starter/SpRegisterAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.springboot.starter;
17 |
18 | import org.springframework.beans.factory.BeanFactory;
19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
20 | import org.springframework.context.annotation.Bean;
21 | import org.springframework.context.annotation.Configuration;
22 | import org.springframework.core.env.Environment;
23 |
24 | /**
25 | * @author lixiaoshuang
26 | */
27 | @Configuration
28 | public class SpRegisterAutoConfiguration {
29 |
30 | private final BeanFactory beanFactory;
31 | private final Environment environment;
32 |
33 | public SpRegisterAutoConfiguration(BeanFactory beanFactory, Environment environment) {
34 | this.beanFactory = beanFactory;
35 | this.environment = environment;
36 | }
37 |
38 | @Bean
39 | @ConditionalOnMissingBean
40 | public SpRegisterScanner spRegisterScanner() {
41 | return SpRegisterScanner.getInstance(beanFactory, environment);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/dashboard/src/pages/Applist/components/AppItem.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |

5 | {{ props.appName }}
6 |
7 |
8 |
14 | {{ ip }}
15 |
16 |
17 |
18 |
19 |
36 |
75 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/exception/GlobalExceptionHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.exception;
17 |
18 | import lombok.extern.slf4j.Slf4j;
19 | import org.serviceplus.broker.model.Response;
20 | import org.serviceplus.broker.util.ResponseUtil;
21 | import org.springframework.http.HttpStatus;
22 | import org.springframework.web.bind.annotation.ControllerAdvice;
23 | import org.springframework.web.bind.annotation.ExceptionHandler;
24 |
25 | /**
26 | * @author lixiaoshuang
27 | */
28 | @ControllerAdvice
29 | @Slf4j
30 | public class GlobalExceptionHandler {
31 |
32 | // 处理特定异常
33 | @ExceptionHandler(BrokerException.class)
34 | public Response handleSpecificException(BrokerException ex) {
35 | return ResponseUtil.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getMessage());
36 | }
37 |
38 | // 处理所有未捕获的异常
39 | @ExceptionHandler(Exception.class)
40 | public Response handleAllUncaughtException(Exception ex) {
41 | log.error("Unexpected error occurred", ex);
42 | return ResponseUtil.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getMessage());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/util/ApplicationContextUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.util;
17 |
18 | import org.springframework.beans.BeansException;
19 | import org.springframework.context.ApplicationContext;
20 | import org.springframework.context.ApplicationContextAware;
21 | import org.springframework.core.env.ConfigurableEnvironment;
22 | import org.springframework.stereotype.Component;
23 |
24 | /**
25 | * 上下文工具类
26 | *
27 | * @author lixiaoshuang
28 | */
29 | @Component
30 | public class ApplicationContextUtil implements ApplicationContextAware {
31 |
32 | private static ApplicationContext applicationContext;
33 |
34 | @Override
35 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
36 | ConfigurableEnvironment environment = (ConfigurableEnvironment) applicationContext.getEnvironment();
37 | EnvUtil.setEnvironment(environment);
38 | ApplicationContextUtil.applicationContext = applicationContext;
39 | }
40 |
41 | public static T getBean(Class clazz) {
42 | return applicationContext != null ? applicationContext.getBean(clazz) : null;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/kv/controller/KvController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.kv.controller;
17 |
18 | import org.serviceplus.broker.kv.storage.KvStorageClient;
19 | import org.serviceplus.broker.kv.storage.KvStorageClientFactory;
20 | import org.serviceplus.broker.model.Response;
21 | import org.serviceplus.broker.util.ResponseUtil;
22 | import org.springframework.web.bind.annotation.*;
23 |
24 | /**
25 | * @author lixiaoshuang
26 | */
27 | @RestController
28 | @RequestMapping(path = "kv/v1")
29 | public class KvController {
30 |
31 | @PostMapping(path = "put")
32 | public Response putKv(@RequestParam("key") String key, @RequestParam("value") String value) {
33 | KvStorageClient kvStorageClient = KvStorageClientFactory.createKvStorageClient();
34 | boolean put = kvStorageClient.put(key, value);
35 | return ResponseUtil.success(put);
36 | }
37 |
38 | @GetMapping(path = "get")
39 | public Response getKv(@RequestParam("key") String key) {
40 | KvStorageClient kvStorageClient = KvStorageClientFactory.createKvStorageClient();
41 | String value = kvStorageClient.get(key);
42 | return ResponseUtil.success(value);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/broker/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | serviceplus
7 | org.serviceplus
8 | 1.0.0-SNAPSHOT
9 |
10 |
11 | serviceplus-broker
12 | jar
13 |
14 |
15 | 1.8
16 |
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-test
27 | test
28 |
29 |
30 |
31 | org.serviceplus
32 | serviceplus-common
33 |
34 |
35 | org.apache.commons
36 | commons-collections4
37 |
38 |
39 | org.apache.commons
40 | commons-lang3
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-maven-plugin
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/common/src/main/proto/SpServiceRegister.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | option java_package = "org.serviceplus.register.proto";
3 |
4 | service SpServiceRegister {
5 | rpc BidirectionalStreamingMethod(stream ClientRegisterRequest) returns (stream ServerRegisterRequest) {}
6 | }
7 |
8 | message ClientRegisterRequest {
9 | oneof ClientPayload {
10 | ServiceRegister serviceRegister = 1; // 服务注册
11 | ServiceInvokeResponse serviceInvokeResponse = 2; // 服务调用响应
12 | }
13 | }
14 |
15 | message ServerRegisterRequest {
16 | oneof ServerPayload {
17 | ServiceInvoke serviceInvoke = 1; // 服务调用
18 | ServiceRegisterResponse serviceRegisterResponse = 2; // 服务注册响应
19 | }
20 | }
21 |
22 | message ServiceRegister{
23 | string applicationName = 1; // 应用名
24 | string applicationIp = 2; // IP地址
25 | string applicationPort = 3; // 端口
26 | string applicationType = 4; // 应用类型
27 | repeated ClientService clientService = 5; // 服务列表
28 | }
29 |
30 | message ClientService {
31 | string className = 1; // 全类名
32 | string simpleClassName = 2; // 简单类名
33 | string methodDesc = 3; // 方法描述
34 | string methodName = 4; // 方法名
35 | repeated string paramNames = 5; // 参数名称,使用列表
36 | repeated string paramDesc = 6; // 参数描述,使用列表
37 | repeated string paramTypes = 7; // 参数类型,这里使用字符串列表表示类名
38 | string returnName = 8; // 返回值名称
39 | string returnType = 9; // 返回值类型,使用字符串表示类名
40 | }
41 |
42 | message ServiceInvoke{
43 |
44 | }
45 |
46 | message ServiceRegisterResponse{
47 | int32 code = 1; // 响应码
48 | string message = 2; // 响应消息
49 | string data = 3; // 响应数据
50 | }
51 |
52 | message ServiceInvokeResponse{
53 | int32 code = 1; // 响应码
54 | string message = 2; // 响应消息
55 | string data = 3; // 响应数据
56 | }
57 |
--------------------------------------------------------------------------------
/storage/src/main/java/org/serviceplus/storage/StorageStartUp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.serviceplus.storage;
18 |
19 |
20 | import io.grpc.Server;
21 | import org.serviceplus.storage.server.StorageGrpcServerBuilder;
22 | import org.serviceplus.storage.service.StorageServiceManager;
23 | import org.slf4j.Logger;
24 | import org.slf4j.LoggerFactory;
25 |
26 | import java.io.IOException;
27 |
28 | /**
29 | * @author lixiaoshuang
30 | */
31 | public class StorageStartUp {
32 |
33 | private static final Logger LOGGER = LoggerFactory.getLogger(StorageStartUp.class);
34 |
35 | public static void main(String[] args) throws InterruptedException {
36 | StorageGrpcServerBuilder storageGrpcServerBuilder = StorageGrpcServerBuilder.forPort(8866);
37 | Server server = storageGrpcServerBuilder.addService(StorageServiceManager.getBindableServiceList()).build();
38 | try {
39 | server.start();
40 | Runtime.getRuntime().addShutdownHook(new Thread(server::shutdown));
41 | LOGGER.info("The grpc server at the storage tier is successfully started.");
42 | } catch (IOException e) {
43 | LOGGER.error("The grpc server at the storage tier fails to be started.", e);
44 | }finally {
45 | if (server!=null){
46 | server.awaitTermination();
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/storage/src/test/java/org/serviceplus/storage/RocksDbStorageApiTest.java:
--------------------------------------------------------------------------------
1 | package org.serviceplus.storage;/*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | import org.junit.Assert;
19 | import org.junit.Before;
20 | import org.junit.Test;
21 | import org.serviceplus.storage.api.RocksDbStorage;
22 |
23 | import java.util.Properties;
24 |
25 | /**
26 | * @author lixiaoshuang
27 | */
28 | public class RocksDbStorageApiTest {
29 |
30 | private RocksDbStorage rocksDbStore;
31 |
32 | @Before
33 | public void setUp() {
34 | Properties properties = new Properties();
35 | properties.setProperty("rocksdb.path", "target/rocksdb");
36 | rocksDbStore = new RocksDbStorage(properties);
37 | rocksDbStore.init();
38 | }
39 |
40 | @Test
41 | public void testPut() {
42 | boolean put = rocksDbStore.put("key", "hello store");
43 | Assert.assertTrue(put);
44 | }
45 |
46 | @Test
47 | public void testGet() {
48 | String key = "key";
49 | String value = "hello store";
50 | rocksDbStore.put(key, value);
51 | String returnValue = rocksDbStore.get(key);
52 | Assert.assertEquals(value, returnValue);
53 | }
54 |
55 | @Test
56 | public void testDelete() {
57 | String key = "key";
58 | String value = "hello store";
59 | rocksDbStore.put(key, value);
60 | boolean delete = rocksDbStore.delete(key);
61 | Assert.assertTrue(delete);
62 | }
63 | }
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/server/BrokerGrpcServerStartUp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.server;
17 |
18 | import io.grpc.Server;
19 | import org.slf4j.Logger;
20 | import org.slf4j.LoggerFactory;
21 | import org.springframework.beans.factory.annotation.Value;
22 | import org.springframework.stereotype.Component;
23 |
24 | import javax.annotation.PostConstruct;
25 | import javax.annotation.Resource;
26 | import java.io.IOException;
27 |
28 | /**
29 | * broker grpc 服务端启动类
30 | *
31 | * @author lixiaoshuang
32 | */
33 | @Component
34 | public class BrokerGrpcServerStartUp {
35 |
36 | private static final Logger LOGGER = LoggerFactory.getLogger(BrokerGrpcServerStartUp.class);
37 |
38 | @Value("${serviceplus.broker.grpc.port:8766}")
39 | private int port;
40 | @Resource
41 | private BrokerServiceManager brokerServiceManager;
42 |
43 | @PostConstruct
44 | public void start() {
45 | BrokerGrpcServerBuilder brokerGrpcServerBuilder = BrokerGrpcServerBuilder.forPort(port);
46 | Server server = brokerGrpcServerBuilder.addService(brokerServiceManager.getBindableServiceList()).build();
47 | try {
48 | server.start();
49 | Runtime.getRuntime().addShutdownHook(new Thread(server::shutdown));
50 | LOGGER.info("The grpc server at the broker tier is successfully started. port: {}", port);
51 | } catch (IOException e) {
52 | LOGGER.error("The grpc server at the broker tier fails to be started.", e);
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/server/BrokerGrpcServer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.server;
17 |
18 | import io.grpc.Server;
19 | import org.slf4j.Logger;
20 | import org.slf4j.LoggerFactory;
21 |
22 | import java.io.IOException;
23 | import java.util.concurrent.TimeUnit;
24 |
25 | /**
26 | * Grpc 服务端.
27 | *
28 | * @author lixiaoshuang
29 | */
30 | public class BrokerGrpcServer extends Server {
31 |
32 | private static final Logger LOGGER = LoggerFactory.getLogger(BrokerGrpcServer.class);
33 |
34 | private Server server;
35 |
36 | public BrokerGrpcServer(Server server) {
37 | this.server = server;
38 | }
39 |
40 | @Override
41 | public Server start() throws IOException {
42 | // 启动 grpc 服务
43 | return server.start();
44 | }
45 |
46 | @Override
47 | public Server shutdown() {
48 | return server.shutdown();
49 | }
50 |
51 | @Override
52 | public Server shutdownNow() {
53 | return server.shutdownNow();
54 | }
55 |
56 | @Override
57 | public boolean isShutdown() {
58 | return server.isShutdown();
59 | }
60 |
61 | @Override
62 | public boolean isTerminated() {
63 | return server.isTerminated();
64 | }
65 |
66 | @Override
67 | public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException {
68 | return server.awaitTermination(l, timeUnit);
69 | }
70 |
71 | @Override
72 | public void awaitTermination() throws InterruptedException {
73 | server.awaitTermination();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/dashboard/src/pages/ServiceDetail/components/MethodDrawer.vue:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
26 |
40 |
41 |
42 |
43 |
72 |
73 |
95 |
--------------------------------------------------------------------------------
/storage/src/main/java/org/serviceplus/storage/api/StorageManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.storage.api;
17 |
18 | import org.slf4j.Logger;
19 | import org.slf4j.LoggerFactory;
20 |
21 | import java.io.FileReader;
22 | import java.io.IOException;
23 | import java.util.Objects;
24 | import java.util.Properties;
25 |
26 | /**
27 | * 存储管理.
28 | *
29 | * @author lixiaoshuang
30 | */
31 | public class StorageManager {
32 |
33 | private static final Logger LOGGER = LoggerFactory.getLogger(StorageManager.class);
34 |
35 | private static final StorageManager storageManager = new StorageManager();
36 |
37 | private StorageApi storageApi;
38 |
39 | private StorageManager() {
40 | }
41 |
42 | public static StorageManager instance() {
43 | return storageManager;
44 | }
45 |
46 | /**
47 | * 初始化存储.
48 | */
49 | public void initialized() {
50 | if (Objects.nonNull(storageApi)) {
51 | return;
52 | }
53 | Properties properties = new Properties();
54 | String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
55 | try {
56 | properties.load(new FileReader(path + "/store.properties"));
57 | } catch (IOException e) {
58 | LOGGER.error("Failed to read the configuration file.", e);
59 | }
60 | RocksDbStorage rocksDbStore = new RocksDbStorage(properties);
61 | rocksDbStore.init();
62 | storageApi = rocksDbStore;
63 | }
64 |
65 | /**
66 | * 获取存储器.
67 | *
68 | * @return StorageApi
69 | */
70 | public StorageApi getStorage() {
71 | return storageApi;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/dashboard/src/pages/Applist/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
36 |
37 |
93 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/util/ResponseUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.serviceplus.broker.util;
18 |
19 |
20 | import org.serviceplus.broker.enums.ErrorCode;
21 | import org.serviceplus.broker.model.Response;
22 |
23 | /**
24 | * @author lixiaoshuang
25 | */
26 | public class ResponseUtil {
27 |
28 | /**
29 | * Construct a successful response to the request with no return value
30 | *
31 | * @param
32 | * @return
33 | */
34 | public static Response success() {
35 | return new Response<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMessage(), null);
36 | }
37 |
38 | /**
39 | * Build a successful access response
40 | *
41 | * @param dada
42 | * @return
43 | */
44 | public static Response success(T dada) {
45 | return new Response<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMessage(), dada);
46 | }
47 |
48 | /**
49 | * Build a successful access response,Specify code and message and data
50 | *
51 | * @param code
52 | * @param message
53 | * @param dada
54 | * @return
55 | */
56 | public static Response success(int code, String message, T dada) {
57 | return new Response<>(code, message, dada);
58 | }
59 |
60 | /**
61 | * Build failure response,Specify code and message
62 | *
63 | * @param code
64 | * @param message
65 | * @return
66 | */
67 | public static Response fail(int code, String message) {
68 | return new Response<>(code, message, null);
69 | }
70 |
71 | /**
72 | * Build failure response
73 | *
74 | * @return
75 | */
76 | public static Response fail() {
77 | return new Response<>(ErrorCode.FAIL.getCode(), ErrorCode.FAIL.getMessage(), null);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/storage/src/main/java/org/serviceplus/storage/server/StorageGrpcServer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.storage.server;
17 |
18 | import io.grpc.Server;
19 | import org.serviceplus.storage.api.RocksDbStorage;
20 | import org.serviceplus.storage.api.StorageApi;
21 | import org.serviceplus.storage.api.StorageManager;
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 |
25 | import java.io.FileReader;
26 | import java.io.IOException;
27 | import java.util.Properties;
28 | import java.util.concurrent.TimeUnit;
29 |
30 | /**
31 | * 存储模块 Grpc 服务端.
32 | *
33 | * @author lixiaoshuang
34 | */
35 | public class StorageGrpcServer extends Server {
36 |
37 | private static final Logger LOGGER = LoggerFactory.getLogger(StorageGrpcServer.class);
38 |
39 | private Server server;
40 |
41 | public StorageGrpcServer(Server server) {
42 | this.server = server;
43 | }
44 |
45 | @Override
46 | public Server start() throws IOException {
47 | // 先初始化 Storage
48 | StorageManager storageManager = StorageManager.instance();
49 | storageManager.initialized();
50 |
51 | // 启动 grpc 服务
52 | return server.start();
53 | }
54 |
55 | @Override
56 | public Server shutdown() {
57 | return server.shutdown();
58 | }
59 |
60 | @Override
61 | public Server shutdownNow() {
62 | return server.shutdownNow();
63 | }
64 |
65 | @Override
66 | public boolean isShutdown() {
67 | return server.isShutdown();
68 | }
69 |
70 | @Override
71 | public boolean isTerminated() {
72 | return server.isTerminated();
73 | }
74 |
75 | @Override
76 | public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException {
77 | return server.awaitTermination(l, timeUnit);
78 | }
79 |
80 | @Override
81 | public void awaitTermination() throws InterruptedException {
82 | server.awaitTermination();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/kv/storage/KvStorageClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.kv.storage;
17 |
18 | import io.grpc.ManagedChannel;
19 | import io.grpc.ManagedChannelBuilder;
20 | import org.serviceplus.broker.util.EnvUtil;
21 | import org.serviceplus.store.proto.KvServiceGrpc;
22 | import org.serviceplus.store.proto.KvServiceOuterClass;
23 |
24 | /**
25 | * @author lixiaoshuang
26 | */
27 | public class KvStorageClient {
28 |
29 | private int port;
30 |
31 | private String host;
32 |
33 | private ManagedChannel channel;
34 |
35 | private KvServiceGrpc.KvServiceBlockingStub kvServiceBlockingStub;
36 |
37 | public void init() {
38 | port = Integer.parseInt(EnvUtil.getProperty("serviceplus.storage.port", "8866"));
39 | host = EnvUtil.getProperty("serviceplus.storage.host", "127.0.0.1");
40 | //初始化连接
41 | channel = ManagedChannelBuilder.forAddress(host, port)
42 | .usePlaintext()
43 | .build();
44 | //初始化远程服务Stub
45 | kvServiceBlockingStub = KvServiceGrpc.newBlockingStub(channel);
46 | }
47 |
48 | /**
49 | * 添加kv
50 | *
51 | * @param key key
52 | * @param value value
53 | * @return result
54 | */
55 | public boolean put(String key, String value) {
56 | KvServiceOuterClass.KvRequest kvRequest = KvServiceOuterClass.KvRequest.newBuilder().setKey(key).setValue(value).build();
57 | KvServiceOuterClass.KvResponse kvResponse = kvServiceBlockingStub.put(kvRequest);
58 | return Boolean.getBoolean(kvResponse.getData());
59 | }
60 |
61 | /**
62 | * 获取kv
63 | *
64 | * @param key key
65 | * @return value
66 | */
67 | public String get(String key) {
68 | KvServiceOuterClass.KvRequest kvRequest = KvServiceOuterClass.KvRequest.newBuilder().setKey(key).build();
69 | KvServiceOuterClass.KvResponse kvResponse = kvServiceBlockingStub.get(kvRequest);
70 | return kvResponse.getData();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/common/src/main/java/org/serviceplus/common/utils/NetworkUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.common.utils;
17 |
18 | import org.slf4j.Logger;
19 | import org.slf4j.LoggerFactory;
20 |
21 | import java.net.InetAddress;
22 | import java.net.NetworkInterface;
23 | import java.util.Enumeration;
24 |
25 | /**
26 | * @author lixiaoshuang
27 | */
28 | public class NetworkUtils {
29 | private static final Logger LOGGER = LoggerFactory.getLogger(NetworkUtils.class);
30 |
31 | /**
32 | * 获取本地主机的精确地址
33 | *
34 | * @return IP地址
35 | */
36 | public static String getLocalHostExactAddress() {
37 | try {
38 | Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces();
39 | while (networkInterfaces.hasMoreElements()) {
40 | NetworkInterface networkInterface = networkInterfaces.nextElement();
41 | for (Enumeration inetAddresses = networkInterface.getInetAddresses();
42 | inetAddresses.hasMoreElements(); ) {
43 | InetAddress inetAddr = inetAddresses.nextElement();
44 | if (!inetAddr.isLoopbackAddress()) {
45 | if (inetAddr.isSiteLocalAddress()) {
46 | return inetAddr.getHostAddress();
47 | }
48 | }
49 | }
50 | }
51 | return getLocalHostIP();
52 | } catch (Exception e) {
53 | LOGGER.error("getLocalHostExactAddress error", e);
54 | }
55 | return null;
56 | }
57 |
58 | /**
59 | * 获取本地主机的IP地址
60 | *
61 | * @return IP地址
62 | */
63 | public static String getLocalHostIP() {
64 | try {
65 | InetAddress localHost = InetAddress.getLocalHost();
66 | return localHost.getHostAddress();
67 | } catch (Exception e) {
68 | LOGGER.error("Unable to obtain IP address", e);
69 | }
70 | return "";
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/dashboard/src/pages/ServiceDetail/result.json:
--------------------------------------------------------------------------------
1 | {
2 | "data": {
3 | "banners": [
4 | {
5 | "id": "1",
6 | "uniqueId": "",
7 | "src": "https://fliggy-axin.oss-cn-beijing.aliyuncs.com/axFiles/FIRST_PAGE_IMAGE/2023/12/13/81f0025d-f6f6-4f4d-8a4b-d5157333457b.png",
8 | "url": "/marketingCampaigns?code=spring-marketing",
9 | "data": {
10 | "routeKeyword": ""
11 | }
12 | },
13 | {
14 | "id": "2",
15 | "uniqueId": "",
16 | "src": "https://fliggy-axin.oss-cn-beijing.aliyuncs.com/axFiles/FIRST_PAGE_IMAGE/2023/10/30/81bbcc31-cb17-416d-91b8-97a4bfb9cc43.png",
17 | "url": "/marketingCampaigns?code=spring-marketing-2",
18 | "data": {
19 | "routeKeyword": ""
20 | }
21 | },
22 | {
23 | "id": "3",
24 | "uniqueId": "",
25 | "src": "https://fliggy-axin.oss-cn-beijing.aliyuncs.com/axFiles/FIRST_PAGE_IMAGE/2023/10/30/acef3749-d475-4147-8375-3f102c58ce59.png",
26 | "url": "",
27 | "data": {
28 | "routeKeyword": ""
29 | }
30 | },
31 | {
32 | "id": "4",
33 | "uniqueId": "",
34 | "src": "https://fliggy-axin.oss-cn-beijing.aliyuncs.com/axFiles/FIRST_PAGE_IMAGE/2023/10/30/19d07b20-0645-4d72-856e-05934a33956b.png",
35 | "url": "",
36 | "data": {
37 | "routeKeyword": ""
38 | }
39 | },
40 | {
41 | "id": "5",
42 | "uniqueId": "",
43 | "src": "https://fliggy-axin.oss-cn-beijing.aliyuncs.com/axFiles/FIRST_PAGE_IMAGE/2023/10/30/b763c907-0ecc-4e24-a13b-608c01b7f3af.png",
44 | "url": "",
45 | "data": {
46 | "routeKeyword": ""
47 | }
48 | },
49 | {
50 | "id": "6",
51 | "uniqueId": "",
52 | "src": "https://fliggy-axin.oss-cn-beijing.aliyuncs.com/axFiles/FIRST_PAGE_IMAGE/2024/01/29/29d2cf99-57ed-425c-86b5-599df276079e.jpeg",
53 | "url": "",
54 | "data": {
55 | "routeKeyword": ""
56 | }
57 | },
58 | {
59 | "id": "7",
60 | "uniqueId": "",
61 | "src": "https://fliggy-axin.oss-cn-beijing.aliyuncs.com/axFiles/FIRST_PAGE_IMAGE/2023/10/30/3b58a2ac-24a7-45d9-ab05-752284faf36c.jpg",
62 | "url": "",
63 | "data": {
64 | "routeKeyword": ""
65 | }
66 | },
67 | {
68 | "id": "8",
69 | "uniqueId": "",
70 | "src": "https://fliggy-axin.oss-cn-beijing.aliyuncs.com/axFiles/FIRST_PAGE_IMAGE/2024/01/30/000685f1-4a21-4b48-af63-3bae73d1ddfd.jpg",
71 | "url": "/marketingCampaigns?code=early-bird-operation",
72 | "data": {
73 | "routeKeyword": ""
74 | }
75 | }
76 | ]
77 | },
78 | "code": 200,
79 | "message": "ok"
80 | }
81 |
--------------------------------------------------------------------------------
/common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | serviceplus
7 | org.serviceplus
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | serviceplus-common
13 |
14 |
15 | 8
16 | 8
17 | UTF-8
18 |
19 |
20 |
21 |
22 |
23 | io.grpc
24 | grpc-netty-shaded
25 | runtime
26 |
27 |
28 | io.grpc
29 | grpc-protobuf
30 |
31 |
32 | io.grpc
33 | grpc-stub
34 |
35 |
36 | javax.annotation
37 | javax.annotation-api
38 |
39 |
40 |
41 |
42 |
43 |
44 | kr.motd.maven
45 | os-maven-plugin
46 | 1.6.2
47 |
48 |
49 |
50 |
51 | org.xolstice.maven.plugins
52 | protobuf-maven-plugin
53 | 0.6.1
54 |
55 | com.google.protobuf:protoc:3.21.7:exe:${os.detected.classifier}
56 | grpc-java
57 | io.grpc:protoc-gen-grpc-java:1.50.2:exe:${os.detected.classifier}
58 |
59 |
60 |
61 |
62 | compile
63 | compile-custom
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/client/src/main/java/org/serviceplus/client/kv/DefaultKvClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.client.kv;
17 |
18 | import io.grpc.ManagedChannel;
19 | import io.grpc.ManagedChannelBuilder;
20 | import org.serviceplus.store.proto.KvServiceGrpc;
21 | import org.serviceplus.store.proto.KvServiceOuterClass;
22 |
23 | import java.util.Properties;
24 |
25 | /**
26 | * @author lixiaoshuang
27 | */
28 | public class DefaultKvClient implements KvClient {
29 |
30 | private static volatile DefaultKvClient instance;
31 | private final ManagedChannel channel;
32 | private final KvServiceGrpc.KvServiceBlockingStub kvServiceBlockingStub;
33 |
34 | public static DefaultKvClient getInstance(Properties properties) {
35 | if (instance == null) {
36 | synchronized (DefaultKvClient.class) {
37 | if (instance == null) {
38 | instance = new DefaultKvClient(properties);
39 | }
40 | }
41 | }
42 | return instance;
43 | }
44 |
45 | private DefaultKvClient(Properties properties) {
46 | String host = properties.getProperty("host");
47 | int post = Integer.parseInt(properties.getProperty("port"));
48 | //初始化连接
49 | this.channel = ManagedChannelBuilder.forAddress(host, post)
50 | .usePlaintext()
51 | .build();
52 | //初始化远程服务Stub
53 | this.kvServiceBlockingStub = KvServiceGrpc.newBlockingStub(channel);
54 | }
55 |
56 | @Override
57 | public boolean put(String key, String value) {
58 | KvServiceOuterClass.KvRequest kvRequest = KvServiceOuterClass.KvRequest.newBuilder().setKey(key).setValue(value).build();
59 | KvServiceOuterClass.KvResponse kvResponse = kvServiceBlockingStub.put(kvRequest);
60 | return Boolean.parseBoolean(kvResponse.getData());
61 | }
62 |
63 | @Override
64 | public String get(String key) {
65 | KvServiceOuterClass.KvRequest kvRequest = KvServiceOuterClass.KvRequest.newBuilder().setKey(key).build();
66 | KvServiceOuterClass.KvResponse kvResponse = kvServiceBlockingStub.get(kvRequest);
67 | return kvResponse.getData();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/storage/src/main/java/org/serviceplus/storage/service/StorageKvService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.storage.service;
17 |
18 | import io.grpc.stub.StreamObserver;
19 | import org.serviceplus.storage.api.StorageApi;
20 | import org.serviceplus.storage.api.StorageManager;
21 | import org.serviceplus.store.proto.KvServiceGrpc;
22 | import org.serviceplus.store.proto.KvServiceOuterClass;
23 | import org.slf4j.Logger;
24 | import org.slf4j.LoggerFactory;
25 |
26 | /**
27 | * kv 操作实现类.
28 | *
29 | * @author lixiaoshuang
30 | */
31 | public class StorageKvService extends KvServiceGrpc.KvServiceImplBase {
32 |
33 | private static final Logger LOGGER = LoggerFactory.getLogger(StorageKvService.class);
34 |
35 | @Override
36 | public void put(KvServiceOuterClass.KvRequest request, StreamObserver responseObserver) {
37 | String key = request.getKey();
38 | String value = request.getValue();
39 | StorageManager storageManager = StorageManager.instance();
40 | StorageApi storage = storageManager.getStorage();
41 | boolean result = storage.put(key, value);
42 | LOGGER.info("put operation,key:{},value:{},result:{}", key, value, result);
43 | KvServiceOuterClass.KvResponse kvResponse = KvServiceOuterClass.KvResponse
44 | .newBuilder().setErrorCode("0").setErrorMessage("").setData(String.valueOf(result)).build();
45 | responseObserver.onNext(kvResponse);
46 | responseObserver.onCompleted();
47 | }
48 |
49 | @Override
50 | public void get(KvServiceOuterClass.KvRequest request, StreamObserver responseObserver) {
51 | String key = request.getKey();
52 | StorageManager storageManager = StorageManager.instance();
53 | StorageApi storage = storageManager.getStorage();
54 | String value = storage.get(key);
55 | LOGGER.info("get operation key:{},value:{}", key, value);
56 | KvServiceOuterClass.KvResponse kvResponse = KvServiceOuterClass.KvResponse
57 | .newBuilder().setErrorCode("0").setErrorMessage("").setData(value).build();
58 | responseObserver.onNext(kvResponse);
59 | responseObserver.onCompleted();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/kv/service/BrokerKvStorageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.kv.service;
17 |
18 | import io.grpc.stub.StreamObserver;
19 | import org.serviceplus.broker.kv.storage.KvStorageClient;
20 | import org.serviceplus.broker.kv.storage.KvStorageClientFactory;
21 | import org.serviceplus.store.proto.KvServiceGrpc;
22 | import org.serviceplus.store.proto.KvServiceOuterClass;
23 | import org.slf4j.Logger;
24 | import org.slf4j.LoggerFactory;
25 | import org.springframework.stereotype.Service;
26 |
27 | /**
28 | * kv 操作实现类.
29 | *
30 | * @author lixiaoshuang
31 | */
32 | @Service
33 | public class BrokerKvStorageService extends KvServiceGrpc.KvServiceImplBase {
34 |
35 | private static final Logger LOGGER = LoggerFactory.getLogger(BrokerKvStorageService.class);
36 |
37 | @Override
38 | public void put(KvServiceOuterClass.KvRequest request, StreamObserver responseObserver) {
39 | String key = request.getKey();
40 | String value = request.getValue();
41 | KvStorageClient kvStorageClient = KvStorageClientFactory.createKvStorageClient();
42 | boolean result = kvStorageClient.put(key, value);
43 | LOGGER.info("put operation,key:{},value:{},result:{}", key, value, result);
44 | KvServiceOuterClass.KvResponse kvResponse = KvServiceOuterClass.KvResponse
45 | .newBuilder().setErrorCode("0").setErrorMessage("").setData(String.valueOf(result)).build();
46 | responseObserver.onNext(kvResponse);
47 | responseObserver.onCompleted();
48 | }
49 |
50 | @Override
51 | public void get(KvServiceOuterClass.KvRequest request, StreamObserver responseObserver) {
52 | String key = request.getKey();
53 | KvStorageClient kvStorageClient = KvStorageClientFactory.createKvStorageClient();
54 | String value = kvStorageClient.get(key);
55 | LOGGER.info("get operation key:{},value:{}", key, value);
56 | KvServiceOuterClass.KvResponse kvResponse = KvServiceOuterClass.KvResponse
57 | .newBuilder().setErrorCode("0").setErrorMessage("").setData(value).build();
58 | responseObserver.onNext(kvResponse);
59 | responseObserver.onCompleted();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/register/storage/MemoryServiceRegisterStorageCenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.register.storage;
17 |
18 | import lombok.extern.slf4j.Slf4j;
19 | import org.apache.commons.lang3.StringUtils;
20 | import org.serviceplus.broker.model.BrokerApplicationInfo;
21 | import org.serviceplus.broker.model.BrokerService;
22 | import org.springframework.stereotype.Component;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 | import java.util.Map;
27 | import java.util.Set;
28 | import java.util.concurrent.ConcurrentHashMap;
29 |
30 | /**
31 | * @author lixiaoshuang
32 | */
33 | @Component
34 | @Slf4j
35 | public class MemoryServiceRegisterStorageCenter implements ServiceRegisterStorageCenter {
36 | /**
37 | * 服务存储
38 | * 应用名 -> 应用ip+port -> 服务列表
39 | */
40 | public static final Map>> SERVICE_MAP = new ConcurrentHashMap<>();
41 |
42 | public static class MemoryServiceRegisterCenterHolder {
43 | public static final MemoryServiceRegisterStorageCenter INSTANCE = new MemoryServiceRegisterStorageCenter();
44 | }
45 |
46 | public static MemoryServiceRegisterStorageCenter getInstance() {
47 | return MemoryServiceRegisterCenterHolder.INSTANCE;
48 | }
49 |
50 | @Override
51 | public void registerService(BrokerApplicationInfo applicationInfo, BrokerService service) {
52 | if (applicationInfo == null || service == null) {
53 | log.error("register service error, applicationInfo: {}, service: {}", applicationInfo, service);
54 | return;
55 | }
56 | SERVICE_MAP.computeIfAbsent(applicationInfo.getApplicationName(), k -> new ConcurrentHashMap<>())
57 | .computeIfAbsent(applicationInfo.getApplicationIp() + applicationInfo.getApplicationPort(), k -> ConcurrentHashMap.newKeySet())
58 | .add(service);
59 | }
60 |
61 | @Override
62 | public List getService(String applicationName, String applicationIp, String applicationPort) {
63 | Map> applicationMap = SERVICE_MAP.get(applicationName);
64 | if (applicationMap == null) {
65 | return new ArrayList<>();
66 | }
67 | Set brokerServices = applicationMap.get(applicationIp + applicationPort);
68 | if (brokerServices == null) {
69 | return new ArrayList<>();
70 | }
71 | return new ArrayList<>(brokerServices);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/register/service/BrokerServiceRegisterService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.register.service;
17 |
18 | import io.grpc.stub.StreamObserver;
19 | import lombok.extern.slf4j.Slf4j;
20 | import org.serviceplus.register.proto.SpServiceRegisterGrpc;
21 | import org.serviceplus.register.proto.SpServiceRegisterOuterClass;
22 | import org.springframework.stereotype.Service;
23 |
24 | /**
25 | * @author lixiaoshuang
26 | */
27 | @Slf4j
28 | @Service
29 | public class BrokerServiceRegisterService extends SpServiceRegisterGrpc.SpServiceRegisterImplBase {
30 |
31 | @Override
32 | public StreamObserver bidirectionalStreamingMethod(
33 | StreamObserver responseObserver) {
34 | StreamObserver streamObserver =
35 | new StreamObserver() {
36 | @Override
37 | public void onNext(SpServiceRegisterOuterClass.ClientRegisterRequest clientRegisterRequest) {
38 | boolean hasServiceRegister = clientRegisterRequest.hasServiceRegister();
39 | if (hasServiceRegister) {
40 | log.info("A request for registration services is received:{}",
41 | clientRegisterRequest.getServiceRegister().getApplicationName());
42 | RegisterUnifiedProcessingCenter.registerApplicationAndService(clientRegisterRequest.getServiceRegister());
43 | }
44 | }
45 |
46 | @Override
47 | public void onError(Throwable throwable) {
48 | System.out.println("收到注册服务请求异常");
49 | }
50 |
51 | @Override
52 | public void onCompleted() {
53 | System.out.println("收到注册服务请求完成");
54 | }
55 | };
56 | // 向客户端返回调用结果
57 | SpServiceRegisterOuterClass.ServiceRegisterResponse registerResponse = SpServiceRegisterOuterClass.ServiceRegisterResponse.newBuilder()
58 | .setMessage("注册服务成功").setCode(200).build();
59 | responseObserver.onNext(SpServiceRegisterOuterClass.ServerRegisterRequest.newBuilder()
60 | .setServiceRegisterResponse(registerResponse).build());
61 | return streamObserver;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/dashboard/src/pages/ServiceDetail/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
14 |
15 |
16 |
17 |
18 |
19 |
25 |
26 |
27 |
28 |
34 |
35 |
78 |
114 |
--------------------------------------------------------------------------------
/website/blog/2019-05-29-long-blog-post.md:
--------------------------------------------------------------------------------
1 | ---
2 | slug: long-blog-post
3 | title: Long Blog Post
4 | authors: endi
5 | tags: [hello, docusaurus]
6 | ---
7 |
8 | This is the summary of a very long blog post,
9 |
10 | Use a `` comment to limit blog post size in the list view.
11 |
12 |
13 |
14 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
15 |
16 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
17 |
18 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
19 |
20 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
21 |
22 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
23 |
24 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
25 |
26 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
27 |
28 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
29 |
30 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
31 |
32 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
33 |
34 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
35 |
36 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
37 |
38 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
39 |
40 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
41 |
42 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
43 |
44 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
45 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/register/storage/MemoryApplicationRegisterStorageCenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.register.storage;
17 |
18 | import lombok.extern.slf4j.Slf4j;
19 | import org.apache.commons.collections4.CollectionUtils;
20 | import org.apache.commons.lang3.StringUtils;
21 | import org.serviceplus.broker.model.BrokerApplicationInfo;
22 | import org.springframework.stereotype.Component;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 | import java.util.Map;
27 | import java.util.Set;
28 | import java.util.concurrent.ConcurrentHashMap;
29 |
30 | /**
31 | * @author lixiaoshuang
32 | */
33 | @Component
34 | @Slf4j
35 | public class MemoryApplicationRegisterStorageCenter implements ApplicationRegisterStorageCenter {
36 | /**
37 | * 应用信息存储
38 | * 应用名 -> 应用列表
39 | */
40 | private static final Map> APPLICATION_MAP = new ConcurrentHashMap<>();
41 | /**
42 | * 应用ip存储
43 | * 应用名 -> 应用ip
44 | */
45 | public static final Map> APPLICATION_IP_MAP = new ConcurrentHashMap<>();
46 |
47 | public static class MemoryApplicationRegisterCenterHolder {
48 | public static final MemoryApplicationRegisterStorageCenter INSTANCE = new MemoryApplicationRegisterStorageCenter();
49 | }
50 |
51 | public static MemoryApplicationRegisterStorageCenter getInstance() {
52 | return MemoryApplicationRegisterCenterHolder.INSTANCE;
53 | }
54 |
55 | @Override
56 | public void registerApplication(String applicationName, BrokerApplicationInfo application) {
57 | if (StringUtils.isBlank(applicationName) || application == null) {
58 | log.error("register application error, applicationName: {}, application: {}", applicationName, application);
59 | return;
60 | }
61 | APPLICATION_MAP.computeIfAbsent(applicationName, k -> ConcurrentHashMap.newKeySet()).add(application);
62 | APPLICATION_IP_MAP.computeIfAbsent(applicationName, k -> ConcurrentHashMap.newKeySet()).add(application.getApplicationIp());
63 | }
64 |
65 | @Override
66 | public List getApplicationList() {
67 | Set applicationNames = APPLICATION_MAP.keySet();
68 | List brokerApplicationInfos = new ArrayList<>();
69 | for (String applicationName : applicationNames) {
70 | Set applications = APPLICATION_MAP.get(applicationName);
71 | if (CollectionUtils.isNotEmpty(applications)) {
72 | brokerApplicationInfos.addAll(applications);
73 | }
74 | }
75 | return brokerApplicationInfos;
76 | }
77 |
78 | @Override
79 | public List getApplicationIps(String applicationName) {
80 | if (StringUtils.isBlank(applicationName) || !APPLICATION_IP_MAP.containsKey(applicationName)) {
81 | return null;
82 | }
83 | return new ArrayList<>(APPLICATION_IP_MAP.get(applicationName));
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/server/BrokerGrpcServerBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.server;
17 |
18 | import com.google.common.util.concurrent.MoreExecutors;
19 | import io.grpc.*;
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 |
23 | import javax.annotation.Nullable;
24 | import java.io.File;
25 | import java.util.List;
26 | import java.util.concurrent.Executor;
27 |
28 | /**
29 | * Grpc 服务端构建者.
30 | *
31 | * @author lixiaoshuang
32 | */
33 | public class BrokerGrpcServerBuilder extends ServerBuilder {
34 |
35 | private static final Logger LOGGER = LoggerFactory.getLogger(BrokerGrpcServerBuilder.class);
36 |
37 | private final ServerBuilder> serverBuilder;
38 |
39 | public BrokerGrpcServerBuilder(ServerBuilder> serverBuilder) {
40 | this.serverBuilder = serverBuilder;
41 | }
42 |
43 | /**
44 | * 通过端口创建 StoreGrpcServerBuilder.
45 | *
46 | * @param port 监听的端口
47 | * @return StoreGrpcServerBuilder
48 | */
49 | public static BrokerGrpcServerBuilder forPort(int port) {
50 | ServerBuilder> builder = ServerBuilder.forPort(port);
51 | return new BrokerGrpcServerBuilder(builder);
52 | }
53 |
54 | /**
55 | * 批量绑定服务实现到服务方法.
56 | *
57 | * @param bindableServices 服务实现
58 | * @return StoreGrpcServerBuilder
59 | */
60 | public BrokerGrpcServerBuilder addService(List bindableServices) {
61 | for (BindableService bindableService : bindableServices) {
62 | this.serverBuilder.addService(bindableService);
63 | LOGGER.info("binding:" + bindableService.bindService().getServiceDescriptor().getName());
64 | }
65 | return this;
66 | }
67 |
68 |
69 | @Override
70 | public BrokerGrpcServerBuilder directExecutor() {
71 | return executor(MoreExecutors.directExecutor());
72 | }
73 |
74 | @Override
75 | public BrokerGrpcServerBuilder executor(@Nullable Executor executor) {
76 | this.serverBuilder.executor(executor);
77 | return this;
78 | }
79 |
80 | @Override
81 | public BrokerGrpcServerBuilder addService(ServerServiceDefinition service) {
82 | this.serverBuilder.addService(service);
83 | return this;
84 | }
85 |
86 | @Override
87 | public BrokerGrpcServerBuilder addService(BindableService bindableService) {
88 | this.serverBuilder.addService(bindableService);
89 | return this;
90 | }
91 |
92 | @Override
93 | public BrokerGrpcServerBuilder fallbackHandlerRegistry(@Nullable HandlerRegistry fallbackRegistry) {
94 | this.serverBuilder.fallbackHandlerRegistry(fallbackRegistry);
95 | return this;
96 | }
97 |
98 | @Override
99 | public BrokerGrpcServerBuilder useTransportSecurity(File certChain, File privateKey) {
100 | this.serverBuilder.useTransportSecurity(certChain, privateKey);
101 | return this;
102 | }
103 |
104 | @Override
105 | public BrokerGrpcServerBuilder decompressorRegistry(@Nullable DecompressorRegistry registry) {
106 | this.serverBuilder.decompressorRegistry(registry);
107 | return this;
108 | }
109 |
110 | @Override
111 | public BrokerGrpcServerBuilder compressorRegistry(@Nullable CompressorRegistry registry) {
112 | this.serverBuilder.compressorRegistry(registry);
113 | return this;
114 | }
115 |
116 | @Override
117 | public Server build() {
118 | return new BrokerGrpcServer(this.serverBuilder.build());
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/storage/src/main/java/org/serviceplus/storage/api/RocksDbStorage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.serviceplus.storage.api;
18 |
19 | import org.rocksdb.Options;
20 | import org.rocksdb.RocksDB;
21 | import org.rocksdb.RocksDBException;
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 |
25 | import java.io.File;
26 | import java.nio.charset.StandardCharsets;
27 | import java.util.Optional;
28 | import java.util.Properties;
29 | import java.util.concurrent.atomic.AtomicBoolean;
30 |
31 | /**
32 | * @author lixiaoshuang
33 | */
34 | public class RocksDbStorage extends AbstractStorage {
35 |
36 | private static final Logger LOGGER = LoggerFactory.getLogger(RocksDbStorage.class);
37 |
38 | private static final String DEFAULT_ROCKSDB_PATH = "rocksdb";
39 |
40 | private static final String ROCKSDB_PATH_KEY = "rocksdb.path";
41 |
42 | private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
43 |
44 | private static RocksDB rocksdb;
45 |
46 | private Properties properties;
47 |
48 |
49 | public RocksDbStorage(Properties properties) {
50 | this.properties = properties;
51 | }
52 |
53 | @Override
54 | public void init() {
55 | if (!INIT_STATUS.compareAndSet(false, true)) {
56 | return;
57 | }
58 | String rocksdbPath = Optional.ofNullable(String.valueOf(properties.get(ROCKSDB_PATH_KEY)))
59 | .orElse(DEFAULT_ROCKSDB_PATH);
60 | File file = new File(rocksdbPath);
61 | if (!file.exists() && !file.isDirectory()) {
62 | boolean mkdir = file.mkdirs();
63 | LOGGER.info("Create a directory for the first time,mkdir:{}", mkdir);
64 | }
65 |
66 | //加载 RocksDB C++ 库的静态方法。
67 | RocksDB.loadLibrary();
68 | try (Options options = new Options()) {
69 | options.setCreateIfMissing(true);
70 | rocksdb = RocksDB.open(options, rocksdbPath);
71 | } catch (RocksDBException e) {
72 | LOGGER.error("Storage initialization error", e);
73 | throw new RuntimeException(e);
74 | }
75 | LOGGER.info("Storage initialization success");
76 | }
77 |
78 | @Override
79 | public void close() {
80 | try {
81 | rocksdb.closeE();
82 | } catch (RocksDBException e) {
83 | LOGGER.error("Storage close error", e);
84 | throw new RuntimeException(e);
85 | }
86 | LOGGER.info("Storage close success");
87 | }
88 |
89 | @Override
90 | public boolean put(String key, String value) {
91 | try {
92 | rocksdb.put(key.getBytes(StandardCharsets.UTF_8), value.getBytes(StandardCharsets.UTF_8));
93 | } catch (RocksDBException e) {
94 | LOGGER.error("put data error", e);
95 | throw new RuntimeException(e);
96 | }
97 | return true;
98 | }
99 |
100 | @Override
101 | public String get(String key) {
102 | try {
103 | return new String(rocksdb.get(key.getBytes(StandardCharsets.UTF_8)));
104 | } catch (RocksDBException e) {
105 | LOGGER.error("get data error", e);
106 | throw new RuntimeException(e);
107 | }
108 | }
109 |
110 | @Override
111 | public boolean delete(String key) {
112 | try {
113 | rocksdb.delete(key.getBytes(StandardCharsets.UTF_8));
114 | } catch (RocksDBException e) {
115 | LOGGER.error("delete data error", e);
116 | throw new RuntimeException(e);
117 | }
118 | return true;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/storage/src/main/java/org/serviceplus/storage/server/StorageGrpcServerBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.storage.server;
17 |
18 | import com.google.common.util.concurrent.MoreExecutors;
19 | import io.grpc.*;
20 | import org.serviceplus.storage.service.StorageServiceManager;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 | import javax.annotation.Nullable;
25 | import java.io.File;
26 | import java.util.List;
27 | import java.util.concurrent.Executor;
28 |
29 | /**
30 | * 存储模块 Grpc 服务端构建者.
31 | *
32 | * @author lixiaoshuang
33 | */
34 | public class StorageGrpcServerBuilder extends ServerBuilder {
35 |
36 | private static final Logger LOGGER = LoggerFactory.getLogger(StorageGrpcServerBuilder.class);
37 |
38 | private final ServerBuilder> serverBuilder;
39 |
40 | public StorageGrpcServerBuilder(ServerBuilder> serverBuilder) {
41 | this.serverBuilder = serverBuilder;
42 | StorageServiceManager storageServiceManager = new StorageServiceManager();
43 | storageServiceManager.initialized();
44 | }
45 |
46 | /**
47 | * 通过端口创建 StoreGrpcServerBuilder.
48 | *
49 | * @param port 监听的端口
50 | * @return StoreGrpcServerBuilder
51 | */
52 | public static StorageGrpcServerBuilder forPort(int port) {
53 | ServerBuilder> builder = ServerBuilder.forPort(port);
54 | return new StorageGrpcServerBuilder(builder);
55 | }
56 |
57 | /**
58 | * 批量绑定服务实现到服务方法.
59 | *
60 | * @param bindableServices 服务实现
61 | * @return StoreGrpcServerBuilder
62 | */
63 | public ServerBuilder addService(List bindableServices) {
64 | for (BindableService bindableService : bindableServices) {
65 | this.serverBuilder.addService(bindableService);
66 | LOGGER.info("binding:" + bindableService.bindService().getServiceDescriptor().getName());
67 | }
68 | return this;
69 | }
70 |
71 |
72 | @Override
73 | public ServerBuilder directExecutor() {
74 | return executor(MoreExecutors.directExecutor());
75 | }
76 |
77 | @Override
78 | public ServerBuilder executor(@Nullable Executor executor) {
79 | this.serverBuilder.executor(executor);
80 | return this;
81 | }
82 |
83 | @Override
84 | public ServerBuilder addService(ServerServiceDefinition service) {
85 | this.serverBuilder.addService(service);
86 | return this;
87 | }
88 |
89 | @Override
90 | public ServerBuilder addService(BindableService bindableService) {
91 | this.serverBuilder.addService(bindableService);
92 | return this;
93 | }
94 |
95 | @Override
96 | public ServerBuilder fallbackHandlerRegistry(@Nullable HandlerRegistry fallbackRegistry) {
97 | this.serverBuilder.fallbackHandlerRegistry(fallbackRegistry);
98 | return this;
99 | }
100 |
101 | @Override
102 | public ServerBuilder useTransportSecurity(File certChain, File privateKey) {
103 | this.serverBuilder.useTransportSecurity(certChain, privateKey);
104 | return this;
105 | }
106 |
107 | @Override
108 | public ServerBuilder decompressorRegistry(@Nullable DecompressorRegistry registry) {
109 | this.serverBuilder.decompressorRegistry(registry);
110 | return this;
111 | }
112 |
113 | @Override
114 | public ServerBuilder compressorRegistry(@Nullable CompressorRegistry registry) {
115 | this.serverBuilder.compressorRegistry(registry);
116 | return this;
117 | }
118 |
119 | @Override
120 | public Server build() {
121 | return new StorageGrpcServer(this.serverBuilder.build());
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/website/docusaurus.config.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 | // Note: type annotations allow type checking and IDEs autocompletion
3 |
4 | const lightCodeTheme = require('prism-react-renderer/themes/github');
5 | const darkCodeTheme = require('prism-react-renderer/themes/dracula');
6 |
7 | /** @type {import('@docusaurus/types').Config} */
8 | const config = {
9 | title: 'Service plus',
10 | tagline: 'Service Plus 致力于打造一个分布式、强一致性 服务+ 的一站式解决方案。',
11 | url: 'https://li-xiao-shuang.github.io/',
12 | baseUrl: '/serviceplus/',
13 | onBrokenLinks: 'throw',
14 | onBrokenMarkdownLinks: 'warn',
15 | favicon: 'img/serviceplus.png',
16 |
17 | // GitHub pages deployment config.
18 | // If you aren't using GitHub pages, you don't need these.
19 | organizationName: 'li-xiao-shuang', // Usually your GitHub org/user name.
20 | projectName: 'serviceplus', // Usually your repo name.
21 |
22 | // Even if you don't use internalization, you can use this field to set useful
23 | // metadata like html lang. For example, if your site is Chinese, you may want
24 | // to replace "en" with "zh-Hans".
25 | i18n: {
26 | defaultLocale: 'en',
27 | locales: ['en'],
28 | },
29 |
30 | presets: [
31 | [
32 | 'classic',
33 | /** @type {import('@docusaurus/preset-classic').Options} */
34 | ({
35 | docs: {
36 | sidebarPath: require.resolve('./sidebars.js'),
37 | // Please change this to your repo.
38 | // Remove this to remove the "edit this page" links.
39 | editUrl:
40 | 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
41 | },
42 | blog: {
43 | showReadingTime: true,
44 | // Please change this to your repo.
45 | // Remove this to remove the "edit this page" links.
46 | editUrl:
47 | 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
48 | },
49 | theme: {
50 | customCss: require.resolve('./src/css/custom.css'),
51 | },
52 | }),
53 | ],
54 | ],
55 |
56 | themeConfig:
57 | /** @type {import('@docusaurus/preset-classic').ThemeConfig} */
58 | ({
59 | navbar: {
60 | title: 'Service Puls',
61 | logo: {
62 | alt: 'My Site Logo',
63 | src: 'img/servicepuls.png',
64 | },
65 | items: [
66 | {
67 | type: 'doc',
68 | docId: 'intro',
69 | position: 'left',
70 | label: 'Tutorial',
71 | },
72 | {to: '/blog', label: 'Blog', position: 'left'},
73 | {
74 | href: 'https://github.com/li-xiao-shuang/serviceplus',
75 | label: 'GitHub',
76 | position: 'right',
77 | },
78 | ],
79 | },
80 | footer: {
81 | style: 'dark',
82 | links: [
83 | {
84 | title: 'Docs',
85 | items: [
86 | {
87 | label: 'Tutorial',
88 | to: '/docs/intro',
89 | },
90 | ],
91 | },
92 | {
93 | title: 'Community',
94 | items: [
95 | {
96 | label: 'Stack Overflow',
97 | href: 'https://stackoverflow.com/questions/tagged/docusaurus',
98 | },
99 | {
100 | label: 'Discord',
101 | href: 'https://discordapp.com/invite/docusaurus',
102 | },
103 | {
104 | label: 'Twitter',
105 | href: 'https://twitter.com/docusaurus',
106 | },
107 | ],
108 | },
109 | {
110 | title: 'More',
111 | items: [
112 | {
113 | label: 'Blog',
114 | to: '/blog',
115 | },
116 | {
117 | label: 'GitHub',
118 | href: 'https://github.com/facebook/docusaurus',
119 | },
120 | ],
121 | },
122 | ],
123 | copyright: `Copyright © ${new Date().getFullYear()} Service Plus.`,
124 | },
125 | prism: {
126 | theme: lightCodeTheme,
127 | darkTheme: darkCodeTheme,
128 | },
129 | }),
130 | };
131 |
132 | module.exports = config;
133 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/register/service/RegisterUnifiedProcessingCenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.register.service;
17 |
18 | import org.serviceplus.broker.model.BrokerApplicationInfo;
19 | import org.serviceplus.broker.model.BrokerService;
20 | import org.serviceplus.broker.register.storage.ApplicationRegisterStorageCenter;
21 | import org.serviceplus.broker.register.storage.BrokerRegisterStorageCenterFactory;
22 | import org.serviceplus.broker.register.storage.ServiceRegisterStorageCenter;
23 | import org.serviceplus.register.proto.SpServiceRegisterOuterClass;
24 |
25 | import java.util.List;
26 |
27 | /**
28 | * @author lixiaoshuang
29 | */
30 | public class RegisterUnifiedProcessingCenter {
31 | /**
32 | * 注册应用及服务
33 | *
34 | * @param serviceRegister 注册信息
35 | */
36 | public static void registerApplicationAndService(SpServiceRegisterOuterClass.ServiceRegister serviceRegister) {
37 | BrokerApplicationInfo brokerApplicationInfo = BrokerApplicationInfo.builder()
38 | .applicationName(serviceRegister.getApplicationName())
39 | .applicationIp(serviceRegister.getApplicationIp())
40 | .applicationPort(serviceRegister.getApplicationPort())
41 | .applicationType(serviceRegister.getApplicationType())
42 | .build();
43 |
44 | ApplicationRegisterStorageCenter applicationRegisterStorageCenter = BrokerRegisterStorageCenterFactory.createApplicationRegisterStorageCenter();
45 | applicationRegisterStorageCenter.registerApplication(serviceRegister.getApplicationName(), brokerApplicationInfo);
46 |
47 | ServiceRegisterStorageCenter serviceRegisterStorageCenter = BrokerRegisterStorageCenterFactory.createServiceRegisterStorageCenter();
48 | serviceRegister.getClientServiceList().forEach(clientService -> {
49 | BrokerService brokerService = getBrokerService(clientService);
50 | serviceRegisterStorageCenter.registerService(brokerApplicationInfo, brokerService);
51 | });
52 | }
53 |
54 | private static BrokerService getBrokerService(SpServiceRegisterOuterClass.ClientService clientService) {
55 | BrokerService brokerService = new BrokerService();
56 | brokerService.setClassName(clientService.getClassName());
57 | brokerService.setSimpleClassName(clientService.getSimpleClassName());
58 | brokerService.setMethodDesc(clientService.getMethodDesc());
59 | brokerService.setMethodName(clientService.getMethodName());
60 | brokerService.setParamNames(clientService.getParamNamesList());
61 | brokerService.setParamDesc(clientService.getParamDescList());
62 | brokerService.setParamTypes(clientService.getParamTypesList());
63 | brokerService.setReturnName(clientService.getReturnName());
64 | brokerService.setReturnType(clientService.getReturnType());
65 | return brokerService;
66 | }
67 |
68 | /**
69 | * 获取应用列表
70 | */
71 | public static List getApplicationList() {
72 | ApplicationRegisterStorageCenter applicationRegisterStorageCenter = BrokerRegisterStorageCenterFactory.createApplicationRegisterStorageCenter();
73 | return applicationRegisterStorageCenter.getApplicationList();
74 | }
75 |
76 | /**
77 | * 获取应用ip列表
78 | *
79 | * @param applicationName 应用名
80 | * @return ip列表
81 | */
82 | public static List getIpList(String applicationName) {
83 | ApplicationRegisterStorageCenter applicationRegisterStorageCenter = BrokerRegisterStorageCenterFactory.createApplicationRegisterStorageCenter();
84 | return applicationRegisterStorageCenter.getApplicationIps(applicationName);
85 | }
86 |
87 | /**
88 | * 获取服务列表
89 | *
90 | * @param applicationName 应用名
91 | * @param applicationIp ip
92 | * @return 服务列表
93 | */
94 | public static List getServiceList(String applicationName, String applicationIp, String applicationPort) {
95 | ServiceRegisterStorageCenter serviceRegisterStorageCenter = BrokerRegisterStorageCenterFactory.createServiceRegisterStorageCenter();
96 | return serviceRegisterStorageCenter.getService(applicationName, applicationIp, applicationPort);
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/broker/src/main/java/org/serviceplus/broker/register/controller/BrokerRegisterController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.broker.register.controller;
17 |
18 | import org.apache.commons.lang3.StringUtils;
19 | import org.serviceplus.broker.enums.ErrorCode;
20 | import org.serviceplus.broker.model.*;
21 | import org.serviceplus.broker.model.vo.BrokerApplicationVO;
22 | import org.serviceplus.broker.model.vo.BrokerServiceVO;
23 | import org.serviceplus.broker.model.vo.ParamInfoVO;
24 | import org.serviceplus.broker.register.service.RegisterUnifiedProcessingCenter;
25 | import org.serviceplus.broker.util.ResponseUtil;
26 | import org.springframework.web.bind.annotation.*;
27 |
28 | import java.util.List;
29 | import java.util.stream.Collectors;
30 | import java.util.stream.IntStream;
31 |
32 | /**
33 | * @author lixiaoshuang
34 | */
35 | @RestController
36 | @RequestMapping(path = "register/v1")
37 | public class BrokerRegisterController {
38 |
39 | @GetMapping(path = "application/list")
40 | public Response> applicationList() {
41 | List result = RegisterUnifiedProcessingCenter.getApplicationList().stream()
42 | .map(brokerApplication -> {
43 | BrokerApplicationVO brokerApplicationVo = new BrokerApplicationVO();
44 | brokerApplicationVo.setApplicationName(brokerApplication.getApplicationName());
45 | brokerApplicationVo.setApplicationPort(brokerApplication.getApplicationPort());
46 | brokerApplicationVo.setApplicationType(brokerApplication.getApplicationType());
47 | brokerApplicationVo.setIpList(RegisterUnifiedProcessingCenter.getIpList(brokerApplication.getApplicationName()));
48 | return brokerApplicationVo;
49 | })
50 | .collect(Collectors.toList());
51 | return ResponseUtil.success(result);
52 | }
53 |
54 | @GetMapping(path = "service/list")
55 | public Response> serviceList(@RequestParam("applicationName") String applicationName,
56 | @RequestParam("applicationIp") String applicationIp,
57 | @RequestParam("applicationPort") String applicationPort) {
58 | if (StringUtils.isBlank(applicationName) || StringUtils.isBlank(applicationIp) || StringUtils.isBlank(applicationPort)) {
59 | return ResponseUtil.fail(ErrorCode.PARAM_ERROR.getCode(), ErrorCode.PARAM_ERROR.getMessage());
60 | }
61 | List serviceList = RegisterUnifiedProcessingCenter.getServiceList(applicationName, applicationIp, applicationPort);
62 | List result = serviceList.stream().map(brokerService -> {
63 | BrokerServiceVO brokerServiceVo = new BrokerServiceVO();
64 | brokerServiceVo.setClassName(brokerService.getClassName());
65 | brokerServiceVo.setSimpleClassName(brokerService.getSimpleClassName());
66 | brokerServiceVo.setMethodName(brokerService.getMethodName());
67 | brokerServiceVo.setMethodDesc(brokerService.getMethodDesc());
68 | List paramInfoVOS = IntStream.range(0, brokerService.getParamNames().size())
69 | .mapToObj(i -> {
70 | ParamInfoVO paramInfoVo = new ParamInfoVO();
71 | paramInfoVo.setParamName(StringUtils.defaultIfBlank(brokerService.getParamDesc().get(i),
72 | brokerService.getParamNames().get(i)));
73 | paramInfoVo.setParamType(brokerService.getParamTypes().get(i));
74 | return paramInfoVo;
75 | }).collect(Collectors.toList());
76 | brokerServiceVo.setParamInfos(paramInfoVOS);
77 | brokerServiceVo.setReturnName(brokerService.getReturnName());
78 | brokerServiceVo.setReturnType(brokerService.getReturnType());
79 | return brokerServiceVo;
80 | }).collect(Collectors.toList());
81 | return ResponseUtil.success(result);
82 | }
83 |
84 | @PostMapping(path = "service/invoke")
85 | public Response invokeService() {
86 | // Object result = RegisterUnifiedProcessingCenter.invokeService(brokerServiceVO);
87 | return ResponseUtil.success("invoke success");
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/serviceplus-spring-boot-starter/src/main/java/org/serviceplus/springboot/starter/SpRegisterScanner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.springboot.starter;
17 |
18 | import org.apache.commons.lang3.StringUtils;
19 | import org.serviceplus.client.ApplicationTypeEnum;
20 | import org.serviceplus.client.ServicePlusFactory;
21 | import org.serviceplus.client.annotation.SpRegister;
22 | import org.serviceplus.client.exception.ClientException;
23 | import org.serviceplus.client.model.SpApplication;
24 | import org.serviceplus.client.model.SpService;
25 | import org.serviceplus.client.register.RegisterClient;
26 | import org.serviceplus.common.constant.EnvironmentConstant;
27 | import org.serviceplus.common.utils.NetworkUtils;
28 | import org.springframework.beans.factory.BeanFactory;
29 | import org.springframework.beans.factory.ListableBeanFactory;
30 | import org.springframework.core.env.Environment;
31 | import org.springframework.stereotype.Component;
32 |
33 | import java.lang.reflect.Method;
34 | import java.lang.reflect.Parameter;
35 | import java.util.Arrays;
36 | import java.util.List;
37 | import java.util.Properties;
38 | import java.util.stream.Collectors;
39 | import java.util.stream.Stream;
40 |
41 | /**
42 | * @author lixiaoshuang
43 | */
44 | public class SpRegisterScanner {
45 |
46 | private static final String PARAM_DESC_SEPARATOR = ";";
47 | private final BeanFactory beanFactory;
48 | private final Environment environment;
49 | private static volatile SpRegisterScanner instance;
50 |
51 | public static SpRegisterScanner getInstance(BeanFactory beanFactory, Environment environment) {
52 | if (instance == null) {
53 | synchronized (SpRegisterScanner.class) {
54 | if (instance == null) {
55 | instance = new SpRegisterScanner(beanFactory, environment);
56 | }
57 | }
58 | }
59 | return instance;
60 | }
61 |
62 | private SpRegisterScanner(BeanFactory beanFactory, Environment environment) {
63 | this.beanFactory = beanFactory;
64 | this.environment = environment;
65 | this.scanner();
66 | }
67 |
68 | /**
69 | * 扫描被@SpRegister注解的方法,将服务注册到注册中心
70 | */
71 | private void scanner() {
72 | if (beanFactory instanceof ListableBeanFactory) {
73 | List spServices = ((ListableBeanFactory) beanFactory).getBeansWithAnnotation(Component.class).values().stream()
74 | .flatMap(bean -> Arrays.stream(bean.getClass().getDeclaredMethods()))
75 | .filter(method -> method.isAnnotationPresent(SpRegister.class))
76 | .map(this::createSpService)
77 | .collect(Collectors.toList());
78 |
79 | SpApplication spApplication = createSpApplication(spServices);
80 | //todo 修改为读配置文件
81 | Properties properties = new Properties();
82 | properties.setProperty("host", "127.0.0.1");
83 | properties.setProperty("port", "8766");
84 | RegisterClient registerClient = ServicePlusFactory.createRegisterClient(properties);
85 | registerClient.register(spApplication);
86 | }
87 | }
88 |
89 | /**
90 | * 创建服务
91 | *
92 | * @param method 方法
93 | * @return 服务
94 | */
95 | private SpService createSpService(Method method) {
96 | SpRegister spRegister = method.getAnnotation(SpRegister.class);
97 | return SpService.builder()
98 | .className(method.getDeclaringClass().getName())
99 | .simpleClassName(method.getDeclaringClass().getSimpleName())
100 | .methodDesc(spRegister.name())
101 | .methodName(method.getName())
102 | .paramNames(Stream.of(method.getParameters()).map(Parameter::getName).collect(Collectors.toList()))
103 | .paramDesc(Arrays.asList(spRegister.paramDesc().split(PARAM_DESC_SEPARATOR)))
104 | .paramTypes(Arrays.asList(method.getParameterTypes()))
105 | .returnNames(method.getReturnType().getName())
106 | .returnTypes(method.getReturnType())
107 | .build();
108 | }
109 |
110 | /**
111 | * 创建应用
112 | *
113 | * @param spServices 服务列表
114 | * @return 应用
115 | */
116 | private SpApplication createSpApplication(List spServices) {
117 | SpApplication spApplication = new SpApplication();
118 | spApplication.setApplicationName(this.getApplicationName());
119 | spApplication.setApplicationIp(NetworkUtils.getLocalHostExactAddress());
120 | spApplication.setApplicationPort(this.getPort());
121 | spApplication.setApplicationType(ApplicationTypeEnum.JAVA.name());
122 | spApplication.setSpServices(spServices);
123 | return spApplication;
124 | }
125 |
126 |
127 | private String getApplicationName() {
128 | String applicationName = environment.getProperty(EnvironmentConstant.APPLICATION_NAME);
129 | if (StringUtils.isBlank(applicationName)) {
130 | throw new ClientException("The application name is not configured.Check the configuration item: spring.application.name");
131 | }
132 | return environment.getProperty(EnvironmentConstant.APPLICATION_NAME);
133 | }
134 |
135 | private String getPort() {
136 | return environment.getProperty(EnvironmentConstant.SERVER_PORT);
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/website/static/img/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.serviceplus
8 | serviceplus
9 | pom
10 | 1.0.0-SNAPSHOT
11 |
12 | storage
13 | broker
14 | client
15 | common
16 | serviceplus-spring-boot-starter
17 |
18 |
19 |
20 | 8
21 | 8
22 | 7.2.2
23 | 4.13.2
24 | 2.18.0
25 | 2.9.1
26 | 1.7.25
27 | 1.50.2
28 | 1.2
29 | 2.7.5
30 | 1.9.6
31 | 1.18.22
32 | 4.4
33 | 3.12.0
34 |
35 |
36 |
37 |
38 | junit
39 | junit
40 | test
41 |
42 |
43 | org.apache.logging.log4j
44 | log4j-api
45 |
46 |
47 | org.apache.logging.log4j
48 | log4j-core
49 |
50 |
51 | org.apache.logging.log4j
52 | log4j-slf4j-impl
53 |
54 |
55 | org.slf4j
56 | slf4j-api
57 |
58 |
59 | org.projectlombok
60 | lombok
61 |
62 |
63 |
64 |
65 |
66 |
67 | org.serviceplus
68 | serviceplus-common
69 | 1.0.0-SNAPSHOT
70 |
71 |
72 | org.serviceplus
73 | serviceplus-client
74 | 1.0.0-SNAPSHOT
75 |
76 |
77 |
78 | org.springframework.boot
79 | spring-boot-dependencies
80 | ${springboot.version}
81 | pom
82 | import
83 |
84 |
85 |
86 | org.rocksdb
87 | rocksdbjni
88 | ${rocksdb.version}
89 |
90 |
91 |
92 | junit
93 | junit
94 | ${junit4.version}
95 | test
96 |
97 |
98 |
99 | org.apache.logging.log4j
100 | log4j-api
101 | ${log4j.version}
102 |
103 |
104 | org.apache.logging.log4j
105 | log4j-core
106 | ${log4j.version}
107 |
108 |
109 |
110 | org.apache.logging.log4j
111 | log4j-slf4j-impl
112 | ${log4j-slf4j-impl.version}
113 |
114 |
115 |
116 | org.slf4j
117 | slf4j-api
118 | ${slf4j-api.version}
119 |
120 |
121 |
122 | javax.annotation
123 | javax.annotation-api
124 | ${javax.annotation-api.version}
125 |
126 |
127 |
128 | io.grpc
129 | grpc-netty-shaded
130 | ${grpc.version}
131 | runtime
132 |
133 |
134 | io.grpc
135 | grpc-protobuf
136 | ${grpc.version}
137 |
138 |
139 | io.grpc
140 | grpc-stub
141 | ${grpc.version}
142 |
143 |
144 | org.projectlombok
145 | lombok
146 | ${lombok.version}
147 |
148 |
149 | org.apache.commons
150 | commons-collections4
151 | ${commons-collections4.version}
152 |
153 |
154 | org.apache.commons
155 | commons-lang3
156 | ${commons-lang3.version}
157 |
158 |
159 |
160 |
161 |
--------------------------------------------------------------------------------
/client/src/main/java/org/serviceplus/client/register/DefaultRegisterClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 service plus open source organization.
3 | *
4 | * Licensed under the Apache License,Version2.0(the"License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.serviceplus.client.register;
17 |
18 | import io.grpc.ManagedChannel;
19 | import io.grpc.ManagedChannelBuilder;
20 | import io.grpc.stub.StreamObserver;
21 | import lombok.extern.slf4j.Slf4j;
22 | import org.serviceplus.client.exception.ClientException;
23 | import org.serviceplus.client.kv.DefaultKvClient;
24 | import org.serviceplus.client.model.SpApplication;
25 | import org.serviceplus.client.model.SpService;
26 | import org.serviceplus.common.constant.ResponseCodeConstant;
27 | import org.serviceplus.register.proto.SpServiceRegisterGrpc;
28 | import org.serviceplus.register.proto.SpServiceRegisterOuterClass;
29 |
30 | import java.util.ArrayList;
31 | import java.util.List;
32 | import java.util.Properties;
33 |
34 | /**
35 | * @author lixiaoshuang
36 | */
37 | @Slf4j
38 | public class DefaultRegisterClient implements RegisterClient {
39 |
40 | private static volatile DefaultRegisterClient instance;
41 |
42 | private final ManagedChannel channel;
43 | private final SpServiceRegisterGrpc.SpServiceRegisterStub spServiceRegisterStub;
44 |
45 | private DefaultRegisterClient(Properties properties) {
46 | String host = properties.getProperty("host");
47 | int post = Integer.parseInt(properties.getProperty("port"));
48 | this.channel = ManagedChannelBuilder.forAddress(host, post)
49 | .usePlaintext()
50 | .build();
51 | this.spServiceRegisterStub = SpServiceRegisterGrpc.newStub(channel);
52 | Runtime.getRuntime().addShutdownHook(new Thread(channel::shutdown));
53 | }
54 |
55 | @Override
56 | public void register(SpApplication spApplication) {
57 | if (spApplication == null) {
58 | throw new IllegalArgumentException("spApplication is null");
59 | }
60 | StreamObserver streamObserver =
61 | spServiceRegisterStub.bidirectionalStreamingMethod(new StreamObserver() {
62 | @Override
63 | public void onNext(SpServiceRegisterOuterClass.ServerRegisterRequest serverRegisterRequest) {
64 | boolean hasServiceRegisterResponse = serverRegisterRequest.hasServiceRegisterResponse();
65 | if (hasServiceRegisterResponse) {
66 | SpServiceRegisterOuterClass.ServiceRegisterResponse serviceRegisterResponse =
67 | serverRegisterRequest.getServiceRegisterResponse();
68 | if (ResponseCodeConstant.OK != serviceRegisterResponse.getCode()) {
69 | log.error("SpService register error:{}", serviceRegisterResponse.getMessage());
70 | throw new ClientException(serviceRegisterResponse.getCode(), serviceRegisterResponse.getMessage());
71 | }
72 | log.info("SpService register response:{}", serviceRegisterResponse.getMessage());
73 | }
74 | }
75 |
76 | @Override
77 | public void onError(Throwable throwable) {
78 | log.error("SpService register error:{}", throwable.getMessage());
79 | }
80 |
81 | @Override
82 | public void onCompleted() {
83 | log.info("SpService register completed");
84 | }
85 | });
86 | // 构建客户端请求
87 | SpServiceRegisterOuterClass.ServiceRegister serviceRegister = SpServiceRegisterOuterClass.ServiceRegister.newBuilder()
88 | .setApplicationName(spApplication.getApplicationName())
89 | .setApplicationIp(spApplication.getApplicationIp())
90 | .setApplicationPort(spApplication.getApplicationPort())
91 | .setApplicationType(spApplication.getApplicationType())
92 | .addAllClientService(this.convertSpServices(spApplication.getSpServices()))
93 | .build();
94 |
95 | SpServiceRegisterOuterClass.ClientRegisterRequest clientRegisterRequest = SpServiceRegisterOuterClass.ClientRegisterRequest.newBuilder()
96 | .setServiceRegister(serviceRegister)
97 | .build();
98 | streamObserver.onNext(clientRegisterRequest);
99 | streamObserver.onCompleted();
100 | }
101 |
102 |
103 | /**
104 | * 将SpService转换为Protobuf消息
105 | *
106 | * @param spServices SpService列表
107 | * @return Protobuf消息列表
108 | */
109 | public List convertSpServices(List spServices) {
110 | List clientServices = new ArrayList<>();
111 | for (SpService spService : spServices) {
112 | SpServiceRegisterOuterClass.ClientService.Builder clientServiceBuilder =
113 | SpServiceRegisterOuterClass.ClientService.newBuilder();
114 | clientServiceBuilder.setClassName(spService.getClassName());
115 | clientServiceBuilder.setSimpleClassName(spService.getSimpleClassName());
116 | clientServiceBuilder.setMethodDesc(spService.getMethodDesc());
117 | clientServiceBuilder.setMethodName(spService.getMethodName());
118 | if (spService.getParamNames() != null) {
119 | clientServiceBuilder.addAllParamNames(spService.getParamNames());
120 | }
121 | if (spService.getParamDesc() != null) {
122 | clientServiceBuilder.addAllParamDesc(spService.getParamDesc());
123 | }
124 | // 将Class>类型的参数转化为字符串(即类的全限定名)
125 | if (spService.getParamTypes() != null) {
126 | List paramTypeNames = new ArrayList<>();
127 | for (Class> paramType : spService.getParamTypes()) {
128 | paramTypeNames.add(paramType.getName());
129 | }
130 | clientServiceBuilder.addAllParamTypes(paramTypeNames);
131 | }
132 |
133 | // 设置返回值名称和类型(需要将Class>类型的返回值转换为字符串)
134 | clientServiceBuilder.setReturnName(spService.getReturnNames());
135 | if (spService.getReturnTypes() != null) {
136 | clientServiceBuilder.setReturnType(spService.getReturnTypes().getName());
137 | }
138 | clientServices.add(clientServiceBuilder.build());
139 | }
140 | return clientServices;
141 | }
142 |
143 |
144 | /**
145 | * 单例模式
146 | *
147 | * @param properties 配置
148 | * @return DefaultRegisterClient
149 | */
150 | public static DefaultRegisterClient getInstance(Properties properties) {
151 | if (instance == null) {
152 | synchronized (DefaultKvClient.class) {
153 | if (instance == null) {
154 | instance = new DefaultRegisterClient(properties);
155 | }
156 | }
157 | }
158 | return instance;
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/website/static/img/undraw_docusaurus_tree.svg:
--------------------------------------------------------------------------------
1 |
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------