tigase 安装及基本开发

2024-03-19 22:48
文章标签 安装 开发 基本 tigase

本文主要是介绍tigase 安装及基本开发,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

参考:http://docs.tigase.org/tigase-server/snapshot/Administration_Guide/html/#manualinstall

1.下载server的包(http://www.tigase.net/downloads)

2.解压tar -xzvf tigase-server-x.y.z-bv.tar.gz

3.chmod u+x ./scripts/tigase.sh

4.修改两个配置文件:tigase.conf和init.properties:

修改tigase.conf中的

JAVA_HOME="${JDKPath}"

JAVA_HOME="${JAVA_HOME}"

修改init.properties内容(下面是最基本的,后面根据需要添加):

config-type=--gen-config-def

--admins=admin@192.168.43.146

--virt-hosts = 192.168.43.146

--debug=server

--user-db=mysql

--user-db-uri=jdbc:mysql://localhost:3306/tigasedb?user=root&password=root&useUnicode=true&characterEncoding=UTF-8&autoCreateUser=true

5.初始化数据库(root/root为数据库账号密码):

./scripts/db-create-mysql.sh root root

6.启动tigase server:

./scripts/tigase.sh start etc/tigase.conf

7.通过查看日志来确认启动是否正常:

tail -f ./logs/tigase.log.0

之后就可以通过各种client(http://xmpp.org/software/clients.html),例如spark和psi等连接server

一些常见的问题:

1.如何进行扩展

只需要添加下面的一些maven依赖:

<dependencies>

<dependency>

<groupId>tigase</groupId>

<artifactId>tigase-server</artifactId>

<version>7.0.4</version>

</dependency>

<dependency>

<groupId>tigase</groupId>

<artifactId>tigase-message-archiving</artifactId>

<version>1.1.0</version>

</dependency>

<dependency>

<groupId>tigase</groupId>

<artifactId>tigase-muc</artifactId>

<version>2.3.0</version>

</dependency>

<dependency>

<groupId>tigase</groupId>

<artifactId>tigase-pubsub</artifactId>

<version>3.1.0</version>

</dependency>

<dependency>

<groupId>tigase</groupId>

<artifactId>tigase-xmltools</artifactId>

<version>3.4.5</version>

</dependency>

<dependency>

<groupId>tigase</groupId>

<artifactId>tigase-http-api</artifactId>

<version>1.1.1</version>

</dependency>

<dependency>

<groupId>tigase</groupId>

<artifactId>tigase-http-api-jetty</artifactId>

<version>1.0.0</version>

</dependency>

<dependency>

<groupId>tigase</groupId>

<artifactId>tigase-utils</artifactId>

<version>3.4.4</version>

</dependency>

</dependencies>

 

<repositories>

<repository>

<id>tigase</id>

<name>Tigase repository</name>

<url>http://maven.tigase.org</url>

</repository>

<repository>

<id>tigase-snapshot</id>

<name>Tigase repository</name>

<url>http://build.xmpp-test.net/maven/</url>

<snapshots>

<enabled>true</enabled>

</snapshots>

</repository>

</repositories>

 

然后我们就可以使用tigase相关的api,之后打成jar包放在tigase安装目录的jars目录下即可。

2.自定义的component如何发送packet:

通过tigase.server.AbstractMessageReceiver类的 boolean addOutPacket(Packet packet)方法即可

3.tigase好友关系在哪个表中维护?

在tig_pairs表

4.如何开启日志:

 

--debug=xmpp.impl.roster

开启tigase.xmpp.impl.roster包下面的类的日志

 

--debug-packages = com.tch.test.tigase.mytigase

开启我们自己的com.tch.test.tigase.mytigase包下面的类的日志

5.添加好友以及查看用户状态的时候,自动认证,无需对方同意,只需要添加下面的一个配置即可(参考:https://projects.tigase.org/issues/1696):

sess-man/plugins-conf/auto-authorize=true

6.如何在程序中添加用户:

调用存储过程 TigAddUserPlainPw,

java.sql.Connection.prepareStatement("{call TigAddUserPlainPw(?, ?)}");

第一个参数是user_id,第二个参数是密码

7.如何持久化聊天室(群聊,参考:https://projects.tigase.org/boards/8/topics/3456?r=5680):

--comp-name-2 = muc

--comp-class-2 = tigase.muc.MUCComponent

muc/default_room_config/muc#roomconfig_persistentroom=true

 

 

 

tigase init.properties一些配置的含义:

#支持群聊,并且默认就会保存群聊记录到muc_history表,但是默认是临时保存,当所有人离开之后,群就会不存在,群聊天记录也会删除,可以通过muc/default_room_config/muc#roomconfig_persistentroom=true来支持持久化(不配置这个component的话,不支持群聊)

--comp-name-2 = muc

--comp-class-2 = tigase.muc.MUCComponent

 

#支持消息存储(tig_ma_msgs表,不配置这个component的话,不会存储私聊消息)

--comp-name-3=message-archive

--comp-class-3=tigase.archive.MessageArchiveComponent

 

#消息存储的数据库配置,不配置这个参数的话,会使用--user-db-uri的数据库地址

message-archive/archive-repo-uri=jdbc:mysql://localhost:3306/messagearchivedb?user=root&password=root&useUnicode=true&characterEncoding=UTF-8

 

#指定消息存储的component

sess-man/plugins-conf/message-archive-xep-0136/component-jid=message-archive@192.168.43.146

#存储消息的方式(不配置这个参数的话,不会保存消息)

sess-man/plugins-conf/message-archive-xep-0136/required-store-method=message

 

#自动授权,配置这个参数之后,加好友的时候,不需要对方同意,自动添加成功

sess-man/plugins-conf/auto-authorize=true

#持久化群聊房间,不配置这个参数的话,所有人离开房间的时候,这个群就不存在了。

muc/default_room_config/muc#roomconfig_persistentroom=true

 

jaxmpp客户端:

添加仓库地址:

<repositories>

<repository>

<id>tigase</id>

<name>Tigase repository</name>

<url>http://maven.tigase.org</url>

</repository>

<repository>

<id>tigase-snapshot</id>

<name>Tigase repository</name>

<url>http://build.xmpp-test.net/maven/</url>

<snapshots>

<enabled>true</enabled>

</snapshots>

</repository>

</repositories>

 

添加依赖:

                 <dependency>

<groupId>tigase</groupId>

<artifactId>jaxmpp-core</artifactId>

<version>2.1.0</version>

</dependency>

<dependency>

<groupId>tigase</groupId>

<artifactId>jaxmpp-j2se</artifactId>

<version>2.1.0</version>

</dependency>

 

 

客户端代码:

 

import tigase.jaxmpp.core.client.BareJID;

import tigase.jaxmpp.core.client.JID;

import tigase.jaxmpp.core.client.SessionObject;

import tigase.jaxmpp.core.client.exceptions.JaxmppException;

import tigase.jaxmpp.core.client.observer.Listener;

import tigase.jaxmpp.core.client.xmpp.modules.presence.PresenceModule;

import tigase.jaxmpp.core.client.xmpp.modules.presence.PresenceModule.PresenceEvent;

import tigase.jaxmpp.core.client.xmpp.modules.roster.RosterItem;

import tigase.jaxmpp.core.client.xmpp.modules.roster.RosterStore;

import tigase.jaxmpp.core.client.xmpp.stanzas.Message;

import tigase.jaxmpp.core.client.xmpp.stanzas.Stanza;

import tigase.jaxmpp.core.client.xmpp.stanzas.StanzaType;

import tigase.jaxmpp.j2se.Jaxmpp;

 

public class JaxmppExample {

 

    public static void main( String[] args ) throws JaxmppException, InterruptedException {

 

        final Jaxmpp jaxmpp = new Jaxmpp();

        try {

jaxmpp.getModulesManager().getModule( PresenceModule.class ).addListener( PresenceModule.ContactChangedPresence, new Listener<PresenceModule.PresenceEvent>() {

   @Override

   public void handleEvent( PresenceEvent be ) throws JaxmppException {

       System.out.println( String.format( "Presence received:\t %1$s is now %2$s (%3$s)", be.getJid(), be.getShow(), be.getStatus() != null ? be.getStatus() : "none" ) );

   }

} );

jaxmpp.getSessionObject().setProperty(tigase.jaxmpp.j2se.connectors.socket.SocketConnector.HOSTNAME_VERIFIER_DISABLED_KEY, Boolean.TRUE);

jaxmpp.getProperties().setUserProperty( SessionObject.USER_BARE_JID, BareJID.bareJIDInstance( "richmj@192.168.43.146" ) );

jaxmpp.getProperties().setUserProperty( SessionObject.PASSWORD, "richmj" );

 

System.out.println("开始登陆。。。");

 

jaxmpp.login();

 

System.out.println("登陆成功。。。");

 

       RosterStore rosterStore = jaxmpp.getRoster();

       for(RosterItem rosterItem : rosterStore.getAll()){

       System.out.println("rosterItem:" + rosterItem);

       }

 

       jaxmpp.send(createMessage("admin,你好啊"));

//contact.sendMessage(JID.jidInstance("admin@192.168.43.146"), "Test", "This is a test");

 

} catch (Exception e) {

e.printStackTrace();

}finally {

if(jaxmpp != null){

jaxmpp.disconnect();

}

}

    }

    

    private static Stanza createMessage(String msg) {

try {

/*

<message id="pCp2F-58" to="richmj@192.168.43.146" from="admin@192.168.43.146/Spark" type="chat">

<body>1</body>

</message>

*/

Message message = Message.create();

message.setType(StanzaType.chat);

message.setAttribute("from", JID.jidInstance("richmj@192.168.43.146").toString());

message.setAttribute("to", JID.jidInstance("admin@192.168.43.146").toString());

message.setBody(msg);

System.out.println("message:" + message.getAsString());

return message;

} catch (JaxmppException e) {

e.printStackTrace();

}

return null;

}

    

}

 

 

 

 

 

 

 

 

 

 

这篇关于tigase 安装及基本开发的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/827479

相关文章

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

MySQL MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指

在Windows上使用qemu安装ubuntu24.04服务器的详细指南

《在Windows上使用qemu安装ubuntu24.04服务器的详细指南》本文介绍了在Windows上使用QEMU安装Ubuntu24.04的全流程:安装QEMU、准备ISO镜像、创建虚拟磁盘、配置... 目录1. 安装QEMU环境2. 准备Ubuntu 24.04镜像3. 启动QEMU安装Ubuntu4

mysql中insert into的基本用法和一些示例

《mysql中insertinto的基本用法和一些示例》INSERTINTO用于向MySQL表插入新行,支持单行/多行及部分列插入,下面给大家介绍mysql中insertinto的基本用法和一些示例... 目录基本语法插入单行数据插入多行数据插入部分列的数据插入默认值注意事项在mysql中,INSERT I

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

mapstruct中的@Mapper注解的基本用法

《mapstruct中的@Mapper注解的基本用法》在MapStruct中,@Mapper注解是核心注解之一,用于标记一个接口或抽象类为MapStruct的映射器(Mapper),本文给大家介绍ma... 目录1. 基本用法2. 常用属性3. 高级用法4. 注意事项5. 总结6. 编译异常处理在MapSt

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

使用Python开发一个现代化屏幕取色器

《使用Python开发一个现代化屏幕取色器》在UI设计、网页开发等场景中,颜色拾取是高频需求,:本文主要介绍如何使用Python开发一个现代化屏幕取色器,有需要的小伙伴可以参考一下... 目录一、项目概述二、核心功能解析2.1 实时颜色追踪2.2 智能颜色显示三、效果展示四、实现步骤详解4.1 环境配置4.

Nexus安装和启动的实现教程

《Nexus安装和启动的实现教程》:本文主要介绍Nexus安装和启动的实现教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Nexus下载二、Nexus安装和启动三、关闭Nexus总结一、Nexus下载官方下载链接:DownloadWindows系统根

MyBatis ResultMap 的基本用法示例详解

《MyBatisResultMap的基本用法示例详解》在MyBatis中,resultMap用于定义数据库查询结果到Java对象属性的映射关系,本文给大家介绍MyBatisResultMap的基本... 目录MyBATis 中的 resultMap1. resultMap 的基本语法2. 简单的 resul