Search code examples
spring-bootspring-integrationgeode

Can't connect to apache geode from spring boot/integration application


I'm trying to connect a local instance of apache geode using spring-geode-starter and spring-integration-gemfire.

In My application.yml:

spring:
   data:
      gemfire:
         name: server1
         locators: localhost[10334]
         pool:
            subscription-enabled: true
            locators: localhost[10334]
        
        

When application starts , log report me that "Running in local mode since no locators were specified". I specified locators to simplify the transition from local to production environment and beacuse spring detect ip of hyper-v(geode is under docker - all port are mapped on local machine).

The properties in the log are clear: no locators is set.

2020-07-17 12:40:29.020  INFO 32928 --- [           main] o.a.g.internal.logging.LoggingSession    : Startup Configuration: ### GemFire Properties using default values ###
ack-severe-alert-threshold=0
ack-wait-threshold=15
archive-disk-space-limit=0
archive-file-size-limit=0
async-distribution-timeout=0
async-max-queue-size=8
async-queue-timeout=60000
bind-address=
cache-xml-file=cache.xml
cluster-configuration-dir=
cluster-ssl-ciphers=any
cluster-ssl-enabled=false
cluster-ssl-keystore=
cluster-ssl-keystore-password=
cluster-ssl-keystore-type=
cluster-ssl-protocols=any
cluster-ssl-require-authentication=true
cluster-ssl-truststore=
cluster-ssl-truststore-password=
conflate-events=server
conserve-sockets=true
delta-propagation=true
deploy-working-dir=C:\Users\c.marotta\Documents\WORKSPACE\poc-web30\spring-cloud-stream-idempotent\poc-kafka-stream-idempotent
disable-auto-reconnect=false
disable-jmx=false
disable-tcp=false
distributed-system-id=-1
distributed-transactions=false
durable-client-id=
durable-client-timeout=300
enable-cluster-configuration=true
enable-network-partition-detection=true
enable-time-statistics=false
enforce-unique-host=false
gateway-ssl-ciphers=any
gateway-ssl-enabled=false
gateway-ssl-keystore=
gateway-ssl-keystore-password=
gateway-ssl-keystore-type=
gateway-ssl-protocols=any
gateway-ssl-require-authentication=true
gateway-ssl-truststore=
gateway-ssl-truststore-password=
groups=
http-service-bind-address=
http-service-port=7070
http-service-ssl-ciphers=any
http-service-ssl-enabled=false
http-service-ssl-keystore=
http-service-ssl-keystore-password=
http-service-ssl-keystore-type=
http-service-ssl-protocols=any
http-service-ssl-require-authentication=false
http-service-ssl-truststore=
http-service-ssl-truststore-password=
jmx-manager=false
jmx-manager-access-file=
jmx-manager-bind-address=
jmx-manager-hostname-for-clients=
jmx-manager-http-port=7070
jmx-manager-password-file=
jmx-manager-port=1099
jmx-manager-ssl-ciphers=any
jmx-manager-ssl-enabled=false
jmx-manager-ssl-keystore=
jmx-manager-ssl-keystore-password=
jmx-manager-ssl-keystore-type=
jmx-manager-ssl-protocols=any
jmx-manager-ssl-require-authentication=true
jmx-manager-ssl-truststore=
jmx-manager-ssl-truststore-password=
jmx-manager-start=false
jmx-manager-update-rate=2000
load-cluster-configuration-from-dir=false
locator-wait-time=0
locators=
lock-memory=false
log-disk-space-limit=0
log-file=
log-file-size-limit=0
log-level=config
max-num-reconnect-tries=3
max-wait-time-reconnect=60000
mcast-address=239.192.81.1
mcast-flow-control=1048576, 0.25, 5000
mcast-port=0
mcast-recv-buffer-size=1048576
mcast-send-buffer-size=65535
mcast-ttl=32
member-timeout=5000
membership-port-range=41000-61000
memcached-bind-address=
memcached-port=0
memcached-protocol=ASCII
name=
off-heap-memory-size=
redis-bind-address=
redis-password=
redis-port=0
redundancy-zone=
remote-locators=
remove-unresponsive-client=false
roles=
security-client-accessor=
security-client-accessor-pp=
security-client-auth-init=
security-client-authenticator=
security-client-dhalgo=
security-log-file=
security-log-level=config
security-manager=
security-peer-auth-init=
security-peer-authenticator=
security-peer-verifymember-timeout=1000
security-post-processor=
security-udp-dhalgo=
serializable-object-filter=!*
server-bind-address=
server-ssl-ciphers=any
server-ssl-enabled=false
server-ssl-keystore=
server-ssl-keystore-password=
server-ssl-keystore-type=
server-ssl-protocols=any
server-ssl-require-authentication=true
server-ssl-truststore=
server-ssl-truststore-password=
socket-buffer-size=32768
socket-lease-time=60000
ssl-ciphers=any
ssl-cluster-alias=
ssl-default-alias=
ssl-enabled-components=
ssl-endpoint-identification-enabled=false
ssl-gateway-alias=
ssl-jmx-alias=
ssl-keystore=
ssl-keystore-password=
ssl-keystore-type=
ssl-locator-alias=
ssl-protocols=any
ssl-require-authentication=true
ssl-server-alias=
ssl-truststore=
ssl-truststore-password=
ssl-truststore-type=
ssl-use-default-context=false
ssl-web-alias=
ssl-web-require-authentication=false
start-dev-rest-api=false
start-locator=
statistic-archive-file=
statistic-sample-rate=1000
statistic-sampling-enabled=true
tcp-port=0
thread-monitor-enabled=true
thread-monitor-interval-ms=60000
thread-monitor-time-limit-ms=30000
udp-fragment-size=60000
udp-recv-buffer-size=1048576
udp-send-buffer-size=65535
use-cluster-configuration=true
user-command-packages=
validate-serializable-objects=false

