max_connections属性设置为0 (连接数不受限制),但 ems 服务器仍然继续将其吐出到 tibemsd.log
[admin:somehost]:连接失败:达到最大连接数 0
这怎么可能?
谢谢!
For anyone interested,
it appears that there is a limit of maximum 256 admin connections that can be open concurrently to the ems server. This limit is apparently not controlled by the max_connections property for some reason.
Here is a small example to verify this.
import com.tibco.tibjms.admin.TibjmsAdmin;
public class AdminConnectionTest{
public static void main(String args[}){
int counter =0;
try{
for(int i=0;i<1000;i++){
TibjmsAdmin admin = new TibjmsAdmin("tcp://localhost:7222","someuser","someuser");
counter++;
}
}catch(Exception e){
System.out.println( "Connections created: "+counter);
System.out.println( e.getMessage());
try{
Thread.sleep(20000); //Some delay to make it possible to verify this from emsadmin
}catch(Exception ee){System.out.println( ee.getMessage());}
}
}
}
为了保护客户端免受连接过载服务器的影响,我编写了一个简单的 commons pool2 类。
import com.tibco.tibjms.admin.TibjmsAdmin;
import com.tibco.tibjms.admin.TibjmsAdminException;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.DefaultPooledObject;
public class TibcoAdminPoolableObjectFactory implements PooledObjectFactory<TibjmsAdmin>{
@Override
public PooledObject<TibjmsAdmin> makeObject() throws Exception {
TibjmsAdmin admin = new TibjmsAdmin("tcp://tibco:7222","USER","password");
return new DefaultPooledObject<>(admin);
}
@Override
public void destroyObject(PooledObject<TibjmsAdmin> po) throws Exception {
po.getObject().close();
}
@Override
public boolean validateObject(PooledObject<TibjmsAdmin> po) {
try {
po.getObject().getQueue("xyzabc");
} catch (TibjmsAdminException ex) {
System.out.println(ex.getMessage());
return false;
}
return true;
}
@Override
public void activateObject(PooledObject<TibjmsAdmin> po) throws Exception {}
@Override
public void passivateObject(PooledObject<TibjmsAdmin> po) throws Exception {}
}
GenericObjectPool<TibjmsAdmin> pool = new GenericObjectPool<>(new TibcoAdminPoolableObjectFactory());
TibjmsAdmin admin = pool.borrowObject();
QueueInfo infos[] = admin.getQueues("YOURQUEUE");
pool.returnObject(admin);//in a finally block