- change redis pool config

- reconnect to redis if connection to subscribe disconnected
This commit is contained in:
Richard Alam 2015-08-23 04:56:30 -04:00
parent a476d073bb
commit 0e2e79fce8
4 changed files with 34 additions and 8 deletions

View File

@ -44,7 +44,7 @@ class AppsRedisSubscriberActor(val system: ActorSystem, msgReceiver: RedisMessag
def checkPongMessage() {
val now = System.currentTimeMillis()
if (lastPongReceivedOn != 0 && (now - lastPongReceivedOn > 10000)) {
if (lastPongReceivedOn != 0 && (now - lastPongReceivedOn > 30000)) {
log.error("FSESL pubsub error!");
}
}

View File

@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPubSub;
import redis.clients.jedis.exceptions.JedisConnectionException;
public class MessageReceiver {
private static Logger log = LoggerFactory.getLogger(MessageReceiver.class);
@ -40,7 +41,12 @@ public class MessageReceiver {
Runnable messageReceiver = new Runnable() {
public void run() {
if (receiveMessage) {
jedis.psubscribe(new PubSubListener(), MessagingConstants.FROM_BBB_APPS_PATTERN);
try {
jedis.psubscribe(new PubSubListener(), MessagingConstants.FROM_BBB_APPS_PATTERN);
} catch(JedisConnectionException ex) {
log.warn("Exception on Jedis connection. Resubscribing to pubsub.");
start();
}
}
}
};

View File

@ -26,12 +26,25 @@ public class MessageSender {
public void stop() {
sendMessage = false;
redisPool.destroy();
}
public void start() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(32);
config.setMaxIdle(8);
config.setMinIdle(1);
config.setTestOnBorrow(true);
config.setTestOnReturn(true);
config.setTestWhileIdle(true);
config.setNumTestsPerEvictionRun(12);
config.setMaxWaitMillis(5000);
config.setTimeBetweenEvictionRunsMillis(60000);
config.setBlockWhenExhausted(true);
// Set the name of this client to be able to distinguish when doing
// CLIENT LIST on redis-cli
redisPool = new JedisPool(new GenericObjectPoolConfig(), host, port, Protocol.DEFAULT_TIMEOUT, null,
redisPool = new JedisPool(config, host, port, Protocol.DEFAULT_TIMEOUT, null,
Protocol.DEFAULT_DATABASE, "BbbWebPub");
log.info("Redis message publisher starting!");
@ -68,9 +81,12 @@ public class MessageSender {
try {
jedis.publish(channel, message);
} catch(Exception e){
log.warn("Cannot publish the message to redis", e);
log.warn("Cannot publish the message to pubsub", e);
} finally {
jedis.close();
if (jedis != null) {
jedis.close();
}
}
}
};

View File

@ -135,7 +135,7 @@ public class KeepAliveService implements MessageListener {
private void processPing(KeepAlivePing msg) {
service.sendKeepAlive(SYSTEM, System.currentTimeMillis());
if (lastKeepAliveMessage != 0 && (System.currentTimeMillis() - lastKeepAliveMessage > 10000)) {
if (lastKeepAliveMessage != 0 && (System.currentTimeMillis() - lastKeepAliveMessage > 30000)) {
log.error("BBB Web pubsub error!");
// BBB-Apps has gone down. Mark it as unavailable. (ralam - april 29, 2014)
available = false;
@ -143,7 +143,11 @@ public class KeepAliveService implements MessageListener {
}
private void processPong(KeepAlivePong msg) {
lastKeepAliveMessage = System.currentTimeMillis();
if (lastKeepAliveMessage != 0 && !available) {
log.error("BBB Web pubsub recovered!");
}
lastKeepAliveMessage = System.currentTimeMillis();
available = true;
}