C++ Thin Client
Prerequisites
-
C compiler: MS Visual C (10.0 and up), g++ (4.4.0 and up)
-
Visual Studio 2010 or newer
Installation
The source code of the C++ thin client comes within the GridGain distribution package under the {GRIDGAIN_HOME}/platforms/cpp directory.
cd {GRIDGAIN_HOME}\platforms\cpp\project\vs
msbuild ignite.sln /p:Configuration=Release /p:Platform=x64
cd {GRIDGAIN_HOME}/platforms/cpp
libtoolize && aclocal && autoheader && automake --add-missing && autoreconf
# You can call the following command to see all the available
# configuration options:
# ./configure --help
# To use default configuration just type:
./configure
make
#The following step is optional if you want to install Ignite
#for your system. It would probably require root:
sudo make install
cd platforms/cpp
libtoolize && aclocal && autoheader && automake --add-missing && autoreconf
# You can call the following command to see all the available
# configuration options:
# ./configure --help
#
# Specify a target subdirectory in your user's home dir:
./configure --prefix=/home/user/odbc
make
#The following step is needed if you want to install Ignite
#under specified prefix directory.
make install
Creating Client Instance
The API provided by the thin client is located under the ignite::thin namespace.
The main entry point to the API is the IgniteClient::Start(IgniteClientConfiguration) method, which returns an instance of the client.
#include <ignite/thin/ignite_client.h>
#include <ignite/thin/ignite_client_configuration.h>
using namespace ignite::thin;
void TestClient()
{
IgniteClientConfiguration cfg;
//Endpoints list format is "<host>[port[..range]][,...]"
cfg.SetEndPoints("127.0.0.1:11110,example.com:1234..1240");
IgniteClient client = IgniteClient::Start(cfg);
cache::CacheClient<int32_t, std::string> cacheClient =
client.GetOrCreateCache<int32_t, std::string>("TestCache");
cacheClient.Put(42, "Hello Ignite Thin Client!");
}
Best Effort Affinity
#include <ignite/thin/ignite_client.h>
#include <ignite/thin/ignite_client_configuration.h>
using namespace ignite::thin;
void TestClientWithAuth()
{
IgniteClientConfiguration cfg;
cfg.SetEndPoints("127.0.0.1:10800");
IgniteClient client = IgniteClient::Start(cfg);
cache::CacheClient<int32_t, std::string> cacheClient =
client.GetOrCreateCache<int32_t, std::string>("TestCache");
cacheClient.Put(42, "Hello Ignite Thin Client with auth!");
cacheClient.RefreshAffinityMapping();
// Getting
std::string val = cacheClient.Get(42);
}
Using Key-Value API
Getting Cache Instance
To perform basic key-value operations on a cache, obtain an instance of the cache as follows:
cache::CacheClient<int32_t, std::string> cache =
client.GetOrCreateCache<int32_t, std::string>("TestCache");
The GetOrCreateCache(cacheName) returns an instance of the cache if it exists or creates the cache.
Basic Cache Operations
The following code snippet demonstrates how to execute basic cache operations on a specific cache.
std::map<int, std::string> vals;
for (int i = 1; i < 100; i++)
{
vals[i] = i;
}
cache.PutAll(vals);
cache.Replace(1, "2");
cache.Put(101, "101");
cache.RemoveAll();
Security
SSL/TLS
To use encrypted communication between the thin client and the cluster, you have to enable it both in the cluster configuration and the client configuration. Refer to the Enabling SSL/TLS for Thin Clients section for the instruction on the cluster configuration.
IgniteClientConfiguration cfg;
// Sets SSL mode.
cfg.SetSslMode(SslMode::Type::REQUIRE);
// Sets file path to SSL certificate authority to authenticate server certificate during connection establishment.
cfg.SetSslCaFile("path/to/SSL/certificate/authority");
// Sets file path to SSL certificate to use during connection establishment.
cfg.SetSslCertFile("path/to/SSL/certificate");
// Sets file path to SSL private key to use during connection establishment.
cfg.SetSslKeyFile("path/to/SSL/private/key");
Authentication
Configure authentication on the cluster side and provide a valid user name and password in the client configuration.
#include <ignite/thin/ignite_client.h>
#include <ignite/thin/ignite_client_configuration.h>
using namespace ignite::thin;
void TestClientWithAuth()
{
IgniteClientConfiguration cfg;
cfg.SetEndPoints("127.0.0.1:10800");
// Use your own credentials here.
cfg.SetUser("ignite");
cfg.SetPassword("ignite");
IgniteClient client = IgniteClient::Start(cfg);
cache::CacheClient<int32_t, std::string> cacheClient =
client.GetOrCreateCache<int32_t, std::string>("TestCache");
cacheClient.Put(42, "Hello Ignite Thin Client with auth!");
}
Authorization
Thin client authorization can be configured in the cluster. Refer to the Authorization page for details.
© 2021 GridGain Systems, Inc. All Rights Reserved. Privacy Policy | Legal Notices. GridGain® is a registered trademark of GridGain Systems, Inc.
Apache, Apache Ignite, the Apache feather and the Apache Ignite logo are either registered trademarks or trademarks of The Apache Software Foundation.