第 3 章 配置 Hot Rod C++ 客户端
热 Rod C++ 客户端通过 RemoteCache API 与远程 Data Grid 集群交互。
3.1. 配置和远程缓存管理器 API 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
使用 ConfigurationBuilder API 配置 Hot Rod C++ 客户端连接和 RemoteCacheManager API,以获取和配置远程缓存。
配置构建器
#include "infinispan/hotrod/ConfigurationBuilder.h"
#include "infinispan/hotrod/RemoteCacheManager.h"
#include <infinispan/hotrod/RemoteCache.h>
#include <iostream>
int main () {
ConfigurationBuilder builder;
// Configure a cache manager to connect with Hot Rod version 2.8
builder.protocolVersion(Configuration::PROTOCOL_VERSION_28);
// Connect to a server at localhost with the default port.
builder.addServer().host("127.0.0.1").port(11222);
// Create and start a RemoteCacheManager to interact with caches.
RemoteCacheManager cacheManager(builder.build(), false);
cacheManager.start();
...
}
跨站点复制
ConfigurationBuilder builder;
builder.addServer().host("127.0.0.1").port(11222);
// Configure a remote cluster and node when using cross-site replication.
builder.addCluster("NYC").addClusterNode("192.0.2.0", 11322);
接近缓存
ConfigurationBuilder builder;
builder.addServer().host("127.0.0.1").port(11222);
// Enable near-caching for the client.
builder.nearCache().mode(NearCacheMode::INVALIDATED).maxEntries(4);