Spring Redisson Sentinel Error - At least two sentinels are required - java

I am using Sentinel mode for Redis. I am using Redisson Client version 3.9.1
<dependencies>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-data-20</artifactId>
<version>${redisson-version}</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${redisson-version}</version>
</dependency>
</dependencies>
The configuration of Sentinel using Redisson:
#EnableCaching
public class RedisCache {
#Autowired
private ObjectMapper objectMapper;
#Bean
public RedissonClient redissonClient() {
Config config = new Config();
config.setCodec(new JsonJacksonCodec(objectMapper));
config.useSentinelServers()
.setMasterName("redis-master")
.addSentinelAddress("redis://localhost:26378")
.addSentinelAddress("redis://localhost:26379");
return Redisson.create(config);
}
#Bean
public RedissonConnectionFactory redissonConnectionFactory(RedissonClient redisson) {
return new RedissonConnectionFactory(redisson);
}
}
I am running two sentinel servers and one Redis master with no slave.
This is just a setup on my local environment.
Output of some commands:
redis-cli -p 26379
127.0.0.1:26379> SENTINEL get-master-addr-by-name redis-master
1) "127.0.0.1"
2) "6379"
redis-cli -p 26378
127.0.0.1:26378> SENTINEL get-master-addr-by-name redis-master
1) "127.0.0.1"
2) "6379"
Whenever I am running my Spring Boot Application, I get the following error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redissonClient' defined in class path resource [xxxx/cache/impl/redis/config/RedisCache.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'redissonClient' threw exception; nested exception is org.redisson.client.RedisConnectionException: At least two sentinels should be defined in Redis configuration!
......
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:204)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType (ServletContextInitializerBeans.java:226)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType (ServletContextInitializerBeans.java:214)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans (ServletContextInitializerBeans.java:91)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init> (ServletContextInitializerBeans.java:80)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans (ServletWebServerApplicationContext.java:250)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize (ServletWebServerApplicationContext.java:237)
at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup (TomcatStarter.java:54)
at org.apache.catalina.core.StandardContext.startInternal (StandardContext.java:5245)
at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call (ContainerBase.java:1420)
at org.apache.catalina.core.ContainerBase$StartChild.call (ContainerBase.java:1410)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.566 s
[INFO] Finished at: 2018-12-07T13:44:14+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:run (default-cli) on project xxx: An exception occurred while running. null: InvocationTargetException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.redis.RedisHealthIndicatorConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redissonConnectionFactory' defined in class path resource [xxxxxxx/cache/impl/redis/config/RedisCache.class]: Unsatisfied dependency expressed through method 'redissonConnectionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redissonClient' defined in class path resource [xxxxxx/cache/impl/redis/config/RedisCache.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'redissonClient' threw exception; nested exception is org.redisson.client.RedisConnectionException: At least two sentinels should be defined in Redis configuration!
How do I resolve this error?
PS: I have tried master-slave configuration also, with one sentinel attached to the host and other one attached to the slave, but the error remains the same. I have tried sentinels running on different local machines with different private IPs, but the error remains the same.
Tried with 3 sentinel servers, no benefits.

Redisson doesn't seem to be working with localhost addresses. When I replaced the sentinel nodes addresses with the ones hosted on AWS, it worked fine.
Redisson, in my opinion, is a very immature client. Consider using lettuce or jedis.
See the bug filed at https://github.com/redisson/redisson/issues/1736
which doesn't allow it to shut down.
Most of the problems I faced were when I used the sentinel mode. Cluster mode I have not tried. Works fine in single mode.
Also, they don't cater to bugs or issues filed on github for months which is obvious as they have a pro and paid version, so you are on your own.
I won't recommend using Redisson as of now.

Redisson perfectly works with localhost addresses. In your case SENTINEL SENTINELS command returns empty result. Which means that Redis setup is not configured properly.

Make sure you run both redis-server as well as redis-sentinal <config>.
Once done, check which port sentinal is running at. It could also be 5000, it was in my case. Then pass "redis://localhost:5000" to addSentinelAddress.

Related

Spring boot BigQuery datasource connection

I am trying to connect BigQuery from Spring boot using Simba jdbc driver but I am getting below exception. Any input is appreciated. I am not sure why spring-boot is looking for a certifcate. I am able to connect with simple java main class, But I am getting this error with Spring boot only.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getDataSource' defined in class path resource [com/test/demo/services/config/DBConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.simba.googlebigquery.jdbc42.DataSource]: Factory method 'getDataSource' threw exception; nested exception is java.sql.SQLException: [Simba]BigQueryJDBCDriver HttpTransport IO error : PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.
DataSource ds = new com.simba.googlebigquery.jdbc42.DataSource();
Connection connection = null;
ds.setURL(
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=project)id;OAuthType=0;OAuthServiceAcctEmail=serviceAccountEmail;OAuthPvtKeyPath=p12CertPath;");
ds.setProjectId("projectId");
// ds.setOAuthType(0);
// connection = ds.getConnection();
connection = ds.getConnection();
Remove the extra spaces from your JDBC URL, it looks like they are interfering with mandatory OAuthPvtKeyPath, OAuthServiceAcctEmail parameters:
jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=<Your Project ID>;OAuthType=0;OAuthServiceAcctEmail=<Your Email>;OAuthPvtKeyPath=<Path To Cert>;

Disable #SqsListener for local environment

I have the following value configured in my SQS Listener in springboot. The queue is configured only for DEV and STAGE environments. So I want to disable it in my local after testing. How do i achieve that?
#SqsListener(value = { "${cloud.aws.endpoint}" } , deletionPolicy =SqsMessageDeletionPolicy.ON_SUCCESS)
public void processMessage(String message) throws Exception {
}
I tried to add the following to my application-local.xml(to keep it local), but it didn't work. Anyone went through the same scenario?
autoconfigure:
exclude:
- org.springframework.cloud.aws.autoconfigure.messaging.MessagingAutoConfiguration
- org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration
- org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
I am getting the following error everytime.
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stackResourceRegistryFactoryBean' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Unsatisfied dependency expressed through method 'stackResourceRegistryFactoryBean' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoDetectingStackNameProvider' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackNameProvider]: Factory method 'autoDetectingStackNameProvider' threw exception; nested exception is java.lang.IllegalArgumentException: No valid instance id defined
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:799) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
com.amazonaws.SdkClientException: Failed to connect to service endpoint:
at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:100) [aws-java-sdk-core-1.11.867.jar:na]
Caused by: java.net.ConnectException: Host is down (connect failed)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoDetectingStackNameProvider' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackNameProvider]: Factory method 'autoDetectingStackNameProvider' threw exception; nested exception is java.lang.IllegalArgumentException: No valid instance id defined
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.sprin
I've faced similar issues while using #SqsListener. What I usually do is comment out the annotation when running the app locally - it's ugly but it works.

Mongock and #Value annotation does not appear to work

I am trying to use the #Value annotation to grab the URI and database name while creating a SpringBootMongock object via SpringBootMongockBuilder and during mvn install it attempts to load the application context and fails because my Spring Contract tests cannot connect to the database in my application.yml file. Which I do not want while building my app anyways.
I have gotten around this by injecting the Environment object in my method signature but I don't understand why the #Value is not working. I have annotated the class with #Configuration which works fine.
Update: I still need to grab the URI from the yaml file to create my MongoClient using the #Bean annotation..
#Configuration
public class MongockConfiguration {
#Value(${spring.data.mongodb.uri})
private String uri;
#Bean
public MongoClient mongoClient(){
return MongoClients.create(uri);
}
#Bean
public SpringBootMongock mongock(Application context, Environment environment) throws Exception {
return new SpringBootMongockBuilder(mongoClient(), dbname, ChangeLogOne.class.getPackage().getName()).setEnabled(migrate).setApplicationContext(applicationContext).build();
}
some of the above values I pull from the Environment object as the #Value wasn't working for me .. no need to provide exact values here
exception is
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongock' defined in class path resource [blah/dht/mcs/registrationservice/config/MongockConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.SpringBootMongock]: Factory method 'mongock' threw exception; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='testUser', source='admin', password=<hidden>, mechanismProperties={}}
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.SpringBootMongock]: Factory method 'mongock' threw exception; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='testUser', source='admin', password=<hidden>, mechanismProperties={}}
Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='testUser', source='admin', password=<hidden>, mechanismProperties={}}
Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
and for the record with the values hardcoded vs using the #Value annotation everything works as expected.
The issue is not related to Mongock, but I see pretty clear that is due to MongoClient not being injected whenever you get the error.
As you mentioned it works when you provide the uri hardcoded, I was tempted to say that Spring doesn't find the spring.data.mongodb.uri, but if I am not wrong, it would fail saying that property is not found, rather than the error you are getting, as you are not providing a default value.
Anyway, it's something around there, for some reason, whenever you are running this and fails, the MongoClient is not added to the context for some reason.
I hope you find it useful.

Local Apache Spark on heroku

I have a problem running the apache spark in local mode on Heroku with Spring. My issue is:
#Configuration
public class SparkConfig {
private String master = "local";
#Bean
public JavaSparkContext javaSparkContext() {
SparkConf conf = new SparkConf().setAppName("local")
.setMaster(master);
return new JavaSparkContext(conf);
}
}
Error:
ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainController': Unsatisfied dependency expressed through field 'javaSparkContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'javaSparkContext' defined in class path resource [com/sensorservice/config/SparkConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.spark.api.java.JavaSparkContext]: Factory method 'javaSparkContext' threw exception; nested exception is java.lang.IllegalArgumentException: System memory 326631424 must be at least 471859200. Please increase heap size using the --driver-memory option or spark.driver.memory in Spark configuration.
I tried to modify the parameters Spark related to memory but this had no effect. It is possible to launch Spark free Heroku?

Elasticsearch Shield throws CreationException

I'm trying to set up a running service which uses Elasticsearch with Shield. However when I try to start the service I get the following error:
org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private java.util.List com.company.AppConfig.identConfigs;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'demoident' defined in URL [file:C:/path/to/config/foo.xml]:
Cannot resolve reference to bean 'bar_client' while setting bean property 'searchClients'
with key [TypedStringValue: value [default], target type [null]];
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'bar_client' defined in URL
[file:C:/path/to/config/foo.xml]: Bean instantiation via constructor failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.company.ElasticSearchClient]:
Constructor threw exception; nested exception is
org.elasticsearch.common.inject.CreationException: Guice creation errors:
1) A binding to org.elasticsearch.shield.transport.filter.IPFilter was already configured
at _unknown_. at _unknown_
2) A binding to org.elasticsearch.shield.transport.ClientTransportFilter was already configured
at _unknown_. at _unknown_
3) A binding to org.elasticsearch.shield.ssl.ClientSSLService was already configured
at _unknown_. at _unknown_
4) A binding to org.elasticsearch.shield.ssl.ServerSSLService was already configured
at _unknown_. at _unknown_
4 errors
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
(Sorry for the ugly formatting of stacktrace, feel free to edit for readability)
If I remove the Maven dependency for Elasticsearch Shield then the service starts as expected, without stacktraces, but obviously won't be able to execute any queries because of the exclusion of Shield.
Any help or input at all would be very appreciated.
Edit: I realized that the error is thrown by the Java client, not Elastic itself.

Categories