spring-boot - 无法从弹簧启动/集成应用程序连接到 apache geode
问题描述
我正在尝试使用 spring-geode-starter 和 spring-integration-gemfire 连接 apache geode 的本地实例。
在我的 application.yml 中:
spring:
data:
gemfire:
name: server1
locators: localhost[10334]
pool:
subscription-enabled: true
locators: localhost[10334]
当应用程序启动时,记录报告我“在本地模式下运行,因为没有指定定位器”。我指定了定位器以简化从本地环境到生产环境的过渡,并且因为 spring 检测了 hyper-v 的 ip(geode 在 docker 下 - 所有端口都映射到本地机器上)。
日志中的属性很清楚:没有设置定位器。
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
此外,我在我的开始课程中定义了这一点:
@Bean
ApplicationRunner runAdditionalClientCacheInitialization(GemFireCache gemfireCache) {
return args -> {
ClientCache clientCache = (ClientCache) gemfireCache;
// perform additional ClientCache initialization as needed
};
}
但是如果我尝试使用 Autowired ClientCache bean,它就会失败。
当然,如果我在配置类中尝试这个:
cacheFactoryBean = new CacheFactoryBean();
try {
cache = (Cache) cacheFactoryBean.getObject();
} catch (Exception e) {
e.printStackTrace();
}
region = cache.getRegion("custom");
区域为空。
应用程序.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
};
}
}
解决方案
我刚刚在本地尝试过这种方法spring-geode-starter:1.3.0.RELEASE
,它似乎工作得很好:
### 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]
你用的是什么版本?。干杯。
推荐阅读
- javascript - 使用 JQuery 处理来自帖子的数据的正确方法
- python - 是否可以对 python 中的列表元素进行唯一的 sql 查询?
- r - 将表从 R 导出到 SQL Server
- azure-storage - 如何在 Azure 表存储中保留空属性?
- html - CSS - 背景图片不显示
- c++ - 有什么方法可以通过向量显示结构的内容?
- json - 将 jq 查询的结果聚合到单个数组中
- bash - 如何仅列出“普通”可读文件夹(例如不压缩文件夹)?
- c# - 如何知道 .txt 扩展名是否包含纯文本或 CSV 结构?
- git - 将文件从主存储库重构为具有历史记录的子模块