Skip to main content

Microservice gateway using Nats

Project description

Metropolis (Python Microservice Gateway with NATS)

Can we make simple, scalable, observable, operable service gateway?

Purpose

Cloud Native

Single Workload Unit

Service Discovery

Service Mesh

Architecture Concept

  +- Cluster --------------------------------------------------+
  |                                                            |
  |  +- Node-1 --+  +- Node-2 -+  +- Node-3 --+  +- Node-4 -+  |
  |  |           |  |          |  |           |  |          |  |
  |  | Worker-a  |  |          |  |           |  | Worker-d |  |
  |  | Worker-b  |  | Worker-c |  | Worker-a  |  | Worker-c |  |
  |  |    |      |  |    |     |  |    |      |  |    |     |  |
<======= NATS ========= NATS ======================= NATS =======>
  |  |    |      |  |          |  |    |      |  |          |  |
  |  |  Gateway  |  |          |  |  Gateway  |  |          |  |
  |  |    |      |  |          |  |    |      |  |          |  |
  |  +--- | -----+  +----------+  +--- | -----+  +----------+  |
  |       |                            |                       |
  |       +--------------+-------------+                       |
  |                      |                                     |
  |                   Ingress                                  |
  +--------------------- | ------------------------------------+
                         V

Components

Nats

Message bus

Worker

Business Logic worker

Gateway

Service gateway

Example

Install metropolis

$ pip install metropolis

Define Worker task

from metropolis import Worker


worker = Worker(nats='nats://localhost:4222')


@worker.task(subject='foo.bar', queue='worker')
def mytask(data, *args, **kwargs):
    """Simple task which returns reverse string
    """

    return data[0][::-1]


worker.run()

Define Gateway

from metropolis import Gateway
import settings


gateway = Gateway(nats='nats://nats:4222')
gateway.app.run(host='0.0.0.0')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for metropolis, version 0.1.4.dev3
Filename, size File type Python version Upload date Hashes
Filename, size metropolis-0.1.4.dev3-py3-none-any.whl (8.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size metropolis-0.1.4.dev3.tar.gz (5.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page