Tigase插件
Tigase插件被SessionManager组件和C2S所加载。
新建一个maven项目,添加tigase-server依赖
1 2 3 4 5
| <dependency> <groupId>tigase</groupId> <artifactId>tigase-server</artifactId> <version>7.1.2</version> </dependency>
|
复制之前教程idea启动Tigase中的etc目录到该maven项目根目录下。
项目中创建java文件DemoPlugin
1 2 3 4 5 6 7 8 9 10 11 12
| @Id(DEMO) @Handles( @Handle(path = "message", xmlns = "jabber:client") ) public class DemoPlugin extends AnnotatedXMPPProcessor implements XMPPProcessorIfc { protected static final String DEMO = "DEMO";
@Override public void process(Packet packet, XMPPResourceConnection session, NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings) throws XMPPException { System.out.println("~~~~~~~" + packet.toString()); } }
|
AnnotatedXMPPProcessor表示可以通过注解配置插件。插件处理消息有:
- XMPPPreprocessorIfc - is the interface for packets pre-processing plugins.
- XMPPProcessorIfc - is the interface for packets processing plugins.
- XMPPPostprocessorIfc - is the interface for packets post-processing plugins.
- XMPPPacketFilterIfc - is the interface for processing results filtering.
process代码写习惯业务逻辑。注解表示该插件的唯一ID,以及需要处理指定的消息。
在配置文件init-mysql.properties中,添加–sm-plugins=+DEMO,如果已经有该配置,在后面添加+DEMO即可。这里+表示添加插件,默认为+,修改为-表示去除插件,可以在SessionManagerConfig类中查看默认加载的插件。
配置tigase.server.XMPPServer启动项目即可。