这是用户在 2025-5-5 2:09 为 https://deepwiki.com/Lihuanghe/SMSGate 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Menu

Overview  概述

Relevant source files  相关源文件

SMSGate is a comprehensive SMS gateway framework that provides support for multiple SMS protocols including CMPP (China Mobile), SMPP (Short Message Peer-to-Peer), SGIP (China Unicom), and SMGP (China Telecom). Built on the Netty framework, SMSGate offers asynchronous network communication capabilities with robust session management, message processing, and protocol handling features.
SMSGate 是一个全面的短信网关框架,支持多种短信协议,包括 CMPP(中国移动)、SMPP(短消息对等)、SGIP(中国联通)和 SMGP(中国电信)。基于 Netty 框架构建,SMSGate 提供异步网络通信能力,具有强大的会话管理、消息处理和协议处理功能。

This document provides a technical overview of the SMSGate system architecture, its core components, and the relationships between them. For detailed information on specific components, refer to their respective wiki pages.
本文档提供了 SMSGate 系统架构的技术概述,其核心组件及其之间的关系。有关特定组件的详细信息,请参阅各自的维基页面。

Core Purpose and Features  核心宗旨和功能

SMSGate serves as a flexible, high-performance SMS gateway that enables:
SMSGate 是一款灵活、高性能的短信网关,它能够实现:

  • Sending and receiving SMS messages using various telecommunications protocols
    使用各种电信协议发送和接收短信消息
  • Supporting both client and server roles for each protocol
    支持每个协议的客户端和服务器角色
  • Managing long message splitting and reassembly
    管理长消息的分割和重组
  • Handling various SMS formats (text, WAP Push, Flash messages)
    处理各种短信格式(文本、WAP 推送、闪信)
  • Providing connection management, authentication, and session tracking
    提供连接管理、身份验证和会话跟踪
  • Offering message persistence, retransmission, and flow control
    提供消息持久化、重传和流量控制

The framework is designed for high throughput (tested at 35K messages/second) while maintaining reliability through message persistence and retry mechanisms.
该框架旨在实现高吞吐量(已测试达到每秒 35K 条消息)的同时,通过消息持久化和重试机制来保证可靠性。

Sources: README.md11-15 README.md245-265 README.md272-273
来源:README.md11-15README.md245-265README.md272-273

System Architecture  系统架构

The following diagram illustrates the high-level architecture of the SMSGate system:
以下图示展示了 SMSGate 系统的高级架构:

At the core of the system is the EndpointManager singleton, which manages all endpoints and their lifecycles. Endpoints are represented by EndpointEntity objects, which can be either clients or servers. Each endpoint has an associated EndpointConnector that manages connections and sets up the Netty channel pipeline with appropriate handlers for session management, message encoding/decoding, and business logic.
系统的核心是 EndpointManager 单例,它管理所有端点和它们的生命周期。端点由 EndpointEntity 对象表示,可以是客户端或服务器。每个端点都有一个关联的 EndpointConnector ,它管理连接并设置 Netty 通道管道,带有适当的处理程序以进行会话管理、消息编解码和业务逻辑。

Sources: README.md285-317
来源:README.md285-317

Protocol Support Structure  协议支持结构

The following diagram shows the inheritance structure for the various protocol implementations:
以下图表显示了各种协议实现的继承结构:

Each protocol has both client and server implementations, and server endpoints have child entities for individual connections. The code structure follows a consistent pattern across all supported protocols, making it easier to extend and maintain.
每个协议都有客户端和服务器实现,服务器端点为每个连接有子实体。代码结构在所有支持的协议中遵循一致的模式,使得扩展和维护更加容易。

Sources: README.md288-296
来源:README.md288-296

Message Flow Through System  系统中的消息流程

The following sequence diagram illustrates how messages flow through the SMSGate system:
以下序列图说明了消息如何在 SMSGate 系统中流动:

This diagram shows the complete lifecycle of a message in the system, from connection establishment to message processing to connection termination.
该图展示了系统内消息的完整生命周期,从连接建立到消息处理再到连接终止。

Sources: README.md334-347 README.md143-156
来源:README.md334-347README.md143-156

Key Components  关键组件

EndpointManager  端点管理器

The EndpointManager is a singleton that manages all endpoints, handling their lifecycle including creation, opening, closing, and reconnection. It's responsible for adding endpoint entities, opening/closing endpoints, and maintaining the connection check task.
EndpointManager 是一个单例,负责管理所有端点,处理它们的生命周期,包括创建、打开、关闭和重新连接。它负责添加端点实体、打开/关闭端点以及维护连接检查任务。

EndpointManager
 ├── addEndpointEntity(EndpointEntity)
 ├── openEndpoint(EndpointEntity)
 ├── openAll()
 ├── close()
 └── startConnectionCheckTask()

Sources: README.md314-316
来源:README.md314-316

EndpointEntity Hierarchy  端点实体层次结构

The EndpointEntity class and its subclasses represent connection endpoints with their configurations. Each endpoint includes information such as host, port, credentials, and protocol-specific settings.
EndpointEntity 类及其子类代表具有配置的连接端点。每个端点都包含诸如主机、端口、凭据和协议特定设置等信息。

Entity Type  实体类型Description  描述Main Properties  主要属性
ClientEndpointEntity  客户端端点实体Initiates connections to servers
初始化与服务器建立连接
host, port, credentials, maxChannels
主机、端口、凭证、最大通道数
ServerEndpointEntity  服务器端点实体Listens for incoming connections
监听传入的连接
host, port, children  主机,端口,子节点
ServerChildEndpointEntity
服务器子端点实体
Represents individual server connections
表示单个服务器连接
credentials, businessHandlers
凭证, 业务处理器

