Multi-language extension-protocol access
The scalability brought by this function to EMQX is very powerful. It can process any proprietary protocol in a programming language familiar to users, and enjoy the advantages of extremely high concurrent connections brought by the EMQX system.
-Very strong expansion capability. Use gRPC as the RPC communication framework to support various mainstream programming languages -Fully asynchronous IO. The connection layer is implemented in a completely asynchronous non-blocking I/O way -The connection layer is transparent. Fully support TCP\TLS UDP\DTLS connection management, and provide a unified API for the upper layer -Connection management capabilities. For example, the maximum number of connections, rate limits for connections and throughput, IP blacklists, etc.
The main contents of this module include:
Connection layer: This part mainly maintains the life cycle of Socket, and the sending and receiving of data. Its functional requirements include:
-Listen to a port. When a new TCP/UDP connection arrives, a connection process is started to maintain the connection status. -Call the ʻOnSocketCreated callback. Used to notify the external module that the connection is closed. -Call the ʻOnReceivedBytes
callback. Used to notify the external module ** the newly received data packet for this connection**. -Provide
Sendinterface. Called by external modules, **used to send data packets**. -Provide
Close` interface. Called by external modules, used to actively close the connection.Protocol/session layer: This part mainly provides PUB/SUB interface** to realize message intercommunication with the EMQX Broker system. include:
-Provide ʻAuthenticate
interface. Used by external modules to register clients to the cluster. -Provide
StartTimerinterface. Called by external modules to start timers such as heartbeat for the connection process. -Provide
Publishinterface. Used by external modules to publish messages in EMQX Broker. -Provide the
Subscribe interface. Called by external modules to unsubscribe a topic. -Call the ʻOnTimerTimeoutcallback. It is used to handle events that the timer expires. -Call the ʻOnReceivedMessages
callback. Used to receive downlink messages (after subscribing to the topic successfully, if there is a message on the topic, this method will be called back)
For details, see: , for example, the definition of the interface is:
Before using this module, users need to develop and deploy a gRPC service and implement the interface defined by ʻexproto.proto`.
The steps are as follows:
- Copy the current version of
lib/emqx_exproto-<x.y.z>/priv/protos/exproto.proto
file. - Use the gRPC framework of the corresponding programming language to generate the gRPC server code of ʻexproto.proto`.
After the development is completed, the service needs to be deployed to a server that can communicate with EMQX, and the port is open.
The gRPC framework of each language can be referred to:
After successfully deploying the gRPC service, you can open the multi-language extension protocol access module through the dashboard page, and configure the following three parts to use it successfully:
- The listening address of ExProto’s service. Used to receive gRPC requests.
- Configure Listener (Listener) to provide TCP/UDP/SSL/DTLS address monitoring. Used to monitor and receive device connections.
- Specify a service address of
ConnectionHandler
for each listener. A service used to send various event callbacks to users.
Open , click the “Modules” tab on the left, and choose to add:
Select “Multilingual Extended Protocol Access”:
Configure the listening address of the ConnectionAdapter
service, and whether to enable SSL listening for it:
Click “Add Listener” to configure the listener for the ExProto module, including:
- The listener’s
listening address
andlistening type
, which indicate how to receive the Socket connection of the custom protocol.
Click OK to complete the listener addition; click Add to complete the creation of the module: