无法在Spring上下文中为嵌入式Apache Geode缓存服务器

时间:2018-05-11 06:20:11

标签: gemfire geode spring-data-gemfire

我为了演示目的创建了存储库SpringbootGeodeExample

在Gfsh中启动了一个Locator,并在Spring Boot应用程序中嵌入了缓存服务器,并在Spring上下文中为嵌入式缓存服务器定义了一些区域。 现在我可以列出区域,但无法查询&破坏地区,执行"描述"地区显示"主持会员"是空白的。

gfsh>describe region --name=Region1
..........................................................
Name            : Region1
Data Policy     : partition
Hosting Members :

gfsh>query --query="select * from /Region1"
Result  : false
Message : Cannot find regions <[/Region1]> in any of the members

gfsh>destroy region --name=Region1
Could not find a Region with Region path "Region1" in this Geode cluster. If region was recently created, please wait for at least jmx-manager-update-rate milliseconds to allow the associated Management resources to be federated.

我可以在Gfsh中创建的区域上面做,如何在Spring上下文中创建的区域进行相同的CRUD操作?

我尝试添加--enable-cluster-configuration = true并使用-cluster-configuration =&#34; true&#34;在定位器和缓存服务器中,但仍无法正常工作。

更多细节: 缓存服务器应用程序配置:

@SpringBootApplication
@CacheServerApplication
@EnableCacheServer(autoStartup = true, port = 41414)
@ImportResource("classpath:spring-cache-context-cluster-side.xml")
public class CacheServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(CacheServerApplication.class, args);
    }
}

春天语境中的区域定义:

<gfe:partitioned-region id="Region1" copies="1">
        <gfe:eviction type="MEMORY_SIZE" threshold="512" action="LOCAL_DESTROY"/>
</gfe:partitioned-region>

根据约翰的评论更新:

更新1:

列表成员显示缓存服务器名称为空,这是根本原因吗?

gfsh>list members
  Name   | Id
-------- | -----------------------------------------------
locator2 | 192.168.1.2(locator2:1396:locator)<ec><v0>:1024
         | 192.168.1.2(6032)<v3>:1025

我尝试将注释更改为:

@SpringBootApplication
@CacheServerApplication(name = "MyServer", locators="localhost[10334]", autoStartup = true, port = 41415)
@EnableCacheServer(name = "MyServer", autoStartup = true, port = 41414)
@ImportResource("classpath:spring-cache-context-cluster-side.xml")

但仍然没有运气,服务器名称为空。

更新2:

我正在使用 spring-data-geode 2.0.6.RELEASE geode-core 1.2.1 我的maven依赖:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.RC1</spring-cloud.version>
        <spring-cloud-services.version>1.5.0.RELEASE</spring-cloud-services.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        <dependency>
                <groupId>io.pivotal.spring.cloud</groupId>
                <artifactId>spring-cloud-services-dependencies</artifactId>
                <version>${spring-cloud-services.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

   <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-geode</artifactId>
        </dependency>

更新3:

弹簧缓存上下文群集side.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:gfe="http://www.springframework.org/schema/geode"
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/geode http://www.springframework.org/schema/gemfire/spring-geode.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 


    <bean id="pdxSerializer" class="org.apache.geode.pdx.ReflectionBasedAutoSerializer">
        <constructor-arg value="com.WMModel.model.*"/>
    </bean>

    <util:properties id="gemfireProperties">
        <prop key="locators">${geode.cache.server.locators}</prop>
        <prop key="mcast-port">0</prop>
    </util:properties>

    <gfe:cache
        properties-ref="gemfireProperties"
        id="gemfireCache"
        use-cluster-configuration="true"
        pdx-serializer-ref="pdxSerializer" 
        copy-on-read="false" 
        critical-heap-percentage="85" 
        eviction-heap-percentage="80">
       <gfe:transaction-listener> 
            <bean class="com.WMCacheServer.db.op.WmTransactionListener"/>
        </gfe:transaction-listener>
        <gfe:transaction-writer> 
            <bean class="com.WMCacheServer.db.op.WmTransactionWriter"/>
        </gfe:transaction-writer>   
        <gfe:dynamic-region-factory/>     
    </gfe:cache>

    <!-- configure the cache and set the port to 0 for it picks the first available port -->
    <gfe:cache-server 
        id="advanced-config"
        port="${geode.cache.server.port}"
        auto-startup="true"
        cache-ref="gemfireCache" />
    <context:property-placeholder location="classpath:cache-server.properties"/>


    <gfe:partitioned-region id="Region1" copies="1">
        <gfe:eviction type="MEMORY_SIZE" threshold="512" action="LOCAL_DESTROY"/>
    </gfe:partitioned-region>
</beans>

cache-server.properties:

### For complete options list: http://gemfire.docs.gopivotal.com/index.html?q=/reference/topics/gemfire_properties.html ###

### Logging ###
log-level=config

### Turn Off Multi Cast ###
mcast-port=0

### Turn on Statistics ###
statistic-archive-file=stats.gfs
statistic-sample-rate=1000
statistic-sampling-enabled=true

enable-network-partition-detection=false

##Conserve Sockets##
conserve-sockets=false
geode.cache.server.port=40434
#geode.cache.server.locators=peer2.com[10334],localhost[10334]
geode.cache.server.locators=localhost[10334]

2 个答案:

答案 0 :(得分:0)

您使用的是什么版本的 Apache Geode Spring Data Geode

list members的输出是什么?

CacheServerApplication类判断,您的 Spring(数据网格)配置和引导的 Apache Geode 服务器似乎没有连接到/ Locator 。此外,您可以简化配置...

@SpringBootApplication
@CacheServerApplication(name = "MyServer", locators="localhost[10334]"
    autoStartup = true, port = 41414)
@ImportResource("classpath:spring-cache-context-cluster-side.xml")
public class CacheServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(CacheServerApplication.class, args);
    }
}

请注意,我将name attribute添加到@CacheServerApplication注释中以明确命名服务器。建议这样做,因为成员名在集群中必须是唯一的,如果使用同一个类启动多个服务器,default name(即“SpringBasedCacheServerApplication”)将发生冲突。当然,它也会在CacheServer端口号上发生冲突,因为它是硬编码的(即“41414”)。您可以使用ConfigurersProperties动态配置。

此外,我已将locators attribute设置为“localhost [10334]”。您应该将定位器的主机和端口(在“host [port]”格式化的String中)更改为运行/侦听成员/客户端连接的主机和端口。

我在Spring Boot GemFire Server Example repo中有一个Spring配置和引导的Pivotal GemFire服务器的示例。我刚刚将此示例升级为 Spring Boot 2.0.2.RELEASE 。这将引入 Spring Data Kay-SR7 ,其中包括 Spring Data GemFire 2.0.7.RELEASE ,这是基于 Pivotal GemFire 9.1.1

此外,此示例最初基于Java配置,因为它在SDG中使用了 new Annotation-based configuration model。因此,使用XML确实没有意义,因为您也可以define a Region in JavaConfig

但是,无论如何。我们可以略微调整这个例子,以便基于XML。

  

注意:我example repo中的服务器也是一个独立的独立服务器/集群,具有自己的定位器和管理器配置。但是,我只是将此配置分离为使用Spring配置文件启用的nested, static @Configuration class(即通过设置系统属性-Dspring.profiles.active=locator-manager)。启用此配置文件后,您不需要运行独立定位器,但您仍然可以。你只需要注意端口冲突等等。无论如何......

我刚刚在我的回购邮件中添加了xml-config分支。

然后,我configured Factorials ”PARTITION Region使用SDG的XML命名空间imported itconfigured Locator端点连接到外部启动的Locator

接下来,我运行 Gfsh ,启动了一个Locator并继续运行SpringBootGemFireServerExample类......

$ echo $GEMFIRE
/Users/jblum/pivdev/pivotal-gemfire-9.1.1
$ 
$ gfsh
    _________________________     __
   / _____/ ______/ ______/ /____/ /
  / /  __/ /___  /_____  / _____  / 
 / /__/ / ____/  _____/ / /    / /  
/______/_/      /______/_/    /_/    9.1.1

Monitor and Manage Pivotal GemFire

gfsh>list members
Command 'list members' was found but is not currently available (type 'help' then ENTER to learn about this command)
gfsh>
gfsh>start locator --name=LocatorOne --log-level=config --J=-Dgemfire.http-service-port=0
Starting a Geode Locator in /Users/jblum/pivdev/lab/LocatorOne...
...
Locator in /Users/jblum/pivdev/lab/LocatorOne on 10.0.0.121[10334] as LocatorOne is currently online.
Process ID: 33659
Uptime: 3 seconds
Geode Version: 9.1.1
Java Version: 1.8.0_152
Log File: /Users/jblum/pivdev/lab/LocatorOne/LocatorOne.log
JVM Arguments: -Dgemfire.log-level=config -Dgemfire.enable-cluster-configuration=true -Dgemfire.load-cluster-configuration-from-dir=false -Dgemfire.http-service-port=0 -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806
Class-Path: /Users/jblum/pivdev/pivotal-gemfire-9.1.1/lib/geode-core-9.1.1.jar:/Users/jblum/pivdev/pivotal-gemfire-9.1.1/lib/geode-dependencies.jar

Successfully connected to: JMX Manager [host=10.0.0.121, port=1099]

Cluster configuration service is up and running.


gfsh>list members
   Name    | Id
---------- | -------------------------------------------------
LocatorOne | 10.0.0.121(LocatorOne:33659:locator)<ec><v0>:1024

现在,我继续从IDE中启动SpringBootGemFireServerExample类。请记住,我启用了“locator-manager”Spring配置文件(即-Dspring.profiles.active=(空))。我不想启动嵌入式定位器/管理器,因为我想连接到Gfsh启动定位器,因此这...

@CacheServerApplication(... locators="localhost[10334]")

从IDE运行服务器后,连接到此定位器......

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.2.RELEASE)

[info 2018/05/11 11:53:36.883 PDT <main> tid=0x1] 
---------------------------------------------------------------------------

  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with this
  work for additional information regarding copyright ownership.

  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with the
  License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
  License for the specific language governing permissions and limitations
  under the License.

---------------------------------------------------------------------------
Build-Date: 2017-09-08 19:39:04 +0000
Build-Id: root 51
Build-Java-Version: 1.8.0_144
Build-Platform: Linux 4.4.0-62-generic amd64
GemFire-Source-Date: 2017-09-01 21:01:32 +0000
GemFire-Source-Repository: support/9.1
GemFire-Source-Revision: ac20a06062204a8f6ba2acaaf2c7dbc1a3d0cfe0
Product-Name: Pivotal GemFire
Product-Version: 9.1.1
Source-Date: 2017-09-08 19:07:34 +0000
Source-Repository: support/9.1
Source-Revision: e756828d0e631cec47f3d027555c022f0fb0e5cc
Native version: native code unavailable
Running on: /10.0.0.121, 8 cpu(s), x86_64 Mac OS X 10.10.5 
Communications version: 65
Process ID: 33670
...
..
.
[info 2018/05/11 11:53:38.454 PDT <main> tid=0x1] CacheServer Configuration:   port=40404 max-connections=800 max-threads=0 notify-by-subscription=true socket-buffer-size=32768 maximum-time-between-pings=60000 maximum-message-count=230000 message-time-to-live=180 eviction-policy=none capacity=1 overflow directory=. groups=[] loadProbe=ConnectionCountProbe loadPollInterval=5000 tcpNoDelay=true

我可以看到服务器加入了Gfsh中定位器定义的集群...

gfsh>list members
         Name           | Id
----------------------- | --------------------------------------------------
LocatorOne              | 10.0.0.121(LocatorOne:33659:locator)<ec><v0>:1024
SpringBootGemFireServer | 10.0.0.121(SpringBootGemFireServer:33670)<v1>:1025

gfsh>describe member --name=SpringBootGemFireServer
Name        : SpringBootGemFireServer
Id          : 10.0.0.121(SpringBootGemFireServer:33670)<v1>:1025
Host        : 10.0.0.121
Regions     : Factorials
PID         : 33670
Groups      : 
Used Heap   : 52M
Max Heap    : 3641M
Working Dir : /Users/jblum/pivdev/spring-data-examples-workspace/spring-boot-gemfire-server-example/build
Log file    : /Users/jblum/pivdev/spring-data-examples-workspace/spring-boot-gemfire-server-example/build
Locators    : localhost[10334]

Cache Server Information
Server Bind              : 
Server Port              : 40404
Running                  : true
Client Connections       : 0

您还可以看到“Factorials”PARTITION Region由“SpringBootGemFireServer”托管,这也很明显......

gfsh>list regions
List of regions
---------------
Factorials

gfsh>describe region --name

required --name: Name/Path of the region to be described.; no default value
gfsh>describe region --name=/Factorials
..........................................................
Name            : Factorials
Data Policy     : partition
Hosting Members : SpringBootGemFireServer

Non-Default Attributes Shared By Hosting Members  

 Type  |    Name     | Value
------ | ----------- | ---------
Region | size        | 0
       | data-policy | PARTITION

接下来,我使用数字键访问一个值。

  

注意:此示例attaches a "Factorial" computational based CacheLoader到“Factorials”PARTITION Region。

gfsh>get --region=/Factorials --key=3 --key-class=java.lang.Long
Result      : true
Key Class   : java.lang.Long
Key         : 3
Value Class : java.lang.Long
Value       : 6


gfsh>get --region=/Factorials --key=5 --key-class=java.lang.Long
Result      : true
Key Class   : java.lang.Long
Key         : 5
Value Class : java.lang.Long
Value       : 120

最后,我可以查询“Factorials”PARTITION Region中的值,就像这样......

gfsh>query --query="SELECT * FROM /Factorials"
Result : true
Limit  : 100
Rows   : 2

Result
------
6
120

当您对区域“describe”时,您可以看到它已被更改(请参阅“尺寸”)。

gfsh>describe region --name=/Factorials
..........................................................
Name            : Factorials
Data Policy     : partition
Hosting Members : SpringBootGemFireServer

Non-Default Attributes Shared By Hosting Members  

 Type  |    Name     | Value
------ | ----------- | ---------
Region | size        | 2
       | data-policy | PARTITION

无论如何,一切都很顺利。希望这有帮助!

-John

答案 1 :(得分:0)

好的,通过更改Maven依赖项来解决。 谢谢约翰! 看起来spring-bootspring-data-geode之间存在冲突。 希望geode-spring-boot-starter即将发布。 我更新的依赖项:

<dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-geode</artifactId>
        <version>2.0.1.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>          
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.7</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.shell</groupId>
      <artifactId>spring-shell</artifactId>
      <version>1.2.0.RELEASE</version>
       <exclusions>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context-support</artifactId>
        </exclusion>
      </exclusions>
    </dependency>