项目简介
本项目是一个用Java语言开发的轻量级、高性能的即时通讯服务器,单机支持数十万至百万在线用户。它基于t-io框架,主要目标是降低即时通讯门槛,快速打造低成本接入在线IM系统。支持多端不同协议间的消息发送,如内置的Http、Websocket、Tcp自定义IM协议等,并提供通过http协议的api接口进行消息发送,无需关心接收端属于什么协议,一个消息格式搞定一切。
项目的主要特性和功能
- 高性能:单机可支持几十万至百万人同时在线。
- 轻量、可扩展性极强:支持集群多机部署,支持SSL/TLS加密传输。
- 消息格式极其简洁:使用JSON格式,支持多种协议(Socket自定义IM协议、Websocket、Http),可分别独立部署。
- 内置消息持久化:支持离线、历史、漫游消息的持久化,保证消息可靠性,高性能存储。
- 丰富的API接口:零成本部署,一键启动。
- 支持多种消息类型:包括文本、图片、语音、视频、音乐、图文等。
- 支持多种操作:包括握手、鉴权、登录、心跳、关闭、获取用户信息、获取持久化聊天消息等。
安装使用步骤
假设用户已经下载了本项目的源码文件,按照以下步骤操作:
1. 引入依赖
在项目的pom.xml
中加入以下依赖:
xml
<dependency>
<groupId>org.j-im</groupId>
<artifactId>jim-server</artifactId>
<version>3.0.0.v20200501-RELEASE</version>
</dependency>
<dependency>
<groupId>org.j-im</groupId>
<artifactId>jim-client</artifactId>
<version>3.0.0.v20200501-RELEASE</version>
</dependency>
2. 配置服务器
创建一个配置文件config/jim.properties
,配置服务器的各项参数,如端口、SSL配置、心跳超时等。
3. 启动服务器
创建一个启动类,如ImServerDemoStart
,初始化并启动IM服务器:
```java
public class ImServerDemoStart {
public static void main(String[] args) throws Exception {
ImServerConfig imServerConfig = new PropertyImServerConfigBuilder("config/jim.properties").build();
initSsl(imServerConfig);
imServerConfig.setImGroupListener(new ImDemoGroupListener());
imServerConfig.setImUserListener(new ImDemoUserListener());
JimServer jimServer = new JimServer(imServerConfig);
jimServer.start();
}
private static void initSsl(ImServerConfig imServerConfig) {
// SSL配置初始化
}
} ```
4. 配置命令处理器
为不同的命令处理器添加业务处理逻辑,如握手请求、登录请求、聊天请求等:
java
CommandManager.registerCommand(Command.COMMAND_HANDSHAKE_REQ, new DemoWsHandshakeProcessor());
CommandManager.registerCommand(Command.COMMAND_LOGIN_REQ, new LoginServiceProcessor());
CommandManager.registerCommand(Command.COMMAND_CHAT_REQ, new DefaultAsyncChatMessageProcessor());
5. 启动客户端
创建一个客户端启动类,如HelloClientStarter
,连接到IM服务器并发送消息:
```java
public class HelloClientStarter {
public static void main(String[] args) throws Exception {
Node serverNode = new Node("localhost", 8888);
ImClientConfig imClientConfig = ImClientConfig.newBuilder()
.clientHandler(new HelloImClientHandler())
.clientListener(new HelloImClientListener())
.build();
JimClient jimClient = new JimClient(imClientConfig);
ImClientChannelContext imClientChannelContext = jimClient.connect(serverNode);
send(imClientChannelContext);
}
private static void send(ImClientChannelContext imClientChannelContext) throws Exception {
// 发送登录请求和聊天消息
}
} ``` 通过以上步骤,即可快速搭建一个基于本项目的即时通讯服务器,并实现客户端与服务器的连接和消息发送。
下载地址
点击下载 【提取码: 4003】【解压密码: www.makuang.net】