我正在使用Firebase SDK Admin(Java)的服务。它曾经工作正常,直到我添加了一个Redis客户端(Jedis)来管理队列。自那次改变以来,我的firebase听众就停止了工作。我没有任何错误。
Firebase侦听器 - 适用于Java的Admin SDK
LOGGER.info("1. Se inicio la sesion de firebase.");
final FirebaseDatabase database = FirebaseDatabase.getInstance();
listenerRef = database.getReference(ENVIRONMENT);
DatabaseReference checkinRef = listenerRef.child(EFirebaseField.CHECKINS.getField());
DatabaseReference collectRef;
LOGGER.info("2. Carga de listeners de checkin para registro en base de datos.");
checkinRef.orderByChild(EFirebaseField.STATUS.getField())
.equalTo(EStatusFirebase.STARTED.getField())
.addChildEventListener(new ChildEventListener() {
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
LOGGER.debug("Se elimino un checkin STARTED: {} {}", dataSnapshot.getKey(),
dataSnapshot.getRef());
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String prevChildKey) {
LOGGER.debug("Se reubico un checkin STARTED: {} {}", dataSnapshot.getKey(),
dataSnapshot.getRef());
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String prevChildKey) {
LOGGER.debug("Se modifico un checkin STARTED: {} {}", dataSnapshot.getKey(),
dataSnapshot.getRef());
}
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String prevChildKey) {
LOGGER.info("A. Se agrego un nuevo checkin STARTED: {} {}", dataSnapshot.getKey(),
dataSnapshot.getRef());
firebaseActuators.processCheckin(dataSnapshot);
}
@Override
public void onCancelled(DatabaseError error) {
LOGGER.error("Ocurrio un error en checkin STARTED: {}", error.getMessage());
}
});
Redis客户端 - Jedis客户端
@Configuration
@PropertySource({"${propertiesDir:}/database-${envTarget:dev}.properties"})
public class RedisConfig {
private static final Logger LOGGER_REDIS = LogManager.getLogger(RedisConfig.class);
@Value("${redis.url}")
private String redisUrl;
@Value("${redis.port}")
private int redisPort;
@Value("${redis.pw}")
private String redisPw;
@Value("${redis.maxTotal}")
private int maxTotal;
@Value("${redis.maxIdle}")
private int maxIdle;
@Value("${redis.minIdle}")
private int minIdle;
@Value("${redis.ssl.trustStore}")
private String trustStore;
@Value("${redis.ssl.trustStoreType}")
private String trustStoreType;
@Value("${redis.ssl.trustStorePassword}")
private String trustStorePassword;
@Value("${redis.ssl.keyStore}")
private String keyStore;
@Value("${redis.ssl.keyStorePassword}")
private String keyStorePassword;
@Value("${redis.ssl.keyStoreType}")
private String keyStoreType;
@Bean
public RedisConnectionFactory connectionFactory() {
try {
System.setProperty("javax.net.ssl.trustStore", trustStore);
System.setProperty("javax.net.ssl.trustStoreType", trustStoreType);
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
System.setProperty("javax.net.ssl.keyStore", keyStore);
System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
System.setProperty("javax.net.ssl.keyStoreType", keyStoreType);
JedisConnectionFactory cf = new JedisConnectionFactory(jedisPoolConfig());
cf.setHostName(redisUrl);
cf.setPort(redisPort);
cf.setUseSsl(true);
cf.setUsePool(true);
cf.afterPropertiesSet();
return cf;
} catch (RedisConnectionFailureException e) {
LOGGER_REDIS.error("Error de conexion con Redis:" + e.getMessage(), e);
return null;
}
}
@Bean
public JedisPoolConfig jedisPoolConfig() {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(maxTotal);
jedisPoolConfig.setMaxIdle(maxIdle);
jedisPoolConfig.setMinIdle(minIdle);
jedisPoolConfig.setTestOnBorrow(true);
jedisPoolConfig.setTestOnReturn(true);
jedisPoolConfig.setTestWhileIdle(true);
jedisPoolConfig.setMinEvictableIdleTimeMillis(
Duration.ofSeconds(60).toMillis());
jedisPoolConfig.setTimeBetweenEvictionRunsMillis(
Duration.ofSeconds(30).toMillis());
jedisPoolConfig.setNumTestsPerEvictionRun(3);
jedisPoolConfig.setBlockWhenExhausted(true);
return jedisPoolConfig;
}
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
if (null == connectionFactory) {
LOGGER_REDIS.error("Redis template service is not available");
return null;
};
template.setConnectionFactory(connectionFactory);
template.afterPropertiesSet();
return template;
}
¿当我使用firebase监听器时,如果我有多种监听器,有什么问题吗? ¿或者,我的redis配置有问题吗?
答案 0 :(得分:0)
问题实际上不是Redis或Firebase,而是在System.setProperties上设置的Truststore。 Redis在JVM上设置信任,当Firebase尝试读取信任库时,识别Redis中的信任库。这就是你遇到问题的原因。要么是这样,要么您的Beans配置有问题。问候。