Named after the Greek god of satire and mockery, also known for his sharp wit and critical eye, Momus scrutinizes and intelligently routes network traffic. By leveraging the dynamic nature of NATS and the robustness of YARP, Momus playfully mocks the complexities of service communication, offering a simplified, yet powerful, solution for modern application architectures.
Momus is in the process of transitioning from private infrastructure to open-source. It's operational and has the potential for production use, but it's not quite there yet. The vision is to refine Momus until it supplants my current setup. Feedback and contributions are welcome and highly appreciated!
At its core, Momus uses NATS for disseminating routing configurations and YARP for handling incoming HTTP requests and routing them to the appropriate backend services. This synergy allows Momus to offer a seamless reverse proxy experience that is both dynamic and resilient.
The architecture of Momus is such that it subscribes to a NATS KeyValue store, which holds the routing configurations. Whenever a change is detected in the configuration, Momus updates its routes accordingly, without the need for service restarts. This offers a significant advantage in terms of uptime and flexibility.
- Real-Time Configuration Updates: Utilize NATS KeyValue stores to manage and apply routing configurations dynamically.
- YARP Integration: Leverage the advanced features of YARP to efficiently proxy HTTP requests to backend services.
- Resilient and Scalable: Designed to handle failures gracefully and scale with your application's needs.
Before diving into Momus, you'll need to have a running instance of nats-server
with JetStream enabled. This is neccessary for Momus to function, as it relies on NATS for dynamic configuration updates.
For instructions on how to set up nats-server
with JetStream, refer to the official NATS documentation.
To see Momus in action, refer to the ConfigUpdater
demo project included in the repository. This project illustrates how to publish updates to the routing configuration, showcasing the dynamic nature of Momus.
Live Example: https://devsite.in
To demonstrate Momus in action, I put a demo up at https://devsite.in
. This section outlines the steps I took to set it up. It uses Momus, Cloudflare, and a Digital Ocean droplet.
-
I created a new Digital Ocean droplet, selecting the Docker option from the Marketplace to ensure Docker and Docker Compose were pre-installed.
-
DNS entries were updated on Cloudflare to proxy requests to the IP address of the newly created droplet.
-
SSH into the Digital Ocean droplet:
ssh root@<droplet-ip-address>
-
Download the
docker-compose.yml
file from the Momus GitHub repository and deploy the services using Docker Compose:curl -sS -L https://raw.githubusercontent.com/rickdotnet/Momus/main/docker-compose.yml -o docker-compose.yml && docker compose up -d
-
To update the routing configuration,
nats-box
was used to interact with the NATS server:docker run --network root_devsite --rm -it -v $(pwd)/nsc:/nsc natsio/nats-box:latest
-
Inside the
nats-box
container, the following commands were executed to establish the NATS context and update the key-value store with the new route configuration:nats context save local --server=nats:https://nats:4222 --select nats kv put momus route-config "{\"Routes\":[{\"RouteId\":\"1f8873f3-4106-4d57-bb69-aeebca57118d\",\"Match\":{\"Hosts\":[\"devsite.in\"],\"Path\":\"{**catch-all}\"},\"ClusterId\":\"5007c31d-e9f6-4063-89cc-a2d433065201\",\"Metadata\":{\"RedirectWww\":\"true\",\"UseOriginalHostHeader\":\"true\"}}],\"Clusters\":[{\"ClusterId\":\"5007c31d-e9f6-4063-89cc-a2d433065201\",\"Destinations\":{\"devsite\":{\"Address\":\"https://web-test:8000\"}}}]}"
{ "Routes": [ { "RouteId": "1f8873f3-4106-4d57-bb69-aeebca57118d", "Match": { "Hosts": [ "devsite.in" ], "Path": "{**catch-all}" }, "ClusterId": "5007c31d-e9f6-4063-89cc-a2d433065201", "Metadata": { "RedirectWww": "true", "UseOriginalHostHeader": "true" } } ], "Clusters": [ { "ClusterId": "5007c31d-e9f6-4063-89cc-a2d433065201", "Destinations": { "devsite": { "Address": "https://web-test:8000" } } } ] }
This configuration directs all traffic for
https://devsite.in
to theweb-test
service.
Momus is released under the MIT License. See the LICENSE file for more details.
This project leverages the power of YARP and NATS, and we are grateful to the maintainers of these projects for their contributions to the open-source community.