Modify tigase configuration file
--cluster-mode = falseconfig-type = --gen-config-def--cluster-nodes = xumatoMacBook-Pro.local--debug = server,xmpp.impl,db,cluster--user-db = derby--admins = admin@xumatoMacBook-Pro.local--user-db-uri = jdbc:derby:/Applications/Tigase-5.1.4/tigasedb--virt-hosts = xumatoMacBook-Pro.local--comp-class-1 = tigase.muc.MUCComponent--comp-name-1 = muc--sm-plugins = +jabber:iq:auth,+urn:ietf:params:xml:ns:xmpp-sasl,+urn:ietf:params:xml:ns:xmpp-bind,+urn:ietf:params:xml:ns:xmpp-session,+jabber:iq:register,+jabber:iq:roster,+presence,+jabber:iq:privacy,+jabber:iq:version,+http://jabber.org/protocol/stats,+starttls,+msgoffline,+vcard-temp,+http://jabber.org/protocol/commands,+jabber:iq:private,+urn:xmpp:ping,+basic-filter,+domain-filter,+pep,-zlib--comp-name-2 = ext--comp-class-2 = tigase.server.ext.ComponentProtocol--external = guanfei.org:test:listen:5270:xumatoMacBook-Pro.local:accept:GuanfeiLB
Configure to enable port 5270, In the xep-0114's accept mode, wait for external component access, guanfeilb for custom load balance rules
--external = guanfei.org:test:listen:5270:xumatoMacBook-Pro.local:accept:GuanfeiLB
package tigase.server.ext.lb;import java.util.ArrayList;import tigase.server.Packet;import tigase.server.ext.ComponentConnection;import tigase.server.ext.ComponentIOService;/** * guanfei's lb * * @author guanfei * @created 2013-1-21 * * @version 1.0 */public class GuanfeiLB implements LoadBalancerIfc { static int i = 0; @Override public ComponentIOService selectConnection(Packet p, ArrayList<ComponentConnection> conns) { ComponentIOService result = null; int index = (++i) % 2; ComponentConnection conn = conns.get(index); if (conn.getService() != null && conn.getService().isConnected()) { result = conn.getService(); } return result; }}
Start tigase.
Compile external component, create a project, and add Dependencies
Write the component class, print the vertex information, and directly restore the information to the sender.
Package COM. guanfei. comp; import tigase. server. abstractmessagereceiver; import tigase. server. packet;/*** guanfei component ** @ author guanfei * @ created 2013-1-21 ** @ version 1.0 */public class guanfeicomponent extends {@ override public void processpacket (packet arg0) {system. out. println (arg0.getelemcdata (); If ("message" = arg0.getelemname () {system. out. println (arg0.getfrom (); system. out. println (arg0.getto (); packet result = arg0.swapelemfromto (); addoutpacket (result );}}}
Write the component configuration file, started in Comp mode, that is, started in component mode, and connected to tigase server in xep-0114
config-type = --gen-config-comp--debug = server--user-db = derby--admins = admin@guanfei.org--user-db-uri = jdbc:derby:/Applications/Tigase-5.1.4/tigasedbGuanfei;create=true--virt-hosts = guanfei.org--comp-name-1 = guanfei--comp-class-1 = com.guanfei.comp.GuanfeiComponent--external = guanfei.org:test:connect:5270:xumatoMacBook-Pro.local:accept
View the log output of tigase server after startup
2013-01-21 19:36:10 ConnectionManager$ConnectionListenerImpl.accept() FINEST: Accept called for service: null@null2013-01-21 19:36:10 ConnectionManager.serviceStarted() FINER: [[ext]] Connection started: null, type: accept, Socket: nullSocket[addr=/192.168.60.161,port=57141,localport=5270]2013-01-21 19:36:10 ComponentProtocol.serviceStarted() FINEST: Connection started: 192.168.60.161, xmlns: jabber:component:accept, type: accept, id=192.168.60.161_5270_192.168.60.161_571412013-01-21 19:36:10 ComponentProtocol.serviceStarted() FINEST: cid: null, sending: null2013-01-21 19:36:10 ComponentProtocol.xmppStreamOpened() FINEST: Stream opened: 192.168.60.161, xmlns: jabber:component:accept, type: accept, uniqueId=192.168.60.161_5270_192.168.60.161_57141, to=guanfei.org2013-01-21 19:36:10 ComponentProtocol.xmppStreamOpened() FINEST: tigase.server.ext.handlers.ComponentAcceptStreamOpenHandler is processing request2013-01-21 19:36:10 ComponentAcceptStreamOpenHandler.streamOpened() FINEST: CompRepoItem for guanfei.org set: guanfei.org:test:accept:5270:xumatoMacBook-Pro.local:accept:tigase.server.ext.lb.GuanfeiLB2013-01-21 19:36:10 ComponentAcceptStreamOpenHandler.streamOpened() FINEST: ID generated and set: e9c0ccd9-55a7-42d9-97df-903508945d8b2013-01-21 19:36:10 ComponentProtocol.xmppStreamOpened() FINEST: Sending back: <stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' from='guanfei.org' id='e9c0ccd9-55a7-42d9-97df-903508945d8b'>2013-01-21 19:36:10 ComponentProtocol.processSocketData() FINEST: Processing socket: null, type: accept, Socket: nullSocket[addr=/192.168.60.161,port=57141,localport=5270], data: null, type: accept, Socket: nullSocket[addr=/192.168.60.161,port=57141,localport=5270]2013-01-21 19:36:10 HandshakeProcessor.process() FINEST: Calculating digest: id=e9c0ccd9-55a7-42d9-97df-903508945d8b, secret=test, digest=3eb494154a8d65c99b348ba308797b53fd89330e2013-01-21 19:36:10 ComponentProtocol.updateRoutings() FINEST: All regex routings: [.*@guanfei.org, .*\.guanfei.org, guanfei.org]2013-01-21 19:36:10 ComponentProtocol.bindHostname() FINE: Authenticated: guanfei.org2013-01-21 19:36:10 BasicComponent.updateServiceDiscoveryItem() FINEST: Adding new item: <item name="ext-comp connected" jid="guanfei.org"/>2013-01-21 19:36:10 ComponentProtocol.addComponentConnection() FINER: A new component connection added for: guanfei.org2013-01-21 19:36:10 ConnectionManager.writePacketsToSocket() FINEST: null, type: accept, Socket: nullSocket[addr=/192.168.60.161,port=57141,localport=5270], Writing packet: from=null, to=null, DATA=
Verify the effect
The external component cluster starts a comp based on the same configuration, and the Server Load balancer runs according to the custom one.