Tool which allows to passthrough messages fetched from RabbitMQ's queue to NATS PubSub. Useful if you receive a data feed through RabbitMQ, but you need to redistribute it further to multiple clients in the most efficient way.
Allows to create an infrastructure as in the diagram below:
The project is organized into the following structure:
rabbit-going-nats/
├── rabbit-going-nats/ # Main application
│ ├── Program.cs # Application entry point and DI configuration
│ ├── Worker.cs # Background service for message processing
│ ├── Model/ # Configuration models
│ │ ├── RabbitMqConnection.cs
│ │ ├── NatsConnection.cs
│ │ ├── WebServiceConfiguration.cs
│ │ └── ApiJsonSerializerContext.cs # AOT-compatible JSON serialization
│ └── Service/ # Core services
│ ├── IRabbitMqConnectionHandler.cs
│ ├── RabbitMqConnectionHandler.cs
│ ├── INatsConnectionHandler.cs
│ ├── NatsConnectionHandler.cs
│ ├── IMessageStatisticsService.cs # Message statistics tracking
│ ├── MessageStatisticsService.cs
│ ├── IWebMonitoringService.cs # HTTP monitoring service
│ └── WebMonitoringService.cs
├── rabbit-going-nats-tests/ # Test project
│ └── Tests/
│ ├── Integration/ # Integration tests
│ ├── Model/ # Model tests
│ └── Service/ # Service unit tests
└── simple-feature-test/ # End-to-end testing with Docker
├── Makefile # Automated testing pipeline
├── setup-test.sh
├── run-test.sh
└── nats/
└── nats-server.conf
Application supports any .NET compatible environment. May be executed as .NET CLR application with .NET 9+ Runtime or precompiled to a standalone native binary using the NativeAOT functionality.
Officially supported and tested platforms:
- 🐧 Linux AMD64 - Native AOT binary provided via CI/CD
- 🐧 Linux ARM64 - Native AOT binary provided via CI/CD
Unofficially supported platforms:
- 🪟 Windows (x64/ARM64) - Should build and run, but not officially supported
- 🍎 macOS (ARM64) - Should build and run, but not officially supported
Note: This is primarily server-side infrastructure software designed for Linux environments. While .NET's cross-platform nature should allow builds for Windows and macOS, these platforms are not officially tested or supported. Community contributions for other platforms are welcome!
Repository provides automated builds for:
- Native Linux AMD64 - Optimized for x64 server environments
- Native Linux ARM64 - Optimized for ARM64 server environments (Snapdragon, Raspberry Pi, etc.)
You may compile for your specific environment using dotnet publish command.
To run the application:
- Download the binary from latest Release or compile yourself
- Place the binary in a desired folder
- Create appsettings.json as instructed below
NOTE: I personally suggest to run this using supervisor to be sure it gets restarted in case of any failure.
Application expects configuration sections file to be present in the config file,
standard appsettings.json in the workdir:
{
"RabbitMq": {
"HostName": "localhost",
"UserName": "user",
"Port": 5000,
"Password": "password",
"VirtualHost": "",
"QueueName": "test"
},
"Nats": {
"Url": "nats://localhost:4222",
"Subject": "test-subject",
"Secret": "s3cr3t"
},
"WebService": {
"Enabled": true,
"Host": "localhost",
"Port": 8018
}
}You may also use username and password:
{
"Nats": {
"Url": "nats://localhost:4222",
"Username": "<your username>",
"Password": "<your password>"
}
}VirtualHost defaults to "/".
If your NATS server does not have any protection leave Secret and Username/Password fields empty.
This file may be used also to set config details for Nlog Logging.
For example adding there:
{
"Logging": {
"NLog": {
"IncludeScopes": false,
"ParseMessageTemplates": true,
"CaptureMessageProperties": true
}
},
"NLog": {
"autoreload": true,
"internalLogLevel": "Debug",
"internalLogFile": "/var/log/rabbit-going-nats.log",
"throwConfigExceptions": true,
"targets": {
"console": {
"type": "Console",
"layout": "${date}|${level:uppercase=true}|${message} ${exception:format=tostring}|${logger}|${all-event-properties}"
},
"file": {
"type": "AsyncWrapper",
"target": {
"wrappedFile": {
"type": "File",
"fileName": "/var/log/rabbit-going-nats.log",
"layout": {
"type": "JsonLayout",
"Attributes": [
{ "name": "timestamp", "layout": "${date:format=o}" },
{ "name": "level", "layout": "${level}" },
{ "name": "logger", "layout": "${logger}" },
{ "name": "message", "layout": "${message:raw=true}" },
{ "name": "properties", "encode": false, "layout": { "type": "JsonLayout", "includeallproperties": "true" } }
]
}
}
}
}
},
"rules": [
{
"logger": "*",
"minLevel": "Trace",
"writeTo": "File,Console"
}
]
}
}Will cause logging of everything in Debug mode to
/var/log/rabbit-going-nats.log.
NOTE: Be sure to set permissions to the log file, user which runs the application must be able to write to it.
You may use different Nlog targets, be sure to check Nlogs config reference: https://nlog-project.org/config/
Warning: this build includes Sentry.IO logging target support.
The application includes a built-in HTTP monitoring service that provides real-time statistics about message processing. This lightweight service uses HttpListener for minimal overhead.
The web service is configured in the WebService section of appsettings.json:
{
"WebService": {
"Enabled": true,
"Host": "localhost",
"Port": 8018
}
}Enabled: Whether the web service is active (default:true)Host: The hostname to bind to (default:"localhost")Port: The port to listen on (default:8018)
- GET
/health - Returns service health status
- Response:
{ "status": "healthy", "timestamp": "2025-09-30T10:15:30.123Z", "service": "RabbitGoingNats" }
- GET
/statsor GET/statisticsor GET/ - Returns real-time message processing statistics
- Response:
{ "lastMessageReceived": "2025-09-30T10:15:29.456Z", "lastMessageSent": "2025-09-30T10:15:29.458Z", "messagesPerMinute": 42, "messagesInLastHour": 2520 }
- Thread-safe: Concurrent message statistics tracking
- CORS-enabled: Accessible from web browsers
- AOT-compatible: Uses source generators for optimal performance
- Rolling statistics: Automatic cleanup of old data
- Lightweight: Uses
HttpListenerfor minimal resource usage
# Check service health
curl http://localhost:8018/health
# Get message statistics
curl http://localhost:8018/stats
# Pretty-print JSON response
curl -s http://localhost:8018/stats | jqThe project includes comprehensive testing infrastructure with multiple test types and automation.
Located in rabbit-going-nats-tests/Tests/Service/:
- MessageStatisticsServiceTests.cs: Statistics tracking and thread safety
- WebMonitoringServiceTests.cs: HTTP service functionality
- NatsConnectionHandlerTests.cs: NATS connection and message publishing
- RabbitMqConnectionHandlerTests.cs: RabbitMQ connection and consumption
- WorkerTests.cs: Background service lifecycle
Located in rabbit-going-nats-tests/Tests/Integration/:
- ProgramStartupTests.cs: Application startup and dependency injection
- ProgramAdvancedTests.cs: Advanced configuration scenarios
- ProgramConfigurationTests.cs: Configuration validation
- WebMonitoringIntegrationTests.cs: End-to-end web service testing
Automated testing pipeline using Docker containers:
# Run complete integration test
cd simple-feature-test
make allThis will:
- Build the application
- Start RabbitMQ and NATS containers
- Configure test queue and subjects
- Start the application
- Test web service endpoints
- Send test messages and verify forwarding
- Validate message statistics
- Clean up containers
# Run all tests
cd rabbit-going-nats-tests
dotnet test
# Run with detailed output
dotnet test --verbosity normal
# Run specific test category
dotnet test --filter "Integration"
dotnet test --filter "MessageStatisticsServiceTests"If you have Docker installed:
-
Setup containers:
cd simple-feature-test ./setup-test.sh -
Build and run:
dotnet publish # Copy appsettings.json.dist to appsettings.json dotnet run -
Send test messages:
./run-test.sh
-
Test web endpoints:
curl http://localhost:8018/health curl http://localhost:8018/stats
The test suite provides comprehensive coverage including:
- ✅ 290 tests covering all major functionality
- ✅ Dependency injection validation
- ✅ Configuration validation with invalid scenarios
- ✅ Message flow from RabbitMQ to NATS
- ✅ Statistics tracking accuracy and thread safety
- ✅ Web service HTTP endpoints and responses
- ✅ Error handling and edge cases
- ✅ AOT compatibility validation
- ✅
Unit Tests- Completed: 290 comprehensive tests - ✅
Functional tests- Completed: Integration and end-to-end testing - ✅
Monitoring/Statistics- Completed: Web service with real-time stats - Utilize the stopping token for graceful shutdown
- Support multiple sources (multiple RabbitMQ queues)
- Support more authorization methods (JWT, certificates)
- Support message transformation/filtering
- Option to support scripted events: execute commands on connection events
- Support for message routing based on content
- Metrics export (Prometheus, InfluxDB)
Feel free to create any issues or pull requests, they are more than welcome!
Application uses:
-
NLog from https://www.nuget.org/packages/nLog/ under BSD-3 License. Copyright (c) 2004-2024 NLog Project - https://nlog-project.org/ Source code has not been altered.
-
RabbitMQ.Client from https://www.nuget.org/packages/RabbitMQ.Client/7.0.0-rc.12 under Apache-2.0 OR MPL-2.0 license. Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. Source code has not been altered.
-
NATS.Net from https://www.nuget.org/packages/NATS.Net under Apache-2.0 license Copyright © The NATS Authors 2016-2024 Source code has not been altered.
-
All licenses provided in LICENSES folder. Copied from: https://licenses.nuget.org/.
Main application Rabbit-Going-Nats is licenses under MIT license. Creator of the application gives all the credits to the authors of the libraries used in this software and claims no ownership to those parts.
