Hazelcast Rest API

Hazelcast 提供了一组Rest的API用于管理集群以及访问数据。通过这个API你可以知道集群的信息,也可以访问它的partition里面的分布式对象,比如map, queue之类的数据结构。

你可以通过下面几种方式来enable这些Rest API:

1.Configuration.xml
把hazelcast.rest.enabled这个property加到你的配置文件中,如下,在代码里加载这个配置文件生成一下Config对象:

<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-2.0.xsd"
    xmlns="http://www.hazelcast.com/schema/config"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    ....
    <properties>
        <property name="hazelcast.rest.enabled">true</property>
            ....
    </properties>
</hazelcast>

2.Configuration API

Config cfg = new Config() ;
cfg.setProperty("hazelcast.rest.enabled", "true");

3.System Property
- 添加JVM启动参数:-Dhazelcast.rest.enabled=true
- 设置System Property: System.setProperty(“hazelcast.rest.enabled”, “true”)

以下的API在1.9.4以及以上的版本中验证过。
Hazelcast其实本身也提供了另外一个management center的包,里面提供了更丰富的API, 感兴趣的可以看下面的官方文档:
Management Center

集群API

通过下面的Rest可以知道当前这个cluster有多少个member

$ curl -s http://localhost:5701/hazelcast/rest/cluster
Cluster [2] {
        Member [192.168.100.12:5701] this
        Member [192.168.100.12:5702]
}

ConnectionCount: 1
AllConnectionCount: 3

数据访问API

以Map这个数据结构为例子,我们可以通过Rest 把某个map上增加一个K/V,然后通过key可以访问到它对应的值。

1.增加一个k/v到”demo”这个map中:

curl -XPOST -iv --data "value1" http://localhost:5722/hazelcast/rest/maps/demo/key1

2.访问map里面的数据

> curl -s http://localhost:5722/hazelcast/rest/maps/demo/key1
value1
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值