concurrency - How do i prevent Java from opening too many new RabbitMQ connections? -
i have put code in function,which used api ,to push message queue
private static connection connection; connectionfactory factory = new connectionfactory(); try { factory.setusername(username); factory.setpassword(password); factory.sethost(host); factory.setport(integer.parseint(portno)); factory.setconnectiontimeout(600000); factory.setrequestedheartbeat(30); // getting connection if (connection == null || !connection.isopen()) { connection = factory.newconnection(); } // creating channel channel = connection.createchannel(); channel.queuebind(queuename, "amq.direct", this.routingkey); return true; } catch (exception e) { logger.error("error connecting mq server.", e); try { connection.close(); } catch (ioexception e1) { // todo auto-generated catch block e1.printstacktrace(); }
when load test it, opening many connection if have tried using static connection tried setting heartbeat still dint work,what can prevent creating many connections. happening when code , rabbitmq on different servers
Comments
Post a Comment