Skip to content

Commit e62a1ea

Browse files
committed
docs: document producer-consumer example using golang-queue with NSQ
- Update title to "Producer-Consumer Example" - Add a detailed description of the example using `golang-queue` with NSQ - Introduce prerequisites section with Go 1.22+ and NSQ installation - Add instructions for running the producer, including directory navigation and running the producer - Add instructions for running the consumer, including directory navigation and running the consumer - Add an explanation section detailing the roles of the producer and consumer - Ensure NSQ is running and accessible before starting the producer and consumer Signed-off-by: appleboy <[email protected]>
1 parent 6914a8b commit e62a1ea

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

_example/producer-consumer/README.md

+29-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
1-
# Example with server and client
1+
# Producer-Consumer Example
22

3-
Please refer the following steps to build server and client.
3+
This example demonstrates how to use the `golang-queue` library with NSQ to implement a producer-consumer pattern.
44

5-
## Build server
5+
## Prerequisites
6+
7+
- Go 1.22 or later
8+
- [NSQ](https://nsq.io/) installed and running
9+
10+
## Running the Producer
11+
12+
The producer sends tasks to the NSQ topic.
13+
14+
Navigate to the producer directory:
615

716
```sh
8-
go build -o app server/main.go
17+
cd _example/producer-consumer/producer
918
```
1019

11-
## Build client
20+
Run the producer:
1221

1322
```sh
14-
go build -o agent client/main.go
23+
go run main.go
1524
```
1625

17-
## Usage
26+
## Running the Consumer
1827

19-
Run the multiple agent. (open two console in the same terminal)
28+
The consumer processes tasks from the NSQ topic.
29+
30+
Navigate to the consumer directory:
2031

2132
```sh
22-
./agent
33+
cd _example/producer-consumer/consumer
2334
```
2435

25-
Publish the message.
36+
Run the consumer:
2637

2738
```sh
28-
./app
39+
go run main.go
2940
```
41+
42+
## Explanation
43+
44+
- The producer creates a pool of workers and assigns tasks to the queue.
45+
- The consumer listens to the NSQ topic and processes the tasks.
46+
47+
Ensure that NSQ is running and accessible at `127.0.0.1:4150` before starting the producer and consumer.

0 commit comments

Comments
 (0)