Skip to content

Commit 57d44ac

Browse files
authored
feature: Optimized pubsub api demo (#594)
1 parent 32d5cd6 commit 57d44ac

File tree

8 files changed

+34
-171
lines changed

8 files changed

+34
-171
lines changed

demo/pubsub/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
You can run server/client demo with different component names.
2+
It is worth noting that both server and client demo should set the same store name by param `-s`.
3+
For example:
4+
```shell
5+
cd ${project_path}/demo/pubsub/server/
6+
// 1. start subscriber
7+
go build -o subscriber
8+
/.subscriber -s pub_subs_demo
9+
10+
// 2. start layotto
11+
cd ${project_path}/cmd/layotto
12+
go build -o layotto
13+
./layotto start -c ../../configs/config_in_memory.json
14+
15+
// 3. start publisher
16+
cd ${project_path}/demo/pubsub/client/
17+
go build -o publisher
18+
./publisher -s pub_subs_demo
19+
20+
```

demo/pubsub/common/client/publish_client.go renamed to demo/pubsub/client/publish_client.go

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ func init() {
3434

3535
func main() {
3636
flag.Parse()
37+
if storeName == "" {
38+
panic("storeName is empty.")
39+
}
3740
// 1. construct client
3841
cli, err := client.NewClient()
3942
if err != nil {

demo/pubsub/in-memory/in-memory.go

-46
This file was deleted.

demo/pubsub/redis/client/publish_client.go

-47
This file was deleted.

demo/pubsub/redis/server/subscribe_server.go

-70
This file was deleted.

demo/pubsub/common/server/subscribe_server.go renamed to demo/pubsub/server/subscribe_server.go

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func init() {
3939

4040
func main() {
4141
flag.Parse()
42+
if storeName == "" {
43+
panic("storeName is empty.")
44+
}
4245
// start a grpc server for callback
4346
testSub()
4447
}

docs/en/start/pubsub/start.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ Parameter Description:
4848
Build:
4949

5050
```shell
51-
cd ${project_path}/demo/pubsub/redis/server/
51+
cd ${project_path}/demo/pubsub/server/
5252
go build -o subscriber
5353
```
5454

5555
Start subscriber:
5656

5757
```shell @background
58-
./subscriber
58+
./subscriber -s pub_subs_demo
5959
```
6060
If the following information is printed out, it means the startup is successful:
6161

@@ -98,9 +98,9 @@ After completion, the layotto file will be generated in the directory, run it:
9898
### Step 4. Run the Publisher program and call Layotto to publish events
9999

100100
```shell
101-
cd ${project_path}/demo/pubsub/redis/client/
101+
cd ${project_path}/demo/pubsub/client/
102102
go build -o publisher
103-
./publisher
103+
./publisher -s pub_subs_demo
104104
```
105105

106106
If the following information is printed, the call is successful:

docs/zh/start/pubsub/start.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ docker run -itd --name redis-test -p 6380:6379 redis
4545

4646
### 第二步:启动Subscriber程序,订阅事件
4747
```shell
48-
cd ${project_path}/demo/pubsub/redis/server/
48+
cd ${project_path}/demo/pubsub/server/
4949
go build -o subscriber
5050
```
5151

5252
```shell @background
53-
./subscriber
53+
./subscriber -s pub_subs_demo
5454
```
5555
打印出如下信息则代表启动成功:
5656

@@ -95,9 +95,9 @@ go build -o layotto
9595
### 第四步:运行Publisher程序,调用Layotto发布事件
9696

9797
```shell
98-
cd ${project_path}/demo/pubsub/redis/client/
98+
cd ${project_path}/demo/pubsub/client/
9999
go build -o publisher
100-
./publisher
100+
./publisher -s pub_subs_demo
101101
```
102102

103103
打印出如下信息则代表调用成功:

0 commit comments

Comments
 (0)