Skip to main content

TCP(WebSocket) Service Mesh Gateway

Library for providing a TCP(WebSocket) gateway to the Nuropb service mesh. The Library leverages the Tornado asynchronous networking framework, and can also be used as a template for other TCP connection handlers. In addition, it can also be used as pattern to implement a WebSocket BFF (Backend For Frontend).

There are two primary classes that interact together in providing consumer access to the services hosted on the Service Mesh. It's always tricky how to coordinate the dependencies between classes, especially when there are bidirectional flows and process between them.

Consumers are external to the service mesh, and are considered to be untrusted, and the nature of the connections to be less reliable. The service mesh transport protocol is implemented AMQP over TCP and is more challenging for broad adoption, and especially from browsers and mobile devices. The solution is to provide a WebSocket gateway interface to the service mesh.

The HandlerManager is responsible for incoming tcp (websocket) connections, and the ServiceMeshManager, which is responsible for proxying communications to the service mesh.

The final design is somewhat under consideration, with the options being:

  • Having an overarching coordination class, i.e. a manager of managers
  • or the current design where the ServiceMeshManager is both the service mesh proxy and the HandlerManager's manager.

It's acknowledge that the two classes are tightly coupled. The physical separation helps with logical separation of responsibilities and the ability to test them.

It is important to NOTE that there's a one-to-one relationship between the HandlerManager and ServiceMeshManager. The design requires that for each handler type, there's a dedicated HandlerManager and by inference, a dedicated ServiceMeshManager with its own connection to the service mesh.

handler_manager.HandlerManager

The HandlerManager is responsible for TCP(WebSocket) connection handlers, and does the following:

  • Registers handlers for incoming connections
  • Unregistering handlers for closed connections
  • Authorization validation of new connections
  • Receiving messages from handlers
  • Sending messages to handlers
  • Sending messages to:
    • all registered handlers
    • one specific handler
    • all handlers registered to one user or a set of specific users

service_mesh_manager.ServiceMeshManager

  • Manages a (NuroPb API) connection to the service mesh.
  • Passes messages between HandlerManager and the service mesh API
  • Tracks the state of asynchronous requests from handlers and directs responses from the service mesh back to the originating handler.
  • Is responsible for its and only its, connection authorisation to the service mesh transport layer and broker. NOT any on-behalf-of authorisation for handler connections.

Authentication and Authorization

The HandlerManager is not responsible for authentication. It is designed to verify that authentication has already been done through validating an authorization token provided when a new handler is registered. A bearer token is assumed, however there is plenty of scope for other passwordless authentication mechanisms.

Implementation instantiation and injection:

On ServiceMeshManager instantiation, and instance of the HandlerManager is passed in.

handler_manager = HandlerManager(
    ...
)
service_mesh_manager = ServiceMeshManager(
    ...,
    handler_manager=handler_manager,
)

The challenge provide by this assembly, if forwarding incoming messages from the handlers to the service mesh. the HandlerManager provides a callback function to be called when a message is received, on_handler_message_received.

There are not many times when HandlerManager is initialised with on_handler_message_received, as it is instantiated before ServiceMeshManager. It is however set by the ServiceMeshManager during its instantiation, as follows:

self._handler_manager = handler_manager
self._handler_manager._on_handler_message_received = self._on_handler_message_received

Metadata

Release files for nuropb-gw 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nuropb-gw 0.1.4
File Size Uploaded Provenance Actions
nuropb_gw-0.1.4.tar.gz 18.1 kB Without provenance Details for nuropb_gw-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nuropb-gw 0.1.4
File Interpreter ABI Platform Actions
nuropb_gw-0.1.4-py3-none-any.whl Python 3 none any Details for nuropb_gw-0.1.4-py3-none-any.whl

Total release size: 39.2 kB

Release files / nuropb_gw-0.1.4.tar.gz

Download URL nuropb_gw-0.1.4.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9ea7c8130ebd1bf2da470ad7d886b1762dffc7d613b3a3b8ccc3173ab5d4a372
BLAKE2b-256 checksum
How to use checksums
7917874366729fce0a54e0d69bef649b40dd40f6c88f7a887a5707fdd6059501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0

Release files / nuropb_gw-0.1.4-py3-none-any.whl

Download URL nuropb_gw-0.1.4-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
669d95fd7e4f6d375e6a4f0c3222cffd5af11f15e872c5520e965a9615433488
BLAKE2b-256 checksum
How to use checksums
4489eb54b9fe229a6276a78276c96125d52796b67805f2cad8394da63b98b828
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0

Security for nuropb-gw 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page