天天看点

Openfire集成实现方式

项目中涉及到消息推送,原来使用融云进行消息推送,现因业务需要,需要将推送改为openfire,和部门领导讨论后,暂定以下实现方案,整理备忘并救急于江湖:

一般的集成openfire方式,需要使用插件同步系统用户表到openfire表中,但在维护数据一致性上比较耗时耗力,并且容易出错.

一种简单的集成openfire的方法:

1.数据库表归并,将openfire的表结构和系统表共同放在系统数据库中.

2.为openfire指定数据源,不使用自己默认的数据源(没有做数据同步,默认的数据源为空),通过openfire后台管理界面,进行参数设置管理,部分参数页面上没体现,但openfire支持,可以直接在属性表中配置,配置完成后后台页面可以展现.

具体的配置语句见最后

3.配置完成后,在系统中创建一个超级admin角色,该角色只负责转发消息.系统中消息发送流程为:发送方通过http将发送内容发送后后台,后台对消息体进行封装,包括但不限于fromuser,touser,content..,将封装完成的json字符串传递给openfire(作为必需步骤,同时需要getboby,并设置目标用户信息,用于openfire信息发送),做为整个消息体发送给目标用户,目标用户拿到封装过的消息,再进行逐层解析,拿到所需信息后,在前端进行展示.

在整个过程中,openfire只作为消息发送通道,如果是群发消息,则获取所有合法的目标用户列表,循环进行发送.

发送消息类型:如果是发送图片/视频/语音等二进制文件,使用http上传下载完成所需功能.等文件完全下载到本地之后进行播放,比较方便.尽量不使用二进制流的方式进行发送,据说可以实现,但坑较多,容易摔倒起不来.

属性表配置信息:

INSERT INTO `ofproperty` VALUES ('admin.authorizedJIDs', '[email protected],[email protected]');
INSERT INTO `ofproperty` VALUES ('adminConsole.port', '9090');
INSERT INTO `ofproperty` VALUES ('adminConsole.securePort', '9091');
INSERT INTO `ofproperty` VALUES ('connectionProvider.className', 'org.jivesoftware.database.DefaultConnectionProvider');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.connectionTimeout', '1.0');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.driver', 'com.mysql.jdbc.Driver');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.maxConnections', '25');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.minConnections', '5');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.password', '0f046094355f69887c42124943c0a838332eee4c10a2554e');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.serverURL', 'jdbc:mysql://127.0.0.1:3306/xxxxxxxx?rewriteBatchedStatements=true');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.testAfterUse', 'false');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.testBeforeUse', 'false');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.testSQL', 'select 1');
INSERT INTO `ofproperty` VALUES ('database.defaultProvider.username', 'b0ce069d9073cb53ab3e236d304224c20ab2af3c0da7f864');
INSERT INTO `ofproperty` VALUES ('jdbcAuthProvider.passwordSQL', 'select password from t_user where account=?');
INSERT INTO `ofproperty` VALUES ('jdbcAuthProvider.passwordType', 'md5');
INSERT INTO `ofproperty` VALUES ('jdbcProvider.connectionString', 'jdbc:mysql://127.0.0.1:3306/xxxxxxxx?user=xxxxxxxx&password=xxxxxxxx');
INSERT INTO `ofproperty` VALUES ('jdbcProvider.driver', 'com.mysql.jdbc.Driver');
INSERT INTO `ofproperty` VALUES ('jdbcUserProvider.allUsersSQL', 'select account from t_user');
INSERT INTO `ofproperty` VALUES ('jdbcUserProvider.emailField', 'email');
INSERT INTO `ofproperty` VALUES ('jdbcUserProvider.loadUserSQL', 'select account,name,email from t_user where account=?');
INSERT INTO `ofproperty` VALUES ('jdbcUserProvider.nameField', 'name');
INSERT INTO `ofproperty` VALUES ('jdbcUserProvider.userCountSQL', 'select count(account) from t_user');
INSERT INTO `ofproperty` VALUES ('jdbcUserProvider.usernameField', 'account');
INSERT INTO `ofproperty` VALUES ('locale', 'zh_CN');
INSERT INTO `ofproperty` VALUES ('passwordKey', 'xxxxxxxx');
INSERT INTO `ofproperty` VALUES ('provider.admin.className', 'org.jivesoftware.openfire.admin.DefaultAdminProvider');
INSERT INTO `ofproperty` VALUES ('provider.auth.className', 'org.jivesoftware.openfire.auth.JDBCAuthProvider');
INSERT INTO `ofproperty` VALUES ('provider.group.className', 'org.jivesoftware.openfire.group.DefaultGroupProvider');
INSERT INTO `ofproperty` VALUES ('provider.lockout.className', 'org.jivesoftware.openfire.lockout.DefaultLockOutProvider');
INSERT INTO `ofproperty` VALUES ('provider.securityAudit.className', 'org.jivesoftware.openfire.security.DefaultSecurityAuditProvider');
INSERT INTO `ofproperty` VALUES ('provider.user.className', 'org.jivesoftware.openfire.user.JDBCUserProvider');
INSERT INTO `ofproperty` VALUES ('provider.vcard.className', 'org.jivesoftware.openfire.vcard.DefaultVCardProvider');
INSERT INTO `ofproperty` VALUES ('sasl.scram-sha-1.iteration-count', '4096');
INSERT INTO `ofproperty` VALUES ('setup', 'true');
INSERT INTO `ofproperty` VALUES ('stream.management.active', 'true');
INSERT INTO `ofproperty` VALUES ('stream.management.requestFrequency', '5');
INSERT INTO `ofproperty` VALUES ('update.lastCheck', '1472091380513');
INSERT INTO `ofproperty` VALUES ('xmpp.auth.anonymous', 'true');
INSERT INTO `ofproperty` VALUES ('xmpp.component.socket.port', '5275');
INSERT INTO `ofproperty` VALUES ('xmpp.domain', 'xxxxxxxx');
INSERT INTO `ofproperty` VALUES ('xmpp.jmx.enabled', 'false');
INSERT INTO `ofproperty` VALUES ('xmpp.jmx.port', '5099');
INSERT INTO `ofproperty` VALUES ('xmpp.jmx.secure', 'true');
INSERT INTO `ofproperty` VALUES ('xmpp.offline.quota', '102400');
INSERT INTO `ofproperty` VALUES ('xmpp.offline.type', 'store');
INSERT INTO `ofproperty` VALUES ('xmpp.server.socket.port', '5269');
INSERT INTO `ofproperty` VALUES ('xmpp.session.conflict-limit', '0');
INSERT INTO `ofproperty` VALUES ('xmpp.socket.plain.port', '5222');
INSERT INTO `ofproperty` VALUES ('xmpp.socket.ssl.active', 'true');
INSERT INTO `ofproperty` VALUES ('xmpp.socket.ssl.port', '5223');