若依集成IM(推送系统)MobileIMSDK 实现服务器端代码

这里写自定义目录标题


想搭建自己的IM系统,查了不少资料觉得MobileIMSDK还是不错的选择,现在我们使用rouyi (基于springboot的权限管理系统)来快速搭建:
第一步:下载若依管理系统
基于SpringBoot的权限管理系统

官网地址:

​ ​http://www.ruoyi.vip/​​

下载地址:

​ ​https://gitee.com/y_project/RuoYi​

导入到idea中。这里我的项目使用了 RuoYi-Cloud 微服务版

第一步:下载 MobileIMSDK

https://gitee.com/jackjiang/MobileIMSDK

IM服务端的代码的位置在demo_src下的MobileIMSDKServerDemo下
在这里插入图片描述
主要是有这三个类,ServerLaunchImpl是其启动类。
MobileIMSDK核心业务在lib下的sdk的jar包中
在这里插入图片描述
MobileIMSDK核心sdk的源码位置在sdk_src下
在这里插入图片描述
所以在搭建好若依项目后打开,暂且将im的服务放在ruoyi-admin模块下,打开ruoyi-system下的pom.xml

根据上面需要的jar包添加如下maven依赖

<!--im驱动包-->
        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.50.Final</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
        <dependency>
            <groupId>com.rabbitmq</groupId>
            <artifactId>amqp-client</artifactId>
            <version>5.9.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.21</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.21</version>
        </dependency>

添加完依赖之后,我们在ruoyi-system下的包路径下新建imserver包,存放im相关的业务。

然后再新建sdk包,用来存放MobileIMSDK的sdk的源码

然后再新建config包,用来设置SpringBoot应用启动后启动IM的启动类

然后将IM的服务端的三个类复制过来

在这里插入图片描述
注意修改这三个类中import的路径问题,都要重新修改。

然后将MobileIMSDK的sdk_src源码下的server下的所有包和类全部复制到若依项目下sdk包下
在这里插入图片描述
在这里插入图片描述
然后打开sdk下的每一个类和接口,将原来的路径下的import全部去掉,然后重新导入为自己的路径
在这里插入图片描述
然后在imserver包下新建config包,包下新建类ChatServerRunner类

使其实现SpringBoot的CommandLineRunner接口并实现其run方法

那么run方法再SpringBoot服务启动后就会自动被调用

修改其代码为

package com.ruoyi.system.imserver.config;

import com.ruoyi.system.imserver.ServerLauncherImpl;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * <p> 启动MobileIMSDK服务端 </p>
 *
 * @author :
 * @description : run方法在SpringBoot服务启动之后会自动被调用
 * @date :
 */

@Component
@Order(value = 1)
public class ChatServerRunner implements CommandLineRunner {

    @Override
    public void run(String... strings) throws Exception {

        // 实例化后记得startup哦,单独startup()的目的是让调用者可以延迟决定何时真正启动IM服务
        final ServerLauncherImpl sli = new ServerLauncherImpl();
        // 启动MobileIMSDK服务端的Demo
        sli.startup();

        // 加一个钩子,确保在JVM退出时释放netty的资源
        Runtime.getRuntime().addShutdownHook(new Thread(sli::shutdown));
    }

}

然后找到ruoyi-system下的启动类RuoYiSystemApplication运行,运行成功后
在这里插入图片描述
就会发现将IM的服务也启动成功了。

为了验证可以使用官方的Java客户端去连接进行验证
在这里插入图片描述
在这里插入图片描述
就可以连接到我本地的im服务了
在这里插入图片描述

代码下载
https://download.csdn.net/download/qq_25987725/88157752

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cesske

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值