Moreover I defined this in my start class:

@Bean
ApplicationRunner runAdditionalClientCacheInitialization(GemFireCache gemfireCache) {

    return args -> {

        ClientCache clientCache = (ClientCache) gemfireCache;

        // perform additional ClientCache initialization as needed
    };
}

but if I try to Autowired ClientCache bean, it's failed.

of course if I try this in Configuration class:

    cacheFactoryBean = new CacheFactoryBean();
    try {
        cache = (Cache) cacheFactoryBean.getObject();
    } catch (Exception e) {
        e.printStackTrace();
    }
    region = cache.getRegion("custom");
    

region is empty.

Application.java

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
    
    @Bean
    ApplicationRunner runAdditionalClientCacheInitialization(GemFireCache gemfireCache) {

        return args -> {

            ClientCache clientCache = (ClientCache) gemfireCache;

            // perform additional ClientCache initialization as needed
        };
    }
}
        

Solution

  • I've just tried this approach locally using spring-geode-starter:1.3.0.RELEASE and it seems to be working just fine:

    ### Using non default ports to prevent the default pool from successfully connecting
    
        _________________________     __
       / _____/ ______/ ______/ /____/ /
      / /  __/ /___  /_____  / _____  / 
     / /__/ / ____/  _____/ / /    / /  
    /______/_/      /______/_/    /_/    1.12.0
    
    Monitor and Manage Apache Geode
    gfsh>start locator --name=locator1 --port=10101
    gfsh>start server --name=server1 --server-port=40405
    gfsh>create region --name=TestRegion
    gfsh>create region --name=TestRegion --type=REPLICATE
    gfsh>put --key="Key1" --value="Value1" --region=/TestRegion
    
    ### Application
    @SpringBootApplication
    public class DemoApplication {
    
      public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
      }
    
      @Bean
      ApplicationRunner runAdditionalClientCacheInitialization(GemFireCache gemfireCache) {
    
        return args -> {
    
          ClientCache clientCache = (ClientCache) gemfireCache;
          Region<String, String> clientRegion = clientCache.<String, String>createClientRegionFactory(ClientRegionShortcut.PROXY).create("TestRegion");
          System.out.println("############ KeySetOnServer:" + clientRegion.keySetOnServer());
        };
      }
    }
    
    ### Output Log
    2020-07-17 13:16:13.762  INFO 12080 --- [           main] o.a.g.internal.InternalDataSerializer    : initializing InternalDataSerializer with 4 services
    2020-07-17 13:16:13.779  INFO 12080 --- [           main] org.apache.geode                         : [ThreadsMonitor] New Monitor object and process were created.
    
    2020-07-17 13:16:13.794  INFO 12080 --- [    StatSampler] o.a.g.i.statistics.StatArchiveHandler    : Disabling statistic archival.
    2020-07-17 13:16:13.866  INFO 12080 --- [           main] o.a.g.internal.cache.GemFireCacheImpl    : Running in client mode
    2020-07-17 13:16:14.041  INFO 12080 --- [           main] o.a.g.internal.cache.GemFireCacheImpl    : Initialized cache service org.apache.geode.cache.lucene.internal.LuceneServiceImpl
    2020-07-17 13:16:14.044  INFO 12080 --- [           main] o.a.g.internal.cache.GemFireCacheImpl    : Initialized cache service org.apache.geode.cache.query.internal.QueryConfigurationServiceImpl
    2020-07-17 13:16:14.415  INFO 12080 --- [           main] o.a.g.internal.cache.GemFireCacheImpl    : Initialized cache service org.apache.geode.management.internal.cli.remote.OnlineCommandProcessor
    2020-07-17 13:16:14.422  INFO 12080 --- [           main] o.s.d.g.client.ClientCacheFactoryBean    : Connected to Distributed System [server1] as Member [192.168.0.73(server1:12080:loner):0:c619b45c:server1] in Group(s) [[]] with Role(s) [[]] on Host [192.168.0.73] having PID [12080]
    2020-07-17 13:16:14.422  INFO 12080 --- [           main] o.s.d.g.client.ClientCacheFactoryBean    : Created new Apache Geode version [1.12.0] Cache [server1]
    2020-07-17 13:16:14.602  INFO 12080 --- [           main] o.a.g.c.c.i.AutoConnectionSourceImpl     : AutoConnectionSource UpdateLocatorListTask started with interval=10000 ms.
    2020-07-17 13:16:14.615  INFO 12080 --- [Timer-DEFAULT-2] o.a.g.c.c.i.AutoConnectionSourceImpl     : AutoConnectionSource discovered new locators [/192.168.0.73:10101]
    2020-07-17 13:16:14.618  INFO 12080 --- [Timer-DEFAULT-3] org.apache.geode                         : Updating membership port.  Port changed from 0 to 55174.  ID is now 192.168.0.73(server1:12080:loner):0:c619b45c:server1
    2020-07-17 13:16:14.659  INFO 12080 --- [           main] o.a.g.cache.client.internal.PoolImpl     : Pool DEFAULT started with multiuser-authentication=false
    2020-07-17 13:16:14.664  INFO 12080 --- [1001 port 40405] o.a.g.i.c.t.sockets.CacheClientUpdater   : Cache Client Updater Thread  on 192.168.0.73(server1:11423)<v1>:41001 port 40405 (192.168.0.73:40405) : ready to process messages.
    2020-07-17 13:16:14.735  INFO 12080 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 3.417 seconds (JVM running for 3.936)
    ############ KeySetOnServer:[Key1]
    2020-07-17 13:16:14.769  INFO 12080 --- [m shutdown hook] o.a.g.d.i.InternalDistributedSystem      : VM is exiting - shutting down distributed system
    2020-07-17 13:16:14.770  INFO 12080 --- [m shutdown hook] o.a.g.internal.cache.GemFireCacheImpl    : GemFireCache[id = 1681351053; isClosing = true; isShutDownAll = false; created = Fri Jul 17 13:16:13 IST 2020; server = false; copyOnRead = false; lockLease = 120; lockTimeout = 60]: Now closing.
    2020-07-17 13:16:14.788  INFO 12080 --- [m shutdown hook] o.a.g.cache.client.internal.PoolImpl     : Destroying connection pool DEFAULT
    
    ### application.yml
    spring:
      data:
        gemfire:
          name: server1
          locators: localhost[10334]
          pool:
            subscription-enabled: true
            locators: localhost[10101]
    

    What versions are you using?. Cheers.