Skip to content

Commit

Permalink
- change redis pool config
Browse files Browse the repository at this point in the history
 - reconnect to redis if connection to subscribe disconnected
  • Loading branch information
ritzalam committed Aug 23, 2015
1 parent a476d07 commit 0e2e79f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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);
Expand Down Expand Up @@ -40,7 +41,12 @@ public void start() {
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();
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down Expand Up @@ -68,9 +81,12 @@ public void run() {
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();
}

}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,19 @@ public void run() {
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;
}
}

private void processPong(KeepAlivePong msg) {
lastKeepAliveMessage = System.currentTimeMillis();
if (lastKeepAliveMessage != 0 && !available) {
log.error("BBB Web pubsub recovered!");
}

lastKeepAliveMessage = System.currentTimeMillis();
available = true;
}

Expand Down

0 comments on commit 0e2e79f

Please sign in to comment.