Client entities use their configured connection information to establish connections to servers, while server entities listen on specified ports and create child entities for each incoming connection.
客户端实体使用其配置的连接信息与服务器建立连接,而服务器实体监听指定的端口并为每个传入连接创建子实体。

Sources: README.md288-298
来源: README.md288-298

EndpointConnector  端点连接器

The EndpointConnector interface and its implementations are responsible for managing connections and setting up Netty channel pipelines:
EndpointConnector 接口及其实现负责管理连接和设置 Netty 通道管道:

The connectors manage the lifecycle of connections, adding appropriate handlers to the Netty pipeline, and maintaining lists of active channels.
连接器管理连接的生命周期,向 Netty 管道添加适当的处理程序,并维护活动通道的列表。

Sources: README.md300-312
来源:README.md300-312

Session Management  会话管理

The session management components handle connection authentication, message tracking, and retransmission:
会话管理组件处理连接认证、消息跟踪和重传:

  1. SessionLoginManager: Authenticates connections and manages the login process
    会话登录管理器:验证连接并管理登录过程
  2. SessionStateManager: Tracks message state, handles retransmission, and controls message flow
    会话状态管理器:跟踪消息状态,处理重传并控制消息流

Each protocol has its own implementation of these managers to handle protocol-specific details.
每个协议都有自己的管理器实现,以处理特定于协议的细节。

Sources: README.md318-321 README.md322-324
来源:README.md 第 318-321 行 README.md 第 322-324 行

Long Message Handling  长消息处理

The framework automatically handles long SMS messages (exceeding standard SMS length) by splitting them into fragments and reassembling them:
框架自动处理超出标准短信长度的长短信消息,通过将其分割成片段并重新组装:

The system can be configured to use Redis for distributed long message caching in cluster environments.
系统可以配置为在集群环境中使用 Redis 进行分布式长消息缓存。

Sources: README.md143-156 README.md157-162
源文件: README.md143-156README.md157-162

Getting Started  入门

To use SMSGate, you need to:
要使用 SMSGate,您需要:

  1. Add the dependency to your project:
    将依赖项添加到您的项目中:
<dependency>
  <groupId>com.chinamobile.cmos</groupId>
  <artifactId>sms-core</artifactId>
  <version>2.1.13.6</version>
</dependency>
  1. Create and configure endpoint entities for your specific protocols
    为您的特定协议创建和配置端点实体
  2. Add business handlers to process messages
    添加业务处理器以处理消息
  3. Register the endpoint entities with the EndpointManager
    将端点实体注册到 EndpointManager
  4. Open the endpoints and start the connection check task
    打开端点并启动连接检查任务

For more detailed information on configuration and usage, see the Core Architecture and Protocol Support pages.
关于配置和使用的详细信息,请参阅核心架构和协议支持页面。

Sources: README.md9-15 README.md396-482
来源:README.md9-15README.md396-482

Common Use Cases  常见用例

Sending SMS Messages  发送短信消息

To send SMS messages, you need to:
发送短信消息,您需要:

  1. Create a client endpoint entity and configure it
    创建客户端端点实体并配置它
  2. Add it to the EndpointManager
    将其添加到 EndpointManager
  3. Open the endpoint to establish connections
    打开端点以建立连接
  4. Create message objects and send them using the established connections
    创建消息对象并使用已建立的连接发送它们

The framework handles message encoding, splitting long messages, and tracking delivery status.
框架处理消息编码、分割长消息和跟踪投递状态。

Sources: README.md31-36  来源:README.md31-36

Receiving SMS Messages  接收短信消息

To receive SMS messages, you need to:
接收短信消息,您需要:

  1. Create server endpoint entities and configure them
    创建服务器端点实体并配置它们
  2. Implement business handlers to process incoming messages
    实现业务处理器以处理传入的消息
  3. Add the entities to the EndpointManager
    将实体添加到 EndpointManager
  4. Open the endpoints to start listening for connections
    打开端点以开始监听连接

Business handlers can process various message types including delivery reports, incoming messages, and other protocol-specific messages.
业务处理器可以处理各种消息类型,包括投递报告、入站消息和其他协议特定消息。

Sources: README.md58-68  来源:README.md58-68

Advanced Features  高级功能

SMSGate includes several advanced features:
SMSGate 包含多个高级功能:

  • Message Persistence: Messages can be stored to disk to prevent loss during restarts
    消息持久化:消息可以存储到磁盘,以防止重启时丢失
  • Proxy Support: HTTP, HTTPS, SOCKS4, and SOCKS5 proxies are supported
    代理支持:支持 HTTP、HTTPS、SOCKS4 和 SOCKS5 代理
  • SSL Encryption: Connections can be encrypted using SSL
    SSL 加密:可以使用 SSL 加密连接
  • Flow Control: Message rates can be limited to prevent overloading
    流量控制:可以限制消息速率以防止过载
  • HAProxy Protocol Support: Real client IP addresses can be determined when behind proxies
    HAProxy 协议支持:在代理后面可以确定真实客户端 IP 地址
  • Clustered Long Message Handling: Redis-based implementation for distributed environments
    集群长消息处理:适用于分布式环境的基于 Redis 的实现

For more information on these features, see the Advanced Features section.
关于这些功能的更多信息,请参阅高级功能部分。

Sources: README.md82-93 README.md157-162 README.md170-176
来源:README.md82-93README.md157-162README.md170-176