Skip to content

Commit

Permalink
Update Cassandra reconnect policy and default delay value
Browse files Browse the repository at this point in the history
  • Loading branch information
yma96 committed Oct 15, 2024
1 parent bdb578f commit 91c403b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SocketOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.datastax.driver.core.policies.ConstantReconnectionPolicy;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -75,6 +76,8 @@ public void init()
socketOptions.setReadTimeoutMillis( config.getReadTimeoutMillis() );
Cluster.Builder builder = Cluster.builder()
.withoutJMXReporting()
.withReconnectionPolicy(
new ConstantReconnectionPolicy( config.getConstantDelayMs() ) )
.withRetryPolicy( new ConfigurableRetryPolicy( config.getReadRetries(),
config.getWriteRetries() ) )
.addContactPoint( host )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package org.commonjava.indy.service.tracking.data.cassandra;

import io.quarkus.runtime.Startup;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import java.util.Optional;

import static java.util.Optional.of;
Expand Down Expand Up @@ -65,6 +65,10 @@ public class CassandraConfiguration
@ConfigProperty( name = "cassandra.retries.write", defaultValue = "3" )
int writeRetries;

@Inject
@ConfigProperty( name = "cassandra.reconnect.delay", defaultValue = "60000" )
long constantDelayMs;

@Inject
@ConfigProperty( name = "cassandra.keyspace" )
Optional<String> keyspace;
Expand Down Expand Up @@ -167,6 +171,16 @@ public void setWriteRetries( int writeRetries )
this.writeRetries = writeRetries;
}

public long getConstantDelayMs()
{
return constantDelayMs;
}

public void setConstantDelayMs( long constantDelayMs )
{
this.constantDelayMs = constantDelayMs;
}

public String getKeyspace()
{
return keyspace.orElse( "" );
Expand Down

0 comments on commit 91c403b

Please sign in to comment.