hot Rod C++ 客户端指南

Red Hat Data Grid 8.3

配置和使用 Hot Rod C++ 客户端

Red Hat Customer Content Services

摘要

hot Rod C++ 客户端允许 C++ 运行时应用程序与远程数据中心集群连接和交互。

Red Hat Data Grid

Data Grid 是一个高性能分布式内存数据存储。

无架构数据结构
将不同对象存储为键值对的灵活性。
基于网格的数据存储
旨在在集群中分发和复制数据。
弹性扩展
动态调整节点数量,以便在不中断服务的情况下满足需求。
数据互操作性
从不同端点在网格中存储、检索和查询数据。

Data Grid 文档

红帽客户门户网站中提供了 Data Grid 的文档。

Data Grid 下载

访问 红帽客户门户上的 Data Grid 软件下载。

注意

您必须有一个红帽帐户才能访问和下载数据中心软件。

使开源包含更多

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。我们从这四个术语开始:master、slave、黑名单和白名单。由于此项工作十分艰巨,这些更改将在即将推出的几个发行版本中逐步实施。详情请查看 CTO Chris Wright 的信息

对红帽文档提供反馈

我们非常感谢您对我们的技术内容提供反馈,并鼓励您告诉我们您的想法。如果您想添加评论,提供见解、纠正拼写错误甚至询问问题,您可以在文档中直接这样做。

注意

您必须有一个红帽帐户并登录到客户门户网站。

要从客户门户网站提交文档反馈,请执行以下操作:

  1. 选择 Multi-page HTML 格式。
  2. 点文档右上角的 反馈 按钮。
  3. 突出显示您要提供反馈的文本部分。
  4. 点高亮文本旁的添加反馈对话框。
  5. 在页面右侧的文本框中输入您的反馈,然后单击 Submit

每次提交反馈时,我们都会自动创建跟踪问题。打开在点 Submit 后显示的链接,并开始监视问题或添加更多注释。

感谢您的宝贵反馈。

第 1 章 安装 Hot Rod C++ 客户端

作为动态库在主机系统上安装 Hot Rod C++ 客户端。

1.1. C++ 编译器要求

操作系统所需的编译器

Red Hat Enterprise Linux (RHEL) 7, 64 位

C++ 11 编译器(GCC 4.8.1)

RHEL 8、64 位

C++ 11 编译器(GCC 4.8.1)

Microsoft Windows 7 x64

C 11 编译器(适用于 x64 平台的 Microsoft Visual C 2013 Redistributable Package)

1.2. 在 Red Hat Enterprise Linux (RHEL)上安装 Hot Rod C++ 客户端

Data Grid 为 RHEL 提供 Hot Rod C++ 客户端的 RPM 发行版本。

流程

  1. 为 RHEL 上的 Hot Rod C++ 客户端启用存储库。

    RHEL 版本软件仓库

    RHEL 7

    jb-datagrid-8.1-for-rhel-7-server-rpms

    RHEL 8

    jb-datagrid-8.1-for-rhel-8-x86_64-rpms

  2. 安装 Hot Rod C++ 客户端。

    # yum install jdg-cpp-client

1.3. 在 Microsoft Windows 上安装 Hot Rod C++ 客户端

Data Grid 提供 Hot Rod C++ 客户端的存档版本,用于在 Windows 上安装。

流程

  1. Data Grid Software Downloads,下载 Hot Rod C++ 客户端的 ZIP 存档。
  2. 将 ZIP 存档提取到您的文件系统中。

第 2 章 编译 Protobuf Schema

Data Grid 使用 ProtoStream API 将数据存储为 Protobuf 编码的条目。

protobuf 是一种语言中立格式,它允许客户端使用 Hot Rod 和 REST 端点在远程缓存中创建和检索条目。

2.1. 在 Red Hat Enterprise Linux (RHEL)上编译 Protobuf 模式

将 Protobuf 模式 .proto 文件编译到 C++ 标头和源文件中,将您的数据描述给 Data Grid。

先决条件

  • 安装 Protobuf 库和 protobuf-devel 软件包。

    # yum install protobuf
    # yum install protobuf-devel

流程

  1. 设置 LD_LIBRARY_PATH 环境变量(如果尚未设置)。

    # export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/lib64
  2. 根据需要为 Hot Rod C++ 客户端编译 Protobuf 模式。

    # /bin/protoc --cpp_out dllexport_decl=HR_PROTO_EXPORT:/path/to/output/ $FILE

    HR_PROTO_EXPORT 是一个宏,Hotot Rod C++ 客户端会在编译 Protobuf 模式时扩展。

  3. 如果您计划使用查询,请将 Protobuf 模式注册到 Data Grid。

2.2. 在 Microsoft Windows 上编译 Protobuf 模式

将 Protobuf 模式 .proto 文件编译到 C++ 标头和源文件中,将您的数据描述给 Data Grid。

流程

  1. 打开 Hot Rod C++ 客户端的安装目录的命令提示符。
  2. 根据需要为 Hot Rod C++ 客户端编译 Protobuf 模式。

    bin\protoc --cpp_out dllexport_decl=HR_PROTO_EXPORT:path\to\output\ $FILE

    HR_PROTO_EXPORT 是一个宏,Hotot Rod C++ 客户端会在编译 Protobuf 模式时扩展。

  3. 如果您计划使用查询,请将 Protobuf 模式注册到 Data Grid。

第 3 章 配置 Hot Rod C++ 客户端

hot Rod C++ 客户端通过 RemoteCache API 与远程数据平面集群交互。

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);

法律通告

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.