TCP protocol gateway

Protocol Introduction

EMQ X provides the emqx-tcp module as an access module close to the end side. According to the relationship between its functional logic and the entire system, the entire message exchange process can be divided into three parts: terminal side, platform side and Other side:

  1. |<-- Terminal -->|<--------- Broker Side --------->|<--- Others --->|
  2. |<- Sid e ->| |<-- Side -->|
  3. +---+ PUB +-----------+
  4. | D | INCOMING +----------+ PUB +---------+ -->| subscriber|
  5. | E |----------->| |----------->| |--/ +-----------+
  6. | V | | emqx-tcp | | EMQ X |
  7. | I |<-----------| |<-----------| |<-- +-----------+
  8. | C | OUTGOING +----------+ PUB +---------+ \--| publisher |
  9. | E | PUB +-----------+
  10. +---+
  1. On the terminal side, access through the TCP private protocol defined by this module, and then implement data reporting or receive downlink messages.
  2. On the platform side, the main body is the emqx-tcp module and the EMQ X system. emqx-tcp is responsible for the encoding and decoding of messages, and the agent subscribes to downlink topics. Realize to convert the uplink message into the MQTT message PUBLISH in the EMQ X system to the entire system; convert the downlink MQTT message into the message structure of the TCP private protocol, and send it to the terminal.
  3. The other side can subscribe to the topic of the upstream PUBLISH message appearing in 2 to receive the upstream message. Or to publish a message to a specific downlink topic to send data to the terminal side.

Create module

Open EMQ X DashboardTCP gateway - 图1 (opens new window), click the “Modules” tab on the left, and choose to add:

image-20200927213049265

Select TCP private protocol to access the gateway:

image-20200927213049265

Configure related basic parameters:

image-20200927213049265

Add listening port:

image-20200927213049265

Configure monitoring parameters:

image-20200927213049265

Click to confirm to the configuration parameter page:

image-20200927213049265

After clicking Add, the module is added: image-20200927213049265

Configuration parameters

ConfigurationDescription
Idle TimeoutIdle time. If the CONNECT frame is not received after this time, the TCP connection will be closed directly
Uplink TopicUp topic. Uplink message to the message subject in the EMQ system%c: ClientId of the access client, %u: Username of the access client
Downlink TopicDown topic. Uplink message to the message subject in the EMQ system%c: ClientId of the access client, %u: Username of the access client
Max Packet SizeMaximum processing size of a single TCP private protocol message
Force GC PolicyMandatory GC, when the process has processed 1000 messages or sent more than 1M data
Force Shutdown PolicyForced to close the connection, when the process accumulates 8000 messages or the stack memory exceeds 800M