如何获取hazelcastMap配置

zbsbpyhn  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(332)

我正在尝试创建一个api来获取hazelcastMap配置。但是当我试着用

hazelcastInstance.getConfig().getMapConfig("MAP");

我出错了

java.lang.UnsupportedOperationException: Client config object only supports adding new data structure configurations

有什么解决方法来获取配置吗?

yx2lnoni

yx2lnoni1#

作为一种解决方法,您可以使用management center的半内部api(注意:不保证向后兼容)获取特定成员的成员配置,然后您可以解析它并提取所需的详细信息。
例子:

HazelcastClientInstanceImpl client = ((HazelcastClientProxy) HazelcastClient.newHazelcastClient()).client;
    client.getMap("myMap").put(1, 2);
    Member aMember = client.getCluster().getMembers().iterator().next();
    ClientInvocation invocation = new ClientInvocation(
            client, // of type HazelcastClientInstanceImpl
            MCGetMemberConfigCodec.encodeRequest(),
            null,
            aMember.getUuid()
    );
    String config = new ClientDelegatingFuture<String>(
            invocation.invoke(),
            client.getSerializationService(),
            clientMessage -> MCGetMemberConfigCodec.decodeResponse(clientMessage).configXml
    ).get();
    MapConfig mapConfig = new XmlConfigBuilder(new ByteArrayInputStream(config.getBytes(StandardCharsets.UTF_8))).build().getMapConfig("myMap");

相关问题