This repository serves as an example for setting up a NATS cluster using Docker Compose. NATS is a simple, secure, and high-performance open-source messaging system for cloud-native applications, IoT messaging, and microservices architectures. This example provides a straightforward way to get started with NATS clustering.
Follow these instructions to get the NATS cluster up and running on your local machine.
- Docker
- Docker Compose
- Clone this repository to your local machine:
Copy code
git clone https://github.com/HiWay-Media/nats-cluster-example.git
- Navigate to the cloned directory:
cd nats-cluster-example
- Start the NATS cluster using Docker Compose:
docker-compose up -d
- Verify that the cluster is running:
docker-compose ps
This command should display three containers running, each representing a member of the NATS cluster.
#should not be able to sub
nats subscribe "test.*" --server localhost:4222 --user=b --password=b
# write message in topic
nats publish "test.broadcast" "ciao" --server localhost:4222 --user=b --password=b
#
You can test the functionality of the NATS cluster by publishing and subscribing to messages.
- Publish a message:
docker-compose exec nats1 nats-pub -s nats://nats1:4222 subject "Hello NATS!"
- Subscribe to the message:
Copy code
docker-compose exec nats2 nats-sub -s nats://nats2:4222 subject
You should see the message "Hello NATS!" being received in the subscriber's console.
The NATS cluster configuration is defined in the docker-compose.yml file. You can modify this file to adjust settings such as the number of nodes, ports, and clustering parameters.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or create a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
- NATS - For providing a lightweight and efficient messaging system.
- Docker - For simplifying the deployment of the NATS cluster using containers.
For any inquiries or assistance, please contact HiWay Media.
Thank you for using the NATS cluster example! 🚀