::: tip
The gateway module was introduced in version 2.0. It brings together protocol decoding and encoding, data forwarding, data calculation, and persistent storage.
:::

## Module Overview

The gateway module is responsible for processing device-side data before it enters the business system. It decodes protocol packets, normalizes messages, forwards data to the correct channel, and supports later calculation and persistence.

<img src="../../../../business/v2/dev/images/gateway/gateway01.png" style="border:1px solid #ccc;border-radius:6px;" alt="Module Overview" loading="lazy" />

* `gateway-boot` is the gateway startup module.
* `fastbee-mq` is the core gateway message module.

## Gateway Data Entry

Device data enters the gateway through the protocol access layer, then flows into the message channel for parsing, routing, and consumption.

<img src="../../../../business/v2/dev/images/gateway/gateway02.png" style="border:1px solid #ccc;border-radius:6px;" alt="Gateway Data Entry" loading="lazy" />

## Message Queue Modes

The gateway message layer supports two modes:

1. `redisChannel` with a local queue.
2. RocketMQ.

The mode is switched through configuration. `redisChannel` is used by default.

```yml
cluster:
  enable: true
  type: redis
```

<img src="../../../../business/v2/dev/images/gateway/gateway03.png" style="border:1px solid #ccc;border-radius:6px;" alt="Message Queue Modes" loading="lazy" />

## Redis Channel Flow

After data is forwarded through the data interface, it is distributed by channel. The following diagrams use `redisChannel` as the example.

Register the required channels:

<img src="../../../../business/v2/dev/images/gateway/gateway04.png" style="border:1px solid #ccc;border-radius:6px;" alt="Redis Channel Flow" loading="lazy" />

Distribute messages after they enter the channel:

<img src="../../../../business/v2/dev/images/gateway/gateway05.png" style="border:1px solid #ccc;border-radius:6px;" alt="Redis Channel Flow" loading="lazy" />

Finally, messages enter the consumer queue where business data processing is performed.

<img src="../../../../business/v2/dev/images/gateway/gateway06.png" style="border:1px solid #ccc;border-radius:6px;" alt="Redis Channel Flow" loading="lazy" />
