Compare commits

9 Commits

Author SHA1 Message Date
88011cf20b . 2025-02-22 23:41:19 +08:00
027fbf781d . 2024-09-22 09:55:13 +08:00
bee336ed5e 补充:ZHub 的rpc使用 2024-09-22 09:48:07 +08:00
621ca23432 . 2024-09-22 09:37:40 +08:00
71fe730e5e 新增:blog set_version_in_go.md 2024-09-22 09:13:09 +08:00
ab2631257b 修改:添加下载入口 2024-04-22 11:37:35 +08:00
c64ff5c035 修改:首页介绍 2024-04-21 14:10:11 +08:00
eeebdae492 . 2024-04-21 12:38:27 +08:00
424eb06417 . 2024-04-21 11:56:14 +08:00
24 changed files with 293 additions and 66 deletions

60
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,60 @@
pipeline {
agent any
tools {
nodejs 'node-v18.18.2' // 使用全局配置的Node.js工具
}
stages {
stage('Checkout') {
steps {
// 从Git仓库克隆项目
checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: '4a774ecd-6ae3-4e27-a5e6-e6488b93b28a', url: 'https://gitea.1216.top/lxy/z-docs.git']])
}
}
stage('Install Dependencies') {
steps {
// 使用配置的Node.js版本安装项目依赖
sh '''
npm config set registry https://registry.npmmirror.com/
npm install
'''
}
}
stage('Build') {
steps {
// 执行构建步骤,比如打包
sh 'npm run build' // 假设你的package.json中有一个名为build的脚本用于打包
}
}
stage('deploy') {
steps {
sshPublisher(publishers: [sshPublisherDesc(
configName: 'u-xg', // SSH服务器的配置名称
transfers: [sshTransfer(
cleanRemote: false,
execCommand: '''
// 这里可以添加在远程机器上执行的其他命令
cd /var/www
rm zhub-docs -rf
mv z-docs zhub-docs
''',
execTimeout: 120000,
flatten: false, // 是否将源文件扁平化到单个目录中
makeEmptyDirs: true, // 是否创建远程目录结构
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '/var/www/z-docs', // 远程机器上的目标目录
removePrefix: 'dist/', // 如果需要,从源文件名中移除的前缀
sourceFiles: 'dist/**' // 要传输的文件模式这里表示dist目录及其所有内容
)],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: true // 设置为true以获取更详细的日志输出
)])
}
}
}
}

View File

@@ -1,7 +0,0 @@
{
"label": "其他常用",
"position": 5,
"link": {
"type": "generated-index"
}
}

View File

@@ -1,7 +0,0 @@
{
"label": "其他组件",
"position": 3,
"link": {
"type": "generated-index"
}
}

View File

@@ -1,7 +0,0 @@
---
sidebar_position: 1
---
# RPC远程调用
#

111
blog/set_version_in_go.md Normal file
View File

@@ -0,0 +1,111 @@
---
slug: setting-version-in-go
title: "在 Go 程序中设置版本号并注入打包"
authors: lxy
tags: [ Golang, Build, Version, CI/CD ]
---
### 场景
在 Go 程序中设置并注入版本号是一种常见的做法,借助 -ldflags 参数,可以在编译时动态传递版本信息,使得生成的可执行文件包含明确的版本标识。这种方法可以帮助开发者轻松管理版本发布,并确保每个构建都带有唯一的版本号,方便后续调试、部署及追踪问题。
---
### 1. 在 `main` 包中设置版本号
#### 示例代码
```go
package main
import (
"flag"
"fmt"
"os"
)
var version string // 定义版本变量
func main() {
// 定义命令行参数
versionFlag := flag.Bool("version", false, "显示版本号")
vFlag := flag.Bool("v", false, "显示版本号")
// 解析命令行参数
flag.Parse()
// 检查版本参数并输出
if *versionFlag || *vFlag {
fmt.Printf("版本号: %s\n", version)
os.Exit(0) // 输出后退出
}
// 主程序逻辑
fmt.Println("运行主程序...")
}
```
#### 打包命令
在打包时使用以下命令注入版本号:
```bash
go build -ldflags "-X 'main.version=$(date +%Y.%m.%d-%H.%M.%S)'" -o your_program_name.exe
```
#### 查看版本号
```bash
your_program_name.exe -version // 显示版本号
```
---
### 2. 在模块中设置版本号
#### `monitor` 包
```go
package monitor
var Version string // 定义版本变量
```
#### 修改 `main.go`
```go
package main
import (
"flag"
"fmt"
"os"
"your_project/monitor" // 修改为实际路径
)
func main() {
// 定义命令行参数
versionFlag := flag.Bool("version", false, "显示版本号")
vFlag := flag.Bool("v", false, "显示版本号")
// 解析命令行参数
flag.Parse()
// 检查版本参数并输出
if *versionFlag || *vFlag {
fmt.Printf("监控版本: %s\n", monitor.Version)
os.Exit(0) // 输出后退出
}
// 主程序逻辑
fmt.Println("运行主程序...")
}
```
#### 打包命令
在打包时使用以下命令注入版本号:
```bash
go build -ldflags "-X 'your_project/monitor.Version=$(date +%Y.%m.%d-%H.%M.%S)'" -o your_program_name.exe
```
---
### 总结
以上示例展示了如何在 `main` 包和模块中设置并注入版本号,以便在打包时动态注入版本号;
同样的也可以按照上面方法注入其他需要在打包时动态注入的其他变量。

