This guide will help you set up a complete local development environment for the CLOOPS NATS SDK. The instructions are primarily given for macOS, but platform-specific alternatives are provided where applicable.
- Docker and Docker Compose
- .NET SDK (9.0 or later)
- Terminal access with admin privileges
Launch the NATS server using Docker Compose:
# From the project root directory
docker compose up -dThis command starts:
- NATS server with JetStream and WebSockets enabled
- NATS monitoring dashboard (accessible at http://localhost:8222)
- Configured with development-friendly settings
The NATS CLI provides essential tools for managing streams, subjects, and debugging.
# Add NATS tools tap
brew tap nats-io/nats-tools
# Install NATS CLI
brew install nats-io/nats-tools/nats- Windows: Download from NATS CLI Releases
- Linux: Use package manager or download binary from releases
- Manual Install: See Official Installation Guide
Set up host file entries and CLI context:
# Add local development hostname
echo "127.0.0.1 dev.nats.cloops.in" | sudo tee -a /etc/hosts
# Create NATS CLI context (server must be running)
nats context add cloops-local-dev \
--server dev.nats.cloops.in:4222 \
--description "CLOOPS NATS Local Development" \
--selectTest your setup:
# Check server info
nats server info
# List available contexts
nats context ls
# Test basic connectivity
nats pub test.subject "Hello NATS!"Navigate to the SDK directory and run the built-in examples:
cd examples
# Test NATS Core publishing (fire-and-forget)
dotnet run pub
# Test JetStream publishing (durable messaging)
dotnet run dpubCreate a JetStream stream for testing durable messaging:
# Create a stream for Connection Loops events
nats stream create CP_Development \
--subjects 'CP.>' \
--retention=limits \
--max-age=14d \
--storage=fileSet up a consumer to verify message delivery:
# Subscribe to specific events with durable consumer
nats subscribe "CP.cloudpathology_deesha.EffectTriggered" \
--durable=dev-consumer \
--deliver=all-
Start Environment:
docker compose up -d
-
Develop and Test:
cd examples dotnet build dotnet run [your-test-command] -
Monitor Messages (separate terminal):
nats subscribe "CP.>" --durable=dev-monitor -
Clean Up (when done):
docker compose down
# View server statistics
nats server report
# List all streams
nats stream ls
# Monitor real-time message flow
nats monitor
# Check stream info
nats stream info CP_Development
# Purge stream (careful!)
nats stream purge CP_Development
# Delete stream (careful!)
nats stream delete CP_DevelopmentConfigure your development environment with these variables:
# .env file or shell environment
NATS_URL=nats://dev.nats.cloops.in:4222Modify docker-compose.yml for custom configurations:
# Example modifications:
services:
nats:
ports:
- "4222:4222" # NATS client port
- "8222:8222" # HTTP monitoring port
- "6222:6222" # Routing port
command:
- "--jetstream"
- "--store_dir=/data"
- "--max_payload=1MB"
- "--max_file_store=10GB"Connection Refused:
# Check if NATS server is running
docker ps | grep nats
# Check logs
docker compose logs natsCLI Context Issues:
# List and select correct context
nats context ls
nats context select cloops-devPort Conflicts:
# Check what's using NATS ports
lsof -i :4222
lsof -i :8222Host Resolution:
# Verify host file entry
ping dev.nats.cloops.in
# Alternative: use localhost directly
nats context add cloops-local --server localhost:4222If you encounter persistent issues:
# Complete reset
docker compose down -v # Removes volumes
docker compose up -d
# Recreate CLI context
nats context delete cloops-dev
nats context add cloops-dev --server dev.nats.cloops.in:4222 --select- URL: http://localhost:8222
- Features: Server stats, connections, subscriptions, message flow
# Real-time server monitoring
nats monitor
# Subscribe to all messages (debug mode)
nats subscribe ">" --raw
# Monitor specific subject patterns
nats subscribe "CP.>" --count=100