1

私はCassandraをデータベースとして使用するSpringブートプロジェクトを持っています。Cassandra MaxRequestsPerConnectionをSpringブートのプロパティファイルを使って追加するには

現在、私は自動配線でCassandraインスタンスを取得していますCassandraOperations

私の質問はです:私たちは、プロパティファイルを使用してMaxRequestsPerConnectionを設定するにはどうすればよい

# spring.data.cassandra.keyspace-name=event 
# spring.data.cassandra.contact-points=localhost 
# spring.data.cassandra.port=9042 

現在、私はプロパティファイルにこれらの性質を持っているが、私はすべてのプロパティの設定を提供していませんMaxRequestsPerConnection

答えて

2

春ブーツを設定するための任意のプロパティが見つかりませんでした。 ClusterBuilderCustomizer beanを定義してClusterインスタンスをカスタマイズすることができます。

@Configuration 
public class MyConfiguration { 

    @Bean 
    ClusterBuilderCustomizer clusterBuilderCustomizer(
      @Value("${spring.data.cassandra.pool.max-requests-local:10}") int local, 
      @Value("${spring.data.cassandra.pool.max-requests-remote:5}") int remote) { 

     PoolingOptions options = new PoolingOptions(); 

     options.setMaxRequestsPerConnection(HostDistance.LOCAL, local); 
     options.setMaxRequestsPerConnection(HostDistance.REMOTE, remote); 

     return builder -> builder.withPoolingOptions(options); 
    } 
} 

代替@Valueた:

プロパティファイルのプロパティを介して提供することができる注入取得カスタマBeanを宣言するために、次のコードを試してください(より一般的には、春の起動に使用可能な任意のプロパティのソースを話します) @ConfigurationPropertiesでアノテーションが付いています(プロパティ名の自動補完など)。

0

ステップ番号:1 ローカルとリモートのプールサイズを宣言する必要がありますサイズ値)

# spring.data.cassandra.keyspace-name=event 
# spring.data.cassandra.contact-points=localhost 
# spring.data.cassandra.port=9042 
# spring.data.cassandra.pool.max-requests-local:20 
# spring.data.cassandra.pool.max-requests-remote:10 

ステップいいえ:豆の設定で2

ClusterBuilderCustomizer @Bean(@value注釈を使用して)次のコードを使用して値を取得してください:

@Value("${spring.data.cassandra.pool.max-requests-local}") 
    private int localPool; 

    @Value("${spring.data.cassandra.pool.max-requests-remote}") 
    private int remotePool; 

このPoolingOptionsクラスを使用すると、ローカルとリモートのsetMaxRequestsPerConnectionsを設定します。

HostDistance.LOCAL -- localPool 
HostDistance.REMOTE -- remotePool 
関連する問題