Projects tigase _server server-core Issues #1448
How to make @ConfigField effective after class execute Constructor. (#1448)
Unknown opened 4 years ago

I have a problem with… I develop a component which using redis client Lettuce.The code is

package tigase.mucon.redis;

import io.lettuce.core.RedisURI;
import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
import tigase.kernel.beans.Bean;
import tigase.kernel.beans.Inject;
import tigase.kernel.beans.config.ConfigField;
import tigase.mucon.MujiComponent;
import tigase.mucon.bean.ConferenceInfo;
import tigase.xmpp.jid.JID;

import java.util.ArrayList;
import java.util.UUID;

@Bean(name = "redis-config", parent = MujiComponent.class, active = true)
public class RedisConfig {

    private ArrayList<RedisURI> list = new ArrayList<RedisURI>();

    @ConfigField(desc = "Redis hosts,split by ,", alias = "redis-hosts")
    protected String redisHosts = "redis://127.0.0.1:7001,redis://127.0.0.2:7001,redis://127.0.0.3:7001";

    @Inject
    private MujiComponent mujiComponent;

    private RedisClusterClient client;

    private StatefulRedisClusterConnection<String, String> connect;

    public RedisConfig() {
        String[] redisHosts = this.redisHosts.split(",");
        for(String redisHost : redisHosts){
            list.add(RedisURI.create(redisHost));
        }
        System.out.println(this.redisHosts);
    }

    public RedisClusterClient getClient() {
        return client;
    }

}

and the config.tdsl is

muji (class: tigase.mucon.MujiComponent) {
    'cache-middleware' = 'redis'
    'redis-config' (class: tigase.mucon.redis.RedisConfig) {
        'redis-hosts' = 'redis://10.64.3.21:7001,redis://10.64.3.22:7001,redis://10.64.3.23:7001'
    }
}

How to make the 'System.out.println(this.redisHosts);' print 'redis://10.64.3.21:7001,redis://10.64.3.22:7001,redis://10.64.3.23:7001' not 'redis://127.0.0.1:7001,redis://127.0.0.2:7001,redis://127.0.0.3:7001' in contructor of class RedisConfig.Or how to initialization the value RedisClusterClient client;

Details (please complete the following information):

  • Tigase version: [e.g. 8.1.2]
  • JVM flavour and version [e.g. JDK11]
  • Operating system/distribution/version [e.g. Linux Centos 7]
Unknown commented 4 years ago

I find that in development guide in 1.7.8,thanks

issue 1 of 1
Type
Question
Issue Votes (0)
Watchers (0)
Reference
tigase/_server/server-core#1448
Please wait...
Page is in error, reload to recover