8
docs/oth/_category_.json Normal file
View File

@@ -0,0 +1,8 @@
{
"label": "其他常用",
"position": 5,
"link": {
"type": "generated-index",
"description": "这里存放了各种常用的工具。"
}
}

View File

@@ -1,5 +1,5 @@
---
sidebar_position: 1
sidebar_position: 9
---
# 一些命令

29
docs/oth/type-token.md Normal file
View File

@@ -0,0 +1,29 @@
---
sidebar_position: 1
---
# IType
> IType 中实现的 TypeToken
```java
package dev.zhub;
import com.google.gson.reflect.TypeToken;
import java.util.List;
import java.util.Map;
public interface IType {
TypeToken<String> STRING = new TypeToken<String>() {};
TypeToken<Short> SHORT = new TypeToken<Short>() {};
TypeToken<Integer> INT = new TypeToken<Integer>() {};
TypeToken<Long> LONG = new TypeToken<Long>() {};
TypeToken<Double> DOUBLE = new TypeToken<Double>() {};
TypeToken<Map<String, String>> MAP = new TypeToken<Map<String, String>>() {};
TypeToken<List<Map<String, String>>> LMAP = new TypeToken<List<Map<String, String>>>() {};
}
```
```
```

14
docs/oth/微服务.md Normal file
View File

@@ -0,0 +1,14 @@
---
sidebar_position: 1
---
# ZHub 与微服务
- 服务注册与发现:
> 在分布式系统中服务注册与发现是确保系统能够找到并调用正确服务的关键机制。ZHub 作为一个服务注册中心或服务发现机制的一部分它负责维护服务列表service-topic使得其他服务能够通过它找到并调用所需的服务。
- 负载均衡:
> 在分布式系统中负载均衡是确保请求均匀分布到各个服务实例上的关键机制。ZHub 是一个负载均衡器,它可负责将请求分发到不同的服务实例上,以提高系统的可用性和性能。
- 消息队列:
> 在微服务架构中消息队列可以用于异步处理请求和解耦服务之间的通信。ZHub 是一个消息队列服务,它可负责接收、存储和分发消息,使得服务可以在需要时处理这些消息。

View File

@@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: 2
title: 广播消息
description: 发送、接收广播消息
---
@@ -29,4 +29,4 @@ description: 发送、接收广播消息
zhub.broadcast("topic-a", value);
return "send ok!";
}
```
```

View File

@@ -1,5 +1,5 @@
---
sidebar_position: 2
sidebar_position: 3
title: 延时消息
description: zhub 的延时消息使用
---
@@ -32,4 +32,4 @@ description: zhub 的延时消息使用
zhub.delay("topic-delay-a", "delay-value", 1000);
return "send ok!";
}
```
```

View File

@@ -1,6 +1,6 @@
---
sidebar_position: 1
title: 订阅&发布
title: 发布&订阅
description: zhub 创建客户端连接、订阅主题、发送主题消息
---

View File

@@ -0,0 +1,36 @@
---
sidebar_position: 4
title: 远程调用 RPC
description: RPC 远程调用Remote Procedure CallRPC
---
# RPC远程调用
:::tip
RPC 是一种通过网络将远程过程调用Remote Procedure CallRPC封装成消息并传送到远程服务器上的过程。
:::
![zhub-fun.png](https://img.1216.top/docs/zhub/rpc-flow.png)
## 使用场景
> 在分布式环境下,通过 RPC 可以在两个应用之间进行消息传递,实现远程调用。
## rpc的订阅-调用基础示例
### 被调用端
```java
// 订阅 rpc-b 事件, 参数类型为 String
zhub.rpcSubscribe("rpc-b", IType.STRING, r -> {
String str = r.getValue();
System.out.println("接收到 b 事件:" + str);
return r.render("接收到 b 事件:" + str);
});
```
### 调用端
```java
// 调用 rpc-b 事件, 参数类型为 String返回类型为 String
RpcResult<String> rpcResult = zhub.rpc("rpc-b", "hello rpc", IType.STRING);
String result = rpcResult.getResult();
System.out.println("rpc result:" + result);
```

View File

@@ -0,0 +1,8 @@
{
"label": "其他组件",
"position": 3,
"link": {
"type": "generated-index",
"description": "分布式系统常用组件"
}
}

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -11,7 +11,7 @@ const config = {
favicon: 'img/favicon.ico',
// Set the production url of your site here
url: 'https://zhub.1216.top',
url: 'https://zhub.dev',
// Set the /<baseUrl>/ pathname under which your site is served
// For GitHub pages deployment, it is often '/<projectName>/'
baseUrl: '/',
@@ -74,18 +74,10 @@ const config = {
src: 'img/logo.svg',
},
items: [
{
type: 'docSidebar',
sidebarId: 'tutorialSidebar',
position: 'left',
label: '文档',
},
{type: 'docSidebar', sidebarId: 'tutorialSidebar', position: 'left', label: '文档',},
{href: 'https://zhub.dev/release/latest', label: '下载', position: 'left',},
{ to: '/blog', label: 'Blog', position: 'left' },
{
href: 'https://gitee.com/tc608/zhub',
label: 'Gitee',
position: 'right',
},
{href: 'https://gitee.com/tc608/zhub', label: 'Gitee', position: 'right',},
],
},
@@ -95,36 +87,26 @@ const config = {
{
title: '文档',
items: [
{
label: '快速开始',
to: '/docs/intro',
},
{label: '下载', href: 'https://zhub.dev/release/latest/',},
{label: '快速开始', to: '/docs/intro',},
],
},
{
title: '社区',
items: [
{
label: 'Gitee',
href: 'https://gitee.com/tc608',
},
{label: 'Gitee', href: 'https://gitee.com/tc608',},
{label: '微信zhub_dev', to: '/'},
],
},
{
title: '更多',
items: [
{
label: '博客',
to: '/blog',
},
{
label: 'GitHub',
href: 'https://github.com/facebook/docusaurus',
},
{label: '博客', to: '/blog',},
{label: '反馈', href: 'https://gitee.com/tc608/zhub/issues?state=all',},
],
},
],
copyright: `Copyright © ${new Date().getFullYear()} ZHub, Inc. Built with Docusaurus.`,
copyright: `Copyright © ${new Date().getFullYear()} ZHub`,
},
prism: {
theme: lightCodeTheme,

View File

@@ -19,8 +19,8 @@
"@mdx-js/react": "^1.6.22",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^18.0.0",
"react-dom": "^18.0.0"
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "2.4.1",

View File

@@ -4,29 +4,29 @@ import styles from './styles.module.css';
const FeatureList = [
{
title: '易于使用',
title: '轻松易用',
Svg: require('@site/static/img/undraw_docusaurus_mountain.svg').default,
description: (
<>
ZHub 新设计易于安装和用于快速启动运行您的项目
新设计易于使用轻松安装助你快速启动项目运行
</>
),
},
{
title: '专注于重要的事情',
title: '专注要事',
Svg: require('@site/static/img/undraw_docusaurus_tree.svg').default,
description: (
<>
ZHub 让你专注于你的业务我们专注于消息收发数据传递让你多个工程进行之间通讯变得如此的简单
专注消息收发与数据传递极简API让你专注业务使多工程间通讯变得简单
</>
),
},
{
title: 'Powered by ZHUB',
title: '由 ZHub 助力',
Svg: require('@site/static/img/undraw_docusaurus_react.svg').default,
description: (
<>
通过 Golang 编写通讯组件自定义消息协议专注提升服务性能
Golang 编写通讯组件 ZHub 之力专注提升服务性能提供稳定可靠的支持
</>
),
},

View File

@@ -6,7 +6,7 @@
/* You can override the default Infima variables here. */
:root {
--ifm-color-primary: #852e79;
--ifm-color-primary: #2e4785;
--ifm-color-primary-dark: #29784c;
--ifm-color-primary-darker: #277148;
--ifm-color-primary-darkest: #205d3b;
@@ -19,7 +19,7 @@
/* For readability concerns, you should choose a lighter palette in dark mode. */
[data-theme='dark'] {
--ifm-color-primary: #852e79;
--ifm-color-primary: #475c98;
--ifm-color-primary-dark: #21af90;
--ifm-color-primary-darker: #1fa588;
--ifm-color-primary-darkest: #1a8870;