I watched video from Springone Platform and John Blum as speaker and interested try myself in Geode/Gemfire setup but with setup as described in Spring Data for Apache Geode Reference Guide
So i make spring boot geode client, locator and cache server using Eclipse, and i have problems when :
Start spring locator, start cache server, and start client with restcontroller so I can post my POJO TitleContent and get my list of TitleContent. Client give me exception Caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:7070/gemfire/v1/regions": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
Complete log :
2019-10-29 09:54:12.461 ERROR 58556 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'gemfireClusterSchemaObjectInitializer'; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:7070/gemfire/v1/regions": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at network.powerhouse.commercehost.CommerceHostGeodeApplication.main(CommerceHostGeodeApplication.java:51) [classes/:na]
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:7070/gemfire/v1/regions": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:751) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:644) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.data.gemfire.config.admin.remote.RestHttpGemfireAdminTemplate.createRegion(RestHttpGemfireAdminTemplate.java:267) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.data.gemfire.config.schema.definitions.RegionDefinition.create(RegionDefinition.java:125) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration$ClusterSchemaObjectInitializer.lambda$null$0(ClusterConfigurationConfiguration.java:403) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at java.base/java.util.Optional.ifPresent(Optional.java:172) ~[na:na]
at org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration$ClusterSchemaObjectInitializer.lambda$start$1(ClusterConfigurationConfiguration.java:402) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[na:na]
at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na]
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[na:na]
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) ~[na:na]
at org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration$ClusterSchemaObjectInitializer.start(ClusterConfigurationConfiguration.java:402) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
... 14 common frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:657) ~[na:na]
at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174) ~[na:na]
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182) ~[na:na]
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474) ~[na:na]
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569) ~[na:na]
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265) ~[na:na]
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372) ~[na:na]
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) ~[na:na]
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1181) ~[na:na]
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1075) ~[na:na]
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) ~[na:na]
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:163) ~[na:na]
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:742) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
... 31 common frames omitted
I remark #EnableClusterConfiguration(useHttp=true) and start Client again and now able to run. Now I give it a try with a POJO post to my restcontroller and get this exception :
2019-10-29 09:43:08.193 ERROR 57276 --- [io-15050-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: remote server on 192.168.100.8(SpringBasedCacheClientApplication:57276:loner):64494:51246215:SpringBasedCacheClientApplication: : While performing a remote put; nested exception is org.apache.geode.cache.client.ServerOperationException: remote server on 192.168.100.8(SpringBasedCacheClientApplication:57276:loner):64494:51246215:SpringBasedCacheClientApplication: : While performing a remote put] with root cause
org.apache.geode.cache.RegionDestroyedException: Server connection from [identity(192.168.100.8(SpringBasedCacheClientApplication:57276:loner):64494:51246215:SpringBasedCacheClientApplication,connection=1; port=64498]: Region named /TitleContent was not found during put request
at org.apache.geode.internal.cache.tier.sockets.BaseCommand.writeRegionDestroyedEx(BaseCommand.java:624) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.command.Put65.cmdExecute(Put65.java:185) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:183) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.ServerConnection.doNormalMessage(ServerConnection.java:851) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.OriginalServerConnection.doOneMessage(OriginalServerConnection.java:75) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1227) ~[geode-core-1.9.1.jar:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at org.apache.geode.internal.cache.tier.sockets.AcceptorImpl.lambda$initializeServerConnectionThreadPool$3(AcceptorImpl.java:616) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.logging.LoggingThreadFactory.lambda$newThread$0(LoggingThreadFactory.java:121) ~[geode-core-1.9.1.jar:na]
at java.base/java.lang.Thread.run(Thread.java:844) [na:na]
This time I un-remark //#EnableClusterConfiguration(useHttp=true) but I remove useHttp and just use #EnableClusterConfiguration, (I suspected error because of this). I stop Spring Client and start it again. Now it fails, and says : org.apache.geode.cache.RegionExistsException: /TitleContent.
The complete log :
Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'gemfireClusterSchemaObjectInitializer'; nested exception is org.apache.geode.cache.execute.FunctionException: org.apache.geode.cache.RegionExistsException: /TitleContent
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at network.powerhouse.commercehost.CommerceHostGeodeApplication.main(CommerceHostGeodeApplication.java:51) [classes/:na]
Caused by: org.apache.geode.cache.execute.FunctionException: org.apache.geode.cache.RegionExistsException: /TitleContent
at org.apache.geode.internal.cache.tier.sockets.command.ExecuteFunction66.cmdExecute(ExecuteFunction66.java:262) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.command.ExecuteFunction70.cmdExecute(ExecuteFunction70.java:66) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:183) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.ServerConnection.doNormalMessage(ServerConnection.java:851) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.OriginalServerConnection.doOneMessage(OriginalServerConnection.java:75) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1227) ~[geode-core-1.9.1.jar:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at org.apache.geode.internal.cache.tier.sockets.AcceptorImpl.lambda$initializeServerConnectionThreadPool$3(AcceptorImpl.java:616) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.logging.LoggingThreadFactory.lambda$newThread$0(LoggingThreadFactory.java:121) ~[geode-core-1.9.1.jar:na]
at java.base/java.lang.Thread.run(Thread.java:844) ~[na:na]
Caused by: org.apache.geode.cache.RegionExistsException: /TitleContent
at org.apache.geode.internal.cache.GemFireCacheImpl.createVMRegion(GemFireCacheImpl.java:2983) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.GemFireCacheImpl.basicCreateRegion(GemFireCacheImpl.java:2938) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.GemFireCacheImpl.createRegion(GemFireCacheImpl.java:2925) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.cache.RegionFactory.create(RegionFactory.java:755) ~[geode-core-1.9.1.jar:na]
at org.springframework.data.gemfire.config.admin.functions.CreateRegionFunction.createRegion(CreateRegionFunction.java:51) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:279) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.data.gemfire.function.PojoFunctionWrapper.invokeTargetMethod(PojoFunctionWrapper.java:176) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.data.gemfire.function.PojoFunctionWrapper.execute(PojoFunctionWrapper.java:155) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.apache.geode.internal.cache.tier.sockets.command.ExecuteFunction66.executeFunctionLocally(ExecuteFunction66.java:320) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.command.ExecuteFunction66.cmdExecute(ExecuteFunction66.java:250) ~[geode-core-1.9.1.jar:na]
... 10 common frames omitted
This time I remark again //#EnableClusterConfiguration and start Spring Client again. This time it runs and I give a try again with the same POJO. It success !
Complete log :
Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-10-29 10:04:04.477 INFO 59413 --- [io-15050-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-10-29 10:04:04.483 INFO 59413 --- [io-15050-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 6 ms
2019-10-29 10:04:04.598 INFO 59413 --- [io-15050-exec-1] o.a.geode.pdx.internal.TypeRegistry : Caching PdxType[dsid=0, typenum=12150516
name=network.powerhouse.commercehost.model.TitleContent
fields=[
id:Object:identity:0:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=-1
code:String:1:1:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=1
title:String:2:2:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=2
content:String:3:3:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=3]]
I try to get list of TitleContent with GET rest endpoint at the controller with success.
Now I shut down all of them and restart them all. And i try to get the list as in point 5 and give me exception as in the complete log :
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: remote server on 192.168.100.8(SpringBasedCacheClientApplication:59853:loner):49745:69bf7c15:SpringBasedCacheClientApplication: While performing a remote query; nested exception is org.apache.geode.cache.client.ServerOperationException: remote server on 192.168.100.8(SpringBasedCacheClientApplication:59853:loner):49745:69bf7c15:SpringBasedCacheClientApplication: While performing a remote query] with root cause
org.apache.geode.cache.query.RegionNotFoundException: Region not found: /TitleContent
at org.apache.geode.cache.query.internal.DefaultQuery.checkQueryOnPR(DefaultQuery.java:464) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:226) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.BaseCommandQuery.processQueryUsingParams(BaseCommandQuery.java:120) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.command.Query651.cmdExecute(Query651.java:135) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:183) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.ServerConnection.doNormalMessage(ServerConnection.java:851) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.OriginalServerConnection.doOneMessage(OriginalServerConnection.java:75) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1227) ~[geode-core-1.9.1.jar:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at org.apache.geode.internal.cache.tier.sockets.AcceptorImpl.lambda$initializeServerConnectionThreadPool$3(AcceptorImpl.java:616) ~[geode-core-1.9.1.jar:na]
at org.apache.geode.internal.logging.LoggingThreadFactory.lambda$newThread$0(LoggingThreadFactory.java:121) ~[geode-core-1.9.1.jar:na]
at java.base/java.lang.Thread.run(Thread.java:844) [na:na]
The Region looks like not persist to disk.
Questions :
At point 3 as exception was thrown, but definitely TitleContent region was created. But why exception is thrown?
Can somebody pinpoint what I missed, why #EnableClusterConfiguration behave strangely in my case and why Region is not persisted to disk (according to ref. manual, it should be persisted to disk by DEFAULT DiskStore at 7.12.7 ref. manual). I am sorry for such very long questions. I just couldn't make it shorter.
Thank you if somebody may be able to help, I really appreciate it.
The complete source code list:
SERVER :
#SpringBootApplication
#CacheServerApplication(locators="localhost[10334]", name="GeodeServerApplication" )
#EnableCacheServer(name="neptunus", autoStartup=true, hostnameForClients = "localhost", port = 48484)
//#EnableCachingDefinedRegions
//#EnableGemfireCaching
#EnablePdx
#EnableManager
#EnableHttpService
public class GeodeServerApplication {
public static void main(String[] args) {
SpringApplication.run(GeodeServerApplication.class, args);
}
}
LOCATOR :
#SpringBootApplication
#LocatorApplication(port = 10334)
public class GeodeLocatorApplication {
public static void main(String[] args) {
SpringApplication.run(GeodeLocatorApplication.class, args);
}
}
CLIENT :
#SpringBootApplication
#ClientCacheApplication(logLevel = "debug", locators = {#Locator(host = "localhost", port = 10334)})
#EnablePool(name="neptunusPool", servers=#Server(host="localhost", port=48484))
#EnableGemfireRepositories(basePackageClasses= {network.powerhouse.commercehost.repository.TitleContentRepository.class})
#EnableEntityDefinedRegions(basePackageClasses= {
network.powerhouse.commercehost.model.TitleContent.class
})
#ReplicateRegion
#EnableClusterDefinedRegions
#EnableCachingDefinedRegions
#EnableGemfireCaching
#EnableIndexing
//#EnableClusterConfiguration
#EnablePdx
public class CommerceHostGeodeApplication {
public static void main(String[] args) {
SpringApplication.run(CommerceHostGeodeApplication.class, args);
}
}
CLIENT CONTROLLER :
#RestController
public class TitleContentController {
#Autowired
TitleContentService service;
#PostMapping("/titlecontent")
TitleContent postTitleContent(#RequestBody TitleContent titleContent) {
return service.save(titleContent);
}
#GetMapping("titlecontent")
List<TitleContent> getTitleContentByCode(#RequestParam("code") String code){
return service.findByCode(code);
}
}
CLIENT REPOSITORY :
#Region("TitleContent")
public interface TitleContentRepository extends CrudRepository<TitleContent, Long> {
#Trace
List<TitleContent> findByCode(String code);
}
CLIENT SERVICE :
public interface TitleContentServiceInterface {
public TitleContent save(TitleContent titleContent);
public void delete(TitleContent titleContent);
public TitleContent findById(Long id);
List<TitleContent> findByCode(String code);
}
#Service
public class TitleContentService implements TitleContentServiceInterface{
#Autowired
TitleContentRepository repo;
#Override
public TitleContent save(TitleContent titleContent) {
return repo.save(titleContent);
}
#Override
public void delete(TitleContent titleContent) {
repo.delete(titleContent);
}
#Override
public TitleContent findById(Long id) {
return repo.findById(id).get();
}
#Override
public List<TitleContent> findByCode(String code) {
return repo.findByCode(code);
}
}
POJO :
#Region("TitleContent")
public class TitleContent {
#Id
private Long id;
#Indexed
private String code;
private String title;
private String content;
public TitleContent(Long id, String code, String title, String content) {
super();
this.id = id;
this.code = code;
this.title = title;
this.content = content;
}
public TitleContent() {
super();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
#Override
public String toString() {
return "TitleContent [id=" + id + ", code=" + code + ", title=" + title + ", content=" + content + "]";
}
}
DEPENDENCIES:
<dependency>
<groupId>org.springframework.geode</groupId>
<artifactId>spring-geode-starter</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>
SPRING BOOT VERSION:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
I finally found the way around this, after reading answer from John Blum several time from SpringData Gemfire DiskStore.
Definitely I couldn't use #EnableClusterConfiguration in my case (still wondering why). According to John, we are able to create Region using gfsh. From this I get an idea to do the same at Spring Boot CacheServer. So, how if I define my POJO at CacheServer and let annotation #EnableEntityDefinedRegions do the job to create the region at CacheServer side. Again I borrow
serverRegionShortcut = RegionShortcut.PARTITION_PERSISTENT
from John but I put it at
#EnableEntityDefinedRegions
Beside that I also need to persist my PDX type (Spring and/or Geode Gemfire do not like me if I am not persisting Pdx type at CacheServer side). So, I am using the same method to persist from SpringData Gemfire DiskStore but I implement it at CacheServer side with some additional entry at application.properties to tell spring to persist Pdx type as well.
In that way, I am able to successfully create and persisting Region at CacheServer side and also persisting Pdx as well.
Here is the complete code and application.properties I made with borrowing the idea from SpringData Gemfire DiskStore.
I appreciate if anybody able to tell me whether this work around is a good way to do or is there any other way or any better idea (still wondering though why #EnableClusterConfiguration doesn't like me while anybody else has no problem with it :=(, so if there is anybody who is able to tell me where is(are) my mistake(s) I really appreciate it ).
CLIENT :
#SpringBootApplication
#ClientCacheApplication(logLevel = "debug", locators = {#Locator(host = "localhost", port = 10334)})
#EnablePool(name="neptunusPool", servers=#Server(host="localhost", port=41414))
#EnableGemfireRepositories(basePackageClasses= {TitleContentRepository.class})
#EnableEntityDefinedRegions(basePackageClasses= {TitleContent.class
})
//#ReplicateRegion
//#EnableClusterDefinedRegions
//#EnableCachingDefinedRegions
//#EnableGemfireCaching
#EnableIndexing
//#EnableClusterConfiguration
#EnablePdx
public class CommerceHostGeodeApplication {
public static void main(String[] args) {
SpringApplication.run(CommerceHostGeodeApplication.class, args);
}
}
At client side the same POJO, Repository and RestController and nothing in application.properties except for server.port definition.
CACHESERVER :
#SpringBootApplication
#CacheServerApplication(locators="localhost[10334]", name="GeodeServerApplication" )
#EnableCacheServer(name="neptunus", autoStartup=true, hostnameForClients = "localhost", port = 41414)
#EnableCachingDefinedRegions
#EnableGemfireCaching
#EnablePdx
#EnableManager
#EnableHttpService
#EnableDiskStore(name = "disk_store")
#EnableEntityDefinedRegions(basePackageClasses= {TitleContent.class
}, serverRegionShortcut = RegionShortcut.PARTITION_PERSISTENT)
public class GeodeServerApplication {
public static void main(String[] args) {
SpringApplication.run(GeodeServerApplication.class, args);
}
}
CACHESERVER application.properties :
server.port=15010
spring.data.gemfire.disk.store.name=disk_store
spring.data.gemfire.disk.store.directory.location=/Users/ars/geode/data
spring.data.gemfire.pdx.disk-store-name=disk_store
spring.data.gemfire.pdx.persistent=true
spring.data.gemfire.management.use-http=true
Upon CacheServer start, region is created and is able to persist / save to disk.
Related
For simplicity, I have created a
RestController which throws an exception
ErrorController, which returns a basic json string
What I am wondering is:
Is there an approach to prevent the stack-trace from being logged by dispatcherServlet since it will be handled inside the ErrorController?
MyRestController.java:
#RestController
#RequestMapping("test")
public class MyRestController {
#GetMapping("/")
public String get() {
throw new RuntimeException("Oops");
}
}
SpringErrorController.java:
#RestController
public class SpringErrorController implements ErrorController {
#RequestMapping("/error")
public String handleError(HttpServletRequest request, HttpServletResponse response)
throws Exception {
Exception exception = (Exception) request.getAttribute(attribute);
if (exception != null) {
// do things ..
}
return "{\"field\": \"value\"}";
}
}
Error in logs:
2022-06-22 16:15:11.074 ERROR 23815 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Oops] with root cause
java.lang.RuntimeException: Oops
at com.example.demo.MyRestController.get(MyRestController.java:14) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.20.jar:5.3.20]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.20.jar:5.3.20]
I am using the Calimero library to try and connect to my KNX system. The stack trace that keeps coming up is this:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'knxNetworkLink' defined in class path resource [io/symphony/knx/config/KnxConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [tuwien.auto.calimero.link.KNXNetworkLink]: Factory method 'knxNetworkLink' threw exception; nested exception is tuwien.auto.calimero.KNXException: connecting 127.0.1.1:41243 10.0.1.223:3671 (bound)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:774) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:339) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329) ~[spring-boot-2.4.5.jar:2.4.5]
at io.symphony.knx.Application.main(Application.java:12) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.5.jar:2.4.5]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [tuwien.auto.calimero.link.KNXNetworkLink]: Factory method 'knxNetworkLink' threw exception; nested exception is tuwien.auto.calimero.KNXException: connecting 127.0.1.1:41243 10.0.1.223:3671 (bound)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.6.jar:5.3.6]
... 25 common frames omitted
Caused by: tuwien.auto.calimero.KNXException: connecting 127.0.1.1:41243 10.0.1.223:3671 (bound)
at tuwien.auto.calimero.knxnetip.ClientConnection.connect(ClientConnection.java:134) ~[calimero-core-2.5-M1.jar:na]
at tuwien.auto.calimero.knxnetip.KNXnetIPTunnel.<init>(KNXnetIPTunnel.java:193) ~[calimero-core-2.5-M1.jar:na]
at tuwien.auto.calimero.knxnetip.KNXnetIPTunnel.newTcpTunnel(KNXnetIPTunnel.java:139) ~[calimero-core-2.5-M1.jar:na]
at tuwien.auto.calimero.link.KNXNetworkLinkIP.newTunnelingLink(KNXNetworkLinkIP.java:158) ~[calimero-core-2.5-M1.jar:na]
at io.symphony.knx.config.KnxConfig.knxNetworkLink(KnxConfig.java:43) ~[classes/:na]
at io.symphony.knx.config.KnxConfig$$EnhancerBySpringCGLIB$$9e2e5d48.CGLIB$knxNetworkLink$0(<generated>) ~[classes/:na]
at io.symphony.knx.config.KnxConfig$$EnhancerBySpringCGLIB$$9e2e5d48$$FastClassBySpringCGLIB$$9c2d5c1c.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.6.jar:5.3.6]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.6.jar:5.3.6]
at io.symphony.knx.config.KnxConfig$$EnhancerBySpringCGLIB$$9e2e5d48.knxNetworkLink(<generated>) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.6.jar:5.3.6]
... 26 common frames omitted
Caused by: java.net.SocketException: Invalid argument
at java.base/sun.nio.ch.Net.connect0(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.connect(Net.java:574) ~[na:na]
at java.base/sun.nio.ch.Net.connect(Net.java:563) ~[na:na]
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:648) ~[na:na]
at tuwien.auto.calimero.knxnetip.Connection.connect(Connection.java:719) ~[calimero-core-2.5-M1.jar:na]
at tuwien.auto.calimero.knxnetip.ClientConnection.connect(ClientConnection.java:129) ~[calimero-core-2.5-M1.jar:na]
... 40 common frames omitted
Something is an "invalid argument" but I don't understand what might be the problem. The code below is what I use: It's based on Springboot and I configure the connection via the application.yaml. Those values (only one in this case) get mapped into the KnxProperties object which I use further down to set up the KNXNetworkLinx bean.
application.yaml
knx:
connection:
remoteAddress: 10.0.1.223
#Configuration
#ConfigurationProperties(prefix = "knx")
#Getter #Setter
public class KnxProperties {
private Connection connection;
#Configuration
#Getter #Setter
public static class Connection {
private String remoteAddress;
private Integer remotePort = 3671;
private String localAddress = null;
private Integer localPort = 0;
}
}
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Set;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tuwien.auto.calimero.IndividualAddress;
import tuwien.auto.calimero.KNXException;
import tuwien.auto.calimero.knxnetip.Connection;
import tuwien.auto.calimero.link.KNXLinkClosedException;
import tuwien.auto.calimero.link.KNXNetworkLink;
import tuwien.auto.calimero.link.KNXNetworkLinkIP;
import tuwien.auto.calimero.link.medium.KNXMediumSettings;
import tuwien.auto.calimero.process.ProcessCommunicator;
import tuwien.auto.calimero.process.ProcessCommunicatorImpl;
import tuwien.auto.calimero.process.ProcessListener;
#Configuration
public class KnxConfig {
#Bean
public KNXNetworkLink knxNetworkLink(KnxProperties config) throws KNXException, InterruptedException, UnknownHostException {
// Remote Socket
String remoteAddr = config.getConnection().getRemoteAddress();
InetAddress remoteInetAddr = InetAddress.getByName(remoteAddr);
int remotePort = config.getConnection().getRemotePort();
InetSocketAddress remote = new InetSocketAddress(remoteInetAddr, remotePort);
// Local Socket
int localPort = config.getConnection().getLocalPort();
InetSocketAddress local = new InetSocketAddress(localPort);
if (config.getConnection().getLocalAddress() != null) {
local = new InetSocketAddress(config.getConnection().getLocalAddress(), localPort);
}
// Setup connection to KNX
Connection conn = Connection.newTcpConnection(local, remote);
KNXMediumSettings settings = KNXMediumSettings.create(KNXMediumSettings.MEDIUM_TP1, new IndividualAddress("1.1.1"));
KNXNetworkLink link = KNXNetworkLinkIP.newTunnelingLink(conn, settings);
return link;
}
#Bean
public ProcessCommunicator processCommunicator(KNXNetworkLink link, Set<ProcessListener> listeners) throws KNXLinkClosedException {
ProcessCommunicator comm = new ProcessCommunicatorImpl(link);
listeners.forEach(l -> comm.addProcessListener(l));
return comm;
}
}
I am using redis cache in my springboot application. Suddently it sarted giving the below exception:
ERROR 1876 --- [http-nio-8004-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: java.io.IOException: An existing connection was forcibly closed by the remote host] with root cause
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method) ~[na:1.8.0_261]
at sun.nio.ch.SocketDispatcher.read(Unknown Source) ~[na:1.8.0_261]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) ~[na:1.8.0_261]
at sun.nio.ch.IOUtil.read(Unknown Source) ~[na:1.8.0_261]
at sun.nio.ch.SocketChannelImpl.read(Unknown Source) ~[na:1.8.0_261]
at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253) ~[netty-buffer-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133) ~[netty-buffer-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_261]
This is my redis configuration:
#Configuration
public class RedisConfig {
#Autowired
private Environment environment;
#Bean
public LettuceConnectionFactory redisConnectionFactory(){
return new LettuceConnectionFactory(new RedisStandaloneConfiguration(Objects.requireNonNull(
environment.getProperty("redis.hostname")), Integer.parseInt(Objects.requireNonNull(
environment.getProperty("redis.port")))));
}
}
Can anyone please help me to resolve the issue?
I meet the same question. then find some function
1: it work for me
lettuce:
cluster:
refresh:
adaptive: true
period: 20
2: change server ssh config ,add the fllow contnet, can't work for me
ClientAliveInterval 600
ClientAliveCountMax 10
3: change the redis conf ,set tcp-keepalive value bettwen 1 and 50,I can't try.
I also not think is a good idea.
4: update the redis version
5: use jedis pool
6: use regular task to keep netty link
#Component
#Slf4j
public class LettuceConnectionValidTask {
#Autowired
private RedisConnectionFactory redisConnectionFactory;
#Scheduled(cron="0/2 * * * * ?")
public void task() {
if(redisConnectionFactory instanceof LettuceConnectionFactory){
LettuceConnectionFactory c=(LettuceConnectionFactory)redisConnectionFactory;
c.validateConnection();
}
}
}
7: trun on connect validate
#Component
#Slf4j
public class LettuceConnectionValidConfig implements InitializingBean {
#Autowired
private RedisConnectionFactory redisConnectionFactory;
#Override
public void afterPropertiesSet() throws Exception {
if(redisConnectionFactory instanceof LettuceConnectionFactory){
LettuceConnectionFactory c=(LettuceConnectionFactory)redisConnectionFactory;
c.setValidateConnection(true);
}
}
}
I get the following error whenever trying to run my spring boot Kafka application.
2020-08-04 20:17:23.366 ERROR 2827 --- [ main] o.springframework.kafka.core.KafkaAdmin : Could not create admin
org.apache.kafka.common.KafkaException: Failed to create new KafkaAdminClient
at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:479) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.admin.Admin.create(Admin.java:71) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.admin.AdminClient.create(AdminClient.java:49) ~[kafka-clients-2.5.0.jar:na]
at org.springframework.kafka.core.KafkaAdmin.initialize(KafkaAdmin.java:177) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.kafka.core.KafkaAdmin.afterSingletonsInstantiated(KafkaAdmin.java:157) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:910) [spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at ai.kollie.kafka.KafkaApplication.main(KafkaApplication.java:19) [main/:na]
Caused by: org.apache.kafka.common.config.ConfigException: Invalid url in bootstrap.servers: ${spring.kafka.bootstrap-servers
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:59) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:48) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:439) ~[kafka-clients-2.5.0.jar:na]
... 15 common frames omitted
Now, I have used spring.kafka.bootstrap-servers to set the server to localhost:9092 and following are my producer, consumer and topic configuration files respectively.
#Configuration
public class KafkaProducerConfig {
#Value(value = "${spring.kafka.bootstrap-servers}")
private String bootstrapAddress;
#EnableKafka
#Configuration
public class KafkaConsumerConfig {
#Value(value = "${spring.kafka.bootstrap-servers}")
private String bootstrapAddress;
#Configuration
public class KafkaTopicConfig {
#Value(value = "${spring.kafka.bootstrap-servers")
private String bootstrapAddress;
#Bean
public KafkaAdmin kafkaAdmin() {
Map<String, Object> configs = new HashMap<>();
configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
...
Am I doing something wrong or overlooking something?
Update:
The previous error is resolved. Although, now I'm facing the following issue.
2020-08-06 01:30:02.895 INFO 4090 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka version: 2.5.0
2020-08-06 01:30:02.897 INFO 4090 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: 66563e712b0b9f84
2020-08-06 01:30:02.897 INFO 4090 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1596657602893
2020-08-06 01:30:32.934 ERROR 4090 --- [ main] o.springframework.kafka.core.KafkaAdmin : Could not configure topics
org.springframework.kafka.KafkaException: Timed out waiting to get existing topics; nested exception is java.util.concurrent.TimeoutException
at org.springframework.kafka.core.KafkaAdmin.lambda$checkPartitions$4(KafkaAdmin.java:254) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at java.base/java.util.HashMap.forEach(HashMap.java:1341) ~[na:na]
at org.springframework.kafka.core.KafkaAdmin.checkPartitions(KafkaAdmin.java:233) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.kafka.core.KafkaAdmin.addTopicsIfNeeded(KafkaAdmin.java:219) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.kafka.core.KafkaAdmin.initialize(KafkaAdmin.java:189) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.kafka.core.KafkaAdmin.afterSingletonsInstantiated(KafkaAdmin.java:157) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:910) [spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at ai.kollie.kafka.KafkaApplication.main(KafkaApplication.java:19) [main/:na]
Caused by: java.util.concurrent.TimeoutException: null
at org.apache.kafka.common.internals.KafkaFutureImpl$SingleWaiter.await(KafkaFutureImpl.java:108) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:272) ~[kafka-clients-2.5.0.jar:na]
at org.springframework.kafka.core.KafkaAdmin.lambda$checkPartitions$4(KafkaAdmin.java:236) [spring-kafka-2.5.2.RELEASE.jar:2.5.2.RELEASE]
... 16 common frames omitted
I have the created the topics that the application is using by creating NewTopic beans as follows:
#Bean
public NewTopic userTestTopic() {
return TopicBuilder.name("test-user")
.partitions(1)
.replicas(3)
.build();
}
#Bean
public NewTopic employeeTestTopic() {
return TopicBuilder.name("test-employee")
.partitions(1)
.replicas(3)
.build();
}
Both the sides could communicate before despite of the previous error but cannot now. The terminal just lists out all the configs and stops, saying Close timed out with 1 pending requests to coordinator, terminating client connections. How do I resolve this?
Caused by: org.apache.kafka.common.config.ConfigException: Invalid url in bootstrap.servers: ${spring.kafka.bootstrap-servers
You are missing the closing }.
#Value(value = "${spring.kafka.bootstrap-servers")
private String bootstrapAddress;
I am trying to listen to messages coming through a Tibco topic in my spring boot application. My config looks like this -
#Configuration
#EnableJms
public class TibcoConfig {
#Bean
public ConnectionFactory connectionFactory() {
TopicConnectionFactory factory = new TibjmsTopicConnectionFactory("TIBCO_BROKER_URL");
return factory;
}
#Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setClientId("client1");
factory.setPubSubDomain(true);
factory.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
return factory;
}
#Bean
public UserCredentialsConnectionFactoryAdapter authenticationConnectionFactory() {
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter();
userCredentialsConnectionFactoryAdapter.setTargetConnectionFactory(connectionFactory());
userCredentialsConnectionFactoryAdapter.setUsername("USERNAME");
userCredentialsConnectionFactoryAdapter.setPassword("PASSWORD");
return userCredentialsConnectionFactoryAdapter;
}
}
And my listener looks like this -
#Component
public class TibcoRequestListener {
#JmsListener(destination = "TIBCO_TOPIC_NAME", containerFactory = "jmsListenerContainerFactory")
public void receiveMessage(Message message) {
try {
TextMessage txtMsg = (TextMessage) message;
System.out.println("Received response: " + txtMsg.getText());
System.out.println("Message type: " + message.getJMSType());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Error log -
2020-07-08 18:28:37.711 WARN 3552 --- [)-10.110.74.130] o.s.boot.actuate.jms.JmsHealthIndicator : JMS health check failed
javax.jms.JMSSecurityException: authentication failed
at com.tibco.tibjms.Tibjmsx.buildException(Tibjmsx.java:575) ~[tibjms-5.1.0.jar:5.1.0]
at com.tibco.tibjms.TibjmsConnection._create(TibjmsConnection.java:1330) ~[tibjms-5.1.0.jar:5.1.0]
at com.tibco.tibjms.TibjmsConnection.<init>(TibjmsConnection.java:4115) ~[tibjms-5.1.0.jar:5.1.0]
at com.tibco.tibjms.TibjmsTopicConnection.<init>(TibjmsTopicConnection.java:36) ~[tibjms-5.1.0.jar:5.1.0]
at com.tibco.tibjms.TibjmsxCFImpl._createImpl(TibjmsxCFImpl.java:191) ~[tibjms-5.1.0.jar:5.1.0]
at com.tibco.tibjms.TibjmsxCFImpl._createConnection(TibjmsxCFImpl.java:253) ~[tibjms-5.1.0.jar:5.1.0]
at com.tibco.tibjms.TibjmsConnectionFactory.createConnection(TibjmsConnectionFactory.java:36) ~[tibjms-5.1.0.jar:5.1.0]
at org.springframework.boot.actuate.jms.JmsHealthIndicator.doHealthCheck(JmsHealthIndicator.java:52) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:82) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthIndicator.getHealth(HealthIndicator.java:37) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpoint.getHealth(HealthEndpoint.java:81) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpoint.getHealth(HealthEndpoint.java:38) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:108) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpointSupport.getAggregateHealth(HealthEndpointSupport.java:119) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:105) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpointSupport.getAggregateHealth(HealthEndpointSupport.java:119) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:105) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:83) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:70) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:75) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:65) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) ~[spring-core-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:77) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:60) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:121) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:96) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809) ~[na:na]
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[na:na]
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466) ~[na:na]
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307) ~[na:na]
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399) ~[na:na]
at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827) ~[na:na]
at java.base/jdk.internal.reflect.GeneratedMethodAccessor147.invoke(Unknown Source) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) ~[na:na]
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) ~[na:na]
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:691) ~[na:na]
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) ~[na:na]
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587) ~[na:na]
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828) ~[na:na]
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391) ~[na:na]
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
2020-07-08 18:28:39.955 ERROR 3552 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination 'TIBCO_TOPIC_NAME' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: authentication failed
2020-07-08 18:28:45.033 ERROR 3552 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination 'TIBCO_TOPIC_NAME' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: authentication failed
...
...
...
Why is the spring boot application unable to authenticate the connection to the tibco topic even though the username and password is provided via UserCredentialsConnectionFactoryAdapter? Do I need to configure anything else?
I am able to connect to this topic and receive messages successfully using the same credentials in a different setup that doesn't use spring boot. And I need to make this work with an existing Spring boot application.
Was able to figure out the solution in case anyone else is stuck. In spring boot, TopicConnectionFactory object is not required to specify that we need to connect to a Tibco Topic (and not a Queue), which is needed in standalone application. It is automatically done when PubSubDomain property is set to true. So, use TibjmsConnectionFactory instead which has methods to set credentials. UserCredentialsConnectionFactoryAdapter is not needed at all.
I changed my config code to below and it started working!
#Configuration
#EnableJms
public class TibcoConfig {
#Bean
public ConnectionFactory connectionFactory() {
TibjmsConnectionFactory factory = new TibjmsConnectionFactory("TIBCO_BROKER_URL");
factory.setUserName("USERNAME");
factory.setUserPassword("PASSWORD");
return factory;
}
#Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setClientId("client1");
factory.setPubSubDomain(true);
factory.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
return factory;
}
}