GemFire basic use and use of Spring-data-gemfire

Source: Internet
Author: User
Tags gemfire

1. Use of the installation program
    • Locator
启动locatorgfsh>start locator --name=locator1  指定端口启动gfsh>start locator --name=locator1  --port=12105指定端口和绑定ip启动gfsh>start locator --name=locator1 --port=12105 --bind-address=10.10.10.110查看locator状态gfsh>status locator --name=locator1gfsh>status locator --host=localhost --port=10334连接locatorgfsh>connectgfsh>connect --locator=localhost[10335]关闭locatorgfsh>stop locator --name=locator1关闭整个集群gfsh>shutdown --include-locators=true
    • Server
启动servergfsh>start server --name=server1指定locator启动gfsh>start server --name=server1 --locators=localhost[10334]指定端口和locator启动gfsh>start server --name=server1 --server-port=12104  --locators=10.10.10.110[12105]停止servergfsh>stop server --name=server1
    • Region
创建regiongfsh>create region --name=test --type=REPLICATE_PERSISTENT存储kv值gfsh>put --region=test --key="a" --value="A"查询信息gfsh>query --query="select * from /test"查看region信息gfsh>describe region --name=test销毁regiongfsh>destroy region --name=test
    • Deploy the jar package (deploy)

The deployment jar packages in GemFire are divided into entity classes and calculation classes in two cases:

1. Entity classes: Entity classes need to be deployed under the CLASSPATH path of the program;

2. Calculation class: For the calculation class, it can be deployed manually through the Deploy command;

部署jar包gfsh>deploy --jars=/data/local/gemfire/apache-geode-1.5.0/lib/geode-demo-1.0-SNAPSHOT.jar查看已部署jar包gfsh>list deployed卸载jar包gfsh>undeploy --jar=geode-demo-1.0-SNAPSHOT.jar
2. Combined with the use of Spring-data

Maven dependencies:

    <dependency>      <groupId>org.springframework.data</groupId>      <artifactId>spring-data-gemfire</artifactId>      <version>2.0.6.RELEASE</version>      <exclusions>        <exclusion>          <groupId>io.pivotal.gemfire</groupId>          <artifactId>geode-lucene</artifactId>        </exclusion>      </exclusions>    </dependency>
2.1 Client Mode
    • Configuration file:

clientcontext. xml

    <!--definition client-cache-->    <gfe:client-cacheid="Gemfirecache"pool-name="Gemfirepool"/>    <!--define Locator connection pool --    <gfe:poolid="Gemfirepool"subscription-enabled="true">        <!--<gfe:locator host= "localhost" port= "10334"/>-->        <gfe:locatorhost="10.10.10.110"port="12105"/>    </gfe:pool>    <!--Define client region--    <gfe:client-regionid="Messages"cache-ref="Gemfirecache"value-constraint="Com.cord.demo.data.Message"shortcut="PROXY"/>
    • The OQL query region is implemented through the Spring-data interface crudrepository:

Messagereposirory.java

@Repository@DependsOn("gemfireCache")publicinterfaceextends CrudRepository<Message, String>{    @Query("SELECT * FROM /messages m WHERE m.message = $1")    findByMessage(String message);    @Query("SELECT * FROM /messages m WHERE m.message IN SET $1")    findByMessages(List<String> messages);}

Clienttestcontroller.java

...        List<Message> c1 = reposirory.findByMessage("C");        c1.stream().forEach(System.out::println);...

conclusion : The client mode is more the query of the data in the cluster, but the management of region in the cluster is limited.

2.2 Service-side embedding mode (server)

Configuration file:

Servercontext.xml

<!-- 定义region--><gfe:replicated-region id="messages" value-constraint="com.cord.demo.data.Message"/>

Application.properties

#server端口和绑定地址spring.data.gemfire.cache.server.port=41414spring.data.gemfire.cache.server.bind-address=localhost#locator端口和地址spring.data.gemfire.locator.host=localhostspring.data.gemfire.locator.port=10335

Gemfire.properties

#开启jmxjmx-manager=truejmx-manager-start=true#指定访问locator集群locators=localhost[10334],localhost[10335]

Start class Annotations:

Serverapplication.java

@SpringBootApplication@CacheServerApplication"embedServer")@EnableLocator@EnableGemfireRepositories"com.cord.demo.dao")@ImportResource(locations = {"classpath:ServerContext.xml"})publicclassimplements CommandLineRunner {  ...}

Dynamically Create region:

Servertestcontroller.java

    ...    @Autowired    private//系统默认的cache名      ...         /**获取region工厂*/        RegionFactory<String, String> rf = gemfireCache.createRegionFactory(RegionShortcut.REPLICATE);        /**创建region*/        Region<String, String> region = rf.create("test");             ...   

GemFire basic use and use of Spring-data-gemfire

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.