@@ -14,10 +14,12 @@ The architecture of this example is shown in the figure below. The running proce
14
14
![ img_1.png] ( ../../../img/mq/start/img_1.png )
15
15
16
16
### Step 1. Start the Subscriber
17
- Build:
17
+ <!-- tabs:start -->
18
+ #### ** Go**
19
+ Build the golang subscriber
18
20
19
21
``` shell
20
- cd ${project_path} / demo/pubsub/server/
22
+ cd demo/pubsub/server/
21
23
go build -o subscriber
22
24
```
23
25
@@ -27,6 +29,29 @@ Start subscriber:
27
29
./subscriber -s pub_subs_demo
28
30
```
29
31
32
+ #### ** Java**
33
+
34
+ Download the java sdk and examples:
35
+
36
+ ``` bash
37
+ git clone https://github.com/layotto/java-sdk
38
+ ```
39
+
40
+ ``` bash
41
+ cd java-sdk
42
+ ```
43
+
44
+ Build and run it:
45
+
46
+ ``` bash
47
+ # build example jar
48
+ mvn -f examples-pubsub-subscriber/pom.xml clean package
49
+ # run the example
50
+ java -jar examples-pubsub-subscriber/target/examples-pubsub-subscriber-1.1.0-jar-with-dependencies.jar
51
+ ```
52
+
53
+ <!-- tabs:end -->
54
+
30
55
If the following information is printed out, it means the startup is successful:
31
56
32
57
``` bash
@@ -38,7 +63,7 @@ Start listening on port 9999 ......
38
63
>
39
64
> - ListTopicSubscriptions
40
65
>
41
- > Calling this API will return the topics subscribed by the application. This program will return "topic1"
66
+ > Calling this API will return the topics subscribed by the application. This program will return "topic1" and "hello"
42
67
>
43
68
> - OnTopicEvent
44
69
>
@@ -65,27 +90,7 @@ You can run Redis with Docker, then compile and run Layotto locally.
65
90
66
91
#### step 2.1. Run Redis with Docker
67
92
68
- 1 . Get the latest version of Redis image.
69
-
70
- Here we pull the latest version of the official image:
71
-
72
- ``` shell
73
- docker pull redis:latest
74
- ```
75
-
76
- 2 . Check local mirror
77
-
78
- Use the following command to check whether Redis is installed:
79
-
80
- ``` shell
81
- docker images
82
- ```
83
-
84
- ![ img.png] ( ../../../img/mq/start/img.png )
85
-
86
- 3 . Run the container
87
-
88
- After the installation is complete, we can use the following command to run the Redis container:
93
+ We can use the following command to run the Redis container:
89
94
90
95
``` shell
91
96
docker run -itd --name redis-test -p 6380:6379 redis
@@ -116,26 +121,59 @@ After completion, the layotto file will be generated in the directory, run it:
116
121
<!-- tabs:end -->
117
122
118
123
### Step 3. Run the Publisher program and call Layotto to publish events
124
+ <!-- tabs:start -->
125
+ #### ** Go**
126
+ Build the golang publisher:
119
127
120
128
``` shell
121
129
cd ${project_path} /demo/pubsub/client/
122
130
go build -o publisher
123
131
./publisher -s pub_subs_demo
124
132
```
125
133
134
+ #### ** Java**
135
+
136
+ Download the java sdk and examples:
137
+
138
+ ``` shell @if.not.exist java-sdk
139
+ git clone https://github.com/layotto/java-sdk
140
+ ```
141
+
142
+ ``` shell
143
+ cd java-sdk
144
+ ```
145
+
146
+ Build:
147
+
148
+ ``` shell @if.not.exist examples-pubsub-publisher/target/examples-pubsub-publisher-1.1.0-jar-with-dependencies.jar
149
+ # build example jar
150
+ mvn -f examples-pubsub-publisher/pom.xml clean package
151
+ ```
152
+
153
+ Run it:
154
+
155
+ ``` shell
156
+ # run the example
157
+ java -jar examples-pubsub-publisher/target/examples-pubsub-publisher-1.1.0-jar-with-dependencies.jar
158
+ ```
159
+
160
+ <!-- tabs:end -->
161
+
126
162
If the following information is printed, the call is successful:
127
163
128
164
``` bash
129
- Published a new event.Topic: topic1 ,Data: value1
165
+ Published a new event.Topic: hello ,Data: world
166
+ Published a new event.Topic: topic1 ,Data: value1
130
167
```
131
168
132
169
### Step 4. Check the event message received by the subscriber
133
170
134
171
Go back to the subscriber's command line and you will see that a new message has been received:
135
172
136
173
``` bash
137
- Start listening on port 9999 ......
138
- Received a new event.Topic: topic1 , Data:value1
174
+ Start listening on port 9999 ......
175
+ Received a new event.Topic: topic1 , Data: value1
176
+ Received a new event.Topic: hello , Data: world
139
177
```
140
178
141
179
### step 5. Stop containers and release resources
0 commit comments