|
3 | 3 | ![Go Report Card][grc] |
4 | 4 | [![License][LIC-BADGE]][LIC] |
5 | 5 |
|
6 | | -mGate is an MQTT proxy. |
7 | 6 |
|
8 | | -It is deployed in front of an MQTT broker and can be used for authorization, packet inspection and modification, logging and debugging and various other purposes. |
| 7 | +mGate is a lightweight, scalable, and customizable IoT API gateway designed to support seamless communication across multiple protocols. It enables real-time packet manipulation, features pluggable authentication mechanisms, and offers observability for monitoring and troubleshooting. Built for flexibility, mGate can be deployed as a sidecar or standalone service and can also function as a library for easy integration into applications. |
| 8 | + |
| 9 | +The extensible nature of mGate allows developers to customize it to fit various IoT ecosystems, ensuring optimal performance and security. |
| 10 | + |
| 11 | +## Key Features |
| 12 | + |
| 13 | +Some of the key features of mGate include multi-protocol support, real-time packet manipulation, pluggable authentication, observability, and scalability, all while being lightweight, customizable, and easily deployable as a sidecar or standalone service. |
| 14 | +<p align="center"><img src="docs/img/features.png"></p> |
| 15 | + |
| 16 | +### 1. Multi-Protocol Support |
| 17 | +mGate is built to interface with a wide range of IoT protocols, including: |
| 18 | +- MQTT |
| 19 | +- CoAP |
| 20 | +- HTTP |
| 21 | +- WebSocket |
| 22 | +- Easily extendable to support additional protocols. |
| 23 | + |
| 24 | +### 2. On-the-Fly Packet Manipulation |
| 25 | +Allows real-time packet transformation and processing. |
| 26 | +Custom logic or package interceptors can be injected for modifying incoming and outgoing messages. |
| 27 | + |
| 28 | +### 3. Authentication and Authorization |
| 29 | +Pluggable authentication system supporting different providers like OAuth, JWT, API Keys, and more. |
| 30 | +Access Control for fine-grained resource authorization. |
| 31 | +Easily replaceable auth modules for integration with custom or enterprise identity systems. |
| 32 | + |
| 33 | +### 4. Observability |
| 34 | +Provides real-time metrics for monitoring system health and performance. |
| 35 | +Offers logging and tracing to facilitate troubleshooting and optimization and options to easily integrate with Prometheus, Grafana, and OpenTelemetry for detailed tracing and visualization. |
| 36 | + |
| 37 | +### 5. Scalable Architecture |
| 38 | +mGate is designed to scale horizontally, ensuring it can handle high-throughput environments. |
| 39 | + |
| 40 | +### 6. Pluggable and Extensible |
| 41 | +Core components are modular, making it easy to plug in custom modules or replace existing ones. |
| 42 | +Extendable to add new IoT protocols, middleware, and features as needed. |
| 43 | + |
| 44 | +### 7. Customizable |
| 45 | +Highly configurable, allowing adjustment of protocol-specific behaviors, observability, and performance optimizations. |
| 46 | +Minimal configuration is required for default deployment but supports deep customization. |
| 47 | + |
| 48 | +### 8. Lightweight |
| 49 | +Built with Go programming language, it's optimized for low resource usage, making it suitable for both high-performance data centers and resource-constrained IoT edge devices. |
| 50 | + |
| 51 | +### 9. Deployment Flexibility |
| 52 | +Can be deployed as a sidecar to enhance existing microservices or as a standalone service for direct IoT device interaction. |
| 53 | +Available as a library for integration into existing applications. |
9 | 54 |
|
10 | 55 | ## Usage |
11 | 56 |
|
|
18 | 63 |
|
19 | 64 | ## Architecture |
20 | 65 |
|
21 | | -mGate starts TCP and WS servers, offering connections to devices. Upon the connection, it establishes a session with a remote MQTT broker. It then pipes packets from devices to the MQTT broker, inspecting or modifying them as they flow through the proxy. |
| 66 | +mGate starts protocol servers, offering connections to devices. Upon the connection, it establishes a session with a remote protocol server. It then pipes packets from devices to the protocol server, inspecting or modifying them as they flow through the proxy. |
22 | 67 |
|
23 | 68 | Here is the flow in more detail: |
24 | 69 |
|
25 | | -- The Device connects to mGate's TCP server |
26 | | -- mGate accepts the inbound (IN) connection and establishes a new session with the remote MQTT broker (i.e. it dials out to the MQTT broker only once it accepts a new connection from a device. This way one device-mGate connection corresponds to one mGate-MQTT broker connection.) |
27 | | -- mGate then spawns 2 goroutines: one that will read incoming packets from the device-mGate socket (INBOUND or UPLINK), inspect them (calling event handlers) and write them to mGate-broker socket (forwarding them towards the broker) and other that will be reading MQTT broker responses from mGate-broker socket and writing them towards device, in device-mGate socket (OUTBOUND or DOWNLINK). |
| 70 | +- The Device connects to mGate's server |
| 71 | +- mGate accepts the inbound (IN) connection and establishes a new session with the remote server (e.g. it dials out to the MQTT broker only once it accepts a new connection from a device. This way one device-mGate connection corresponds to one mGate-MQTT broker connection.) |
| 72 | +- mGate then spawns 2 goroutines: one that will read incoming packets from the device-mGate socket (INBOUND or UPLINK), inspect them (calling event handlers) and write them to mGate-server socket (forwarding them towards the server) and other that will be reading server responses from mGate-server socket and writing them towards device, in device-mGate socket (OUTBOUND or DOWNLINK). |
28 | 73 |
|
29 | 74 | <p align="center"><img src="docs/img/mgate.png"></p> |
30 | 75 |
|
31 | | -mGate can parse and understand MQTT packages, and upon their detection, it calls external event handlers. Event handlers should implement the following interface defined in [pkg/mqtt/events.go](pkg/mqtt/events.go): |
| 76 | +mGate can parse and understand protocol packages, and upon their detection, it calls external event handlers. Event handlers should implement the following interface defined in [pkg/mqtt/events.go](pkg/mqtt/events.go): |
32 | 77 |
|
33 | 78 | ```go |
34 | 79 | // Handler is an interface for mGate hooks |
@@ -61,7 +106,7 @@ type Handler interface { |
61 | 106 | Disconnect(ctx context.Context) |
62 | 107 | } |
63 | 108 | ``` |
64 | | - |
| 109 | +The Handler interface is inspired by MQTT protocol control packets; if the underlying protocol does not support some of these actions, the implementation can simply omit them. |
65 | 110 | An example of implementation is given [here](examples/simple/simple.go), alongside with it's [`main()` function](cmd/main.go). |
66 | 111 |
|
67 | 112 | ## Deployment |
|
0 commit comments