org.redisson.config.SubscriptionMode Java Examples

The following examples show how to use org.redisson.config.SubscriptionMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissonClusterConnectionTest.java    From redisson with Apache License 2.0 7 votes vote down vote up
@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();

    
    ClusterRunner clusterRunner = new ClusterRunner()
            .addNode(master1, slave1)
            .addNode(master2, slave2)
            .addNode(master3, slave3);
    process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setSubscriptionMode(SubscriptionMode.SLAVE)
    .setLoadBalancer(new RandomLoadBalancer())
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
 
Example #2
Source File: RedissonClusterConnectionTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();

    
    ClusterRunner clusterRunner = new ClusterRunner()
            .addNode(master1, slave1)
            .addNode(master2, slave2)
            .addNode(master3, slave3);
    process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setSubscriptionMode(SubscriptionMode.SLAVE)
    .setLoadBalancer(new RandomLoadBalancer())
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
 
Example #3
Source File: RedissonClusterConnectionTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();

    
    ClusterRunner clusterRunner = new ClusterRunner()
            .addNode(master1, slave1)
            .addNode(master2, slave2)
            .addNode(master3, slave3);
    process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setSubscriptionMode(SubscriptionMode.SLAVE)
    .setLoadBalancer(new RandomLoadBalancer())
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
 
Example #4
Source File: RedissonClusterConnectionTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();

    
    ClusterRunner clusterRunner = new ClusterRunner()
            .addNode(master1, slave1)
            .addNode(master2, slave2)
            .addNode(master3, slave3);
    process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setSubscriptionMode(SubscriptionMode.SLAVE)
    .setLoadBalancer(new RandomLoadBalancer())
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
 
Example #5
Source File: RedissonClusterConnectionTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();

    
    ClusterRunner clusterRunner = new ClusterRunner()
            .addNode(master1, slave1)
            .addNode(master2, slave2)
            .addNode(master3, slave3);
    process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setSubscriptionMode(SubscriptionMode.SLAVE)
    .setLoadBalancer(new RandomLoadBalancer())
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
 
Example #6
Source File: RedissonClusterConnectionTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();

    
    ClusterRunner clusterRunner = new ClusterRunner()
            .addNode(master1, slave1)
            .addNode(master2, slave2)
            .addNode(master3, slave3);
    process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setSubscriptionMode(SubscriptionMode.SLAVE)
    .setLoadBalancer(new RandomLoadBalancer())
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
 
Example #7
Source File: MasterSlaveEntry.java    From redisson with Apache License 2.0 5 votes vote down vote up
private RFuture<RedisClient> setupMasterEntry(RedisClient client) {
    RPromise<RedisClient> result = new RedissonPromise<RedisClient>();
    result.onComplete((res, e) -> {
        if (e != null) {
            client.shutdownAsync();
        }
    });
    RFuture<InetSocketAddress> addrFuture = client.resolveAddr();
    addrFuture.onComplete((res, e) -> {
        if (e != null) {
            result.tryFailure(e);
            return;
        }
        
        masterEntry = new ClientConnectionsEntry(
                client, 
                config.getMasterConnectionMinimumIdleSize(), 
                config.getMasterConnectionPoolSize(),
                config.getSubscriptionConnectionMinimumIdleSize(),
                config.getSubscriptionConnectionPoolSize(), 
                connectionManager,
                NodeType.MASTER);

        int counter = 1;
        if (config.getSubscriptionMode() == SubscriptionMode.MASTER) {
            counter++;
        }
        
        CountableListener<RedisClient> listener = new CountableListener<>(result, client, counter);
        RFuture<Void> writeFuture = writeConnectionPool.add(masterEntry);
        writeFuture.onComplete(listener);
        
        if (config.getSubscriptionMode() == SubscriptionMode.MASTER) {
            RFuture<Void> pubSubFuture = pubSubConnectionPool.add(masterEntry);
            pubSubFuture.onComplete(listener);
        }
    });
    
    return result;
}
 
Example #8
Source File: MasterSlaveEntry.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RFuture<RedisPubSubConnection> nextPubSubConnection() {
    if (config.getSubscriptionMode() == SubscriptionMode.MASTER) {
        return pubSubConnectionPool.get();
    }
    
    return slaveBalancer.nextPubSubConnection();
}
 
Example #9
Source File: MasterSlaveEntry.java    From redisson with Apache License 2.0 5 votes vote down vote up
public void returnPubSubConnection(PubSubConnectionEntry entry) {
    if (config.getSubscriptionMode() == SubscriptionMode.MASTER) {
        pubSubConnectionPool.returnConnection(masterEntry, entry.getConnection());
        return;
    }
    slaveBalancer.returnPubSubConnection(entry.getConnection());
}
 
Example #10
Source File: SingleConnectionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
private static MasterSlaveServersConfig create(SingleServerConfig cfg) {
    MasterSlaveServersConfig newconfig = new MasterSlaveServersConfig();
    
    newconfig.setPingConnectionInterval(cfg.getPingConnectionInterval());
    newconfig.setSslEnableEndpointIdentification(cfg.isSslEnableEndpointIdentification());
    newconfig.setSslProvider(cfg.getSslProvider());
    newconfig.setSslTruststore(cfg.getSslTruststore());
    newconfig.setSslTruststorePassword(cfg.getSslTruststorePassword());
    newconfig.setSslKeystore(cfg.getSslKeystore());
    newconfig.setSslKeystorePassword(cfg.getSslKeystorePassword());
    
    newconfig.setRetryAttempts(cfg.getRetryAttempts());
    newconfig.setRetryInterval(cfg.getRetryInterval());
    newconfig.setTimeout(cfg.getTimeout());
    newconfig.setPassword(cfg.getPassword());
    newconfig.setUsername(cfg.getUsername());
    newconfig.setDatabase(cfg.getDatabase());
    newconfig.setClientName(cfg.getClientName());
    newconfig.setMasterAddress(cfg.getAddress());
    newconfig.setMasterConnectionPoolSize(cfg.getConnectionPoolSize());
    newconfig.setSubscriptionsPerConnection(cfg.getSubscriptionsPerConnection());
    newconfig.setSubscriptionConnectionPoolSize(cfg.getSubscriptionConnectionPoolSize());
    newconfig.setConnectTimeout(cfg.getConnectTimeout());
    newconfig.setIdleConnectionTimeout(cfg.getIdleConnectionTimeout());
    newconfig.setDnsMonitoringInterval(cfg.getDnsMonitoringInterval());

    newconfig.setMasterConnectionMinimumIdleSize(cfg.getConnectionMinimumIdleSize());
    newconfig.setSubscriptionConnectionMinimumIdleSize(cfg.getSubscriptionConnectionMinimumIdleSize());
    newconfig.setReadMode(ReadMode.MASTER);
    newconfig.setSubscriptionMode(SubscriptionMode.MASTER);
    newconfig.setKeepAlive(cfg.isKeepAlive());
    
    return newconfig;
}
 
Example #11
Source File: MultipleServerConfig.java    From redisson-spring-boot-starter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public SubscriptionMode getSubscriptionMode() {
    return subscriptionMode;
}
 
Example #12
Source File: MultipleServerConfig.java    From redisson-spring-boot-starter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setSubscriptionMode(SubscriptionMode subscriptionMode) {
    this.subscriptionMode = subscriptionMode;
}
 
Example #13
Source File: RedissonClusterConfig.java    From game-server with MIT License 4 votes vote down vote up
public SubscriptionMode getSubscriptionMode() {
	return subscriptionMode;
}
 
Example #14
Source File: RedissonClusterConfig.java    From game-server with MIT License 4 votes vote down vote up
public void setSubscriptionMode(SubscriptionMode subscriptionMode) {
	this.subscriptionMode = subscriptionMode;
}