Skip to content

Commit

Permalink
docs: document producer-consumer example using golang-queue with NSQ
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
appleboy committed Jan 21, 2025
1 parent 6914a8b commit e62a1ea
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions _example/producer-consumer/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
# Example with server and client
# Producer-Consumer Example

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

## Build server
## Prerequisites

- Go 1.22 or later
- [NSQ](https://nsq.io/) installed and running

## Running the Producer

The producer sends tasks to the NSQ topic.

Navigate to the producer directory:

```sh
go build -o app server/main.go
cd _example/producer-consumer/producer
```

## Build client
Run the producer:

```sh
go build -o agent client/main.go
go run main.go
```

## Usage
## Running the Consumer

Run the multiple agent. (open two console in the same terminal)
The consumer processes tasks from the NSQ topic.

Navigate to the consumer directory:

```sh
./agent
cd _example/producer-consumer/consumer
```

Publish the message.
Run the consumer:

```sh
./app
go run main.go
```

## Explanation

- The producer creates a pool of workers and assigns tasks to the queue.
- The consumer listens to the NSQ topic and processes the tasks.

Ensure that NSQ is running and accessible at `127.0.0.1:4150` before starting the producer and consumer.

0 comments on commit e62a1ea

Please sign in to comment.