本文所用的tigase是7.2.0-SNAPSHOT版本,此版本在init.properties的书写格式上与其他版本有很大区别。
1.下载tigase-message-archving组件
官方git下载地址:
git clone https://repository.tigase.org/git/message-archiving.git
2.数据库表的新建,这里需要用到如下两个建表脚本
mysql-unified-archive-schema-1.1.0.sql —该脚本在maven编译之后的tigase-server项目中的/database目录
mysql-message-archiving-schema-1.3.0.sql —该脚本在tigase-message-archving项目下的/database目录
3.增加tigase-message-archving组件的配置
在init.properties中添加:
message-archive(class: tigase.archive.MessageArchiveComponent, active:true){}
sess-man (class: tigase.server.xmppsession.SessionManager) {
message-archive-xep-0136(class: tigase.archive.processors.Xep0136MessageArchivingProcessor){
required-store-method = body
}
}
4.修改源码
tigase-message-archiving这个项目的MessageArchivePlugin.java:
将以下这段代码注释掉:
if (!settings.isAutoArchivingEnabled())
return;
这样就不需要客户端设置允许进行聊天记录的存储,只要客户端发送带有<body></body>
的消息均被服务端记录
到此为止,重启tigase-server,两个客户端发送消息,服务端将存储消息记录,存储的表为 tig_ma_msgs
5.客户端如何查看消息记录
客户端client1_Name@domain需要查询与client2_Name@domain之间的某一时段的聊天信息,start与end属性即所要拉取消息的时间段。需要发送以下packet:
<iq type="get" id="1234">
<retrieve xmlns='urn:xmpp:archive'
with='client2_Name@domain'
start='2017-04-24T07:00:00Z'
end='2017-04-24T23:00:00Z'>
</retrieve >
</iq>
在这期间遇到一个问题:
发送以上packet服务端没有任何信息返回给客户端:
经过debug与源码分析:发现自己写的一个Iq插件干扰了源码,需将其注释(在init.properties配置文件中注释以下):
sess-man (class: tigase.server.xmppsession.SessionManager) {
iqProcessPlugin (class: **.**.IqProcessPlugin, active: true) {}
}
packet处理流程 源码分析参考:
1. http://jianfulove.iteye.com/blog/2175750
2. http://jianfulove.iteye.com/blog/2173451
3. http://blog.csdn.net/hurryjiang/article/details/48026219
4. http://jianfulove.iteye.com/category/330546