A project where I'm exploring the basics of concurrency in Go. It shows how to implement an asynchronous job queue with a worker pool, focusing on concurrency while handling HTTP requests.
This project showcases the following key components:
- A Queue data structure for managing a list of jobs.
- A worker pool of a specified size for concurrently processing jobs.
- Handling HTTP requests and processing them asynchronously.
Before you can run the project, make sure you have Go installed on your system.
To set up and run the project, follow these steps:
- Clone the repository:
git clone https://github.com/your-username/async-queue-golang.git
cd async-queue-golang
- Build and run the project:
go build
./async-queue-golang
The project will start a server and listen on port 8080.
To add a job to the queue, send an HTTP request to the /addJob
endpoint. You can include a Name
parameter in the request query, which will be used to simulate work processing.
Example:
curl -X GET 'http://localhost:8080/addJob?Name=YourName'
The project includes a worker pool of size WORKER_POOL_SIZE
(set to 4 by default) for concurrently processing jobs from the queue. The workers will extract the Name
parameter from the request query and send a response.
If the "Name" parameter is provided:
Hello, YourName
If the "Name" parameter is missing or empty:
Error: Name parameter is missing or empty