標籤:tap lib shutdown public connect pre TE message data-
1.安裝程式的使用
啟動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
啟動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
建立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
gemfire中部署jar包分為實體類和計算類兩種情況:
1.實體類: 實體類需要部署到程式的classpath路徑下面;
2.計算類: 對於計算類,可以通過deploy命令手動部署;
部署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. 結合spring-data的使用
maven依賴:
<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)
ClientContext.xml
<!-- 定義client-cache--> <gfe:client-cache id="gemfireCache" pool-name="gemfirePool"/> <!-- 定義locator串連池--> <gfe:pool id="gemfirePool" subscription-enabled="true"> <!--<gfe:locator host="localhost" port="10334"/>--> <gfe:locator host="10.10.10.110" port="12105"/> </gfe:pool> <!-- 定義用戶端region --> <gfe:client-region id="messages" cache-ref="gemfireCache" value-constraint="com.cord.demo.data.Message" shortcut="PROXY"/>
- 通過spring-data介面CrudRepository實現OQL查詢region:
MessageReposirory.java
@Repository@DependsOn("gemfireCache")public interface MessageReposirory extends CrudRepository<Message, String>{ @Query("SELECT * FROM /messages m WHERE m.message = $1") List<Message> findByMessage(String message); @Query("SELECT * FROM /messages m WHERE m.message IN SET $1") List<Message> findByMessages(List<String> messages);}
ClientTestController.java
... List<Message> c1 = reposirory.findByMessage("C"); c1.stream().forEach(System.out::println);...
結論: 用戶端模式更多的是對叢集中資料的查詢,而對叢集中region的管理有限;
2.2 服務端嵌入模式(server)
設定檔:
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]
啟動類註解:
ServerApplication.java
@SpringBootApplication@CacheServerApplication(name = "embedServer")@EnableLocator@EnableGemfireRepositories(basePackages = "com.cord.demo.dao")@ImportResource(locations = {"classpath:ServerContext.xml"})public class ServerApplication implements CommandLineRunner { ...}
動態建立region:
ServerTestController.java
... @Autowired private Cache gemfireCache; //系統預設的cache名 ... /**擷取region工廠*/ RegionFactory<String, String> rf = gemfireCache.createRegionFactory(RegionShortcut.REPLICATE); /**建立region*/ Region<String, String> region = rf.create("test"); ...
gemfire基本使用以及spring-data-gemfire的使用