GridGain Developers Hub
GitHub logo GridGain iso GridGain.com
GridGain Software Documentation

Connecting With Thin Clients

It’s assumed that you have already created an account on the GridGain Cloud and started the first cluster there.

The following example image shows a running cluster called MyCluster using the free-tier.

GridGain Cloud Sample Cluster

Connecting to the Cloud

GridGain Cloud supports JDBC and ODBC connectivity as well as REST protocol and thin clients. These APIs make it possible to use the managed offering for distributed SQL database and key-value store scenarios.

The managed service goes with GridGain Client Cloud Pack and is also fully compatible with GridGain Community, Enterprise, and Ultimate Editions:

  1. Download a GridGain Client Cloud Pack from the Cluster Info window that pops up once you click the Actions button or on the cluster row of the cluster table. Other GridGain Editions can be downloaded from the website.

    GridGain Cloud Settings
  2. Unzip the ZIP archive into the installation folder on your system.

  3. Download your personal SSL certificate from the same Cluster Info. Refer to this page for more details on how to use the certificates.

  4. Copy the SSL certificate (keyStore.jks) to the bin directory of GridGain Cloud Pack or your GridGain distribution.

GridGain Cloud Cluster Info

Connection Info

Ignite and GridGain provide thin clients for Java, .NET, Python, PHP, and Node.JS applications, which can be used to communicate with the cluster running on GridGain Cloud, over a TCP socket connection.

To connect to the cluster, click on the Name column of your running cluster and obtain the Thin Client connection string from the Cluster Info screen that looks like the one below:

GridGain Cloud Settings

Java Thin Client

Use the IgniteClient API this way to connect and work with your GridGain Cloud cluster:

  • Add ignite-core.jar to the classpath of your application or use the Maven artifact of the same name. Refer to this Java Thin Client article for more details.

  • Ensure the SSL Certificate named keystore.jks is already downloaded from the Cluster Info dialog. Then, in your code, set the cluster address - host and port, username, password, as well as SSL certificate information in ClientConfiguration.

  • Provide this configuration in the Ignition.startClient(ClientConfiguration) method to establish a secure connection to the cluster and obtain an instance of IgniteClient.

Here is an example code snippet:

String thinClient = "13.57.50.182:9490"; // Provide actual thinClient address from the "Cluster Info" dialog.
String username = "ignite"; // This is a pre-defined username provided by GG Cloud.
String pwd = "myclusterpassword"; // Provide actual cluster password from the "Cluster Info" dialog.
String sslPwd = "LO4B0E0A3LtV7nwETnhY"; // Provide actual SSL password from the "Cluster Info" dialog.
String store = "/path/to/SSL/keyStore.jks"; // Provide the path where the file is stored after downloading from GG Cloud.

ClientConfiguration cfg = new ClientConfiguration()
        .setAddresses(thinClient)
        .setUserName(username)
        .setUserPassword(pwd)
        .setSslMode(SslMode.REQUIRED)
        .setSslClientCertificateKeyStorePath(store)
        .setSslClientCertificateKeyStoreType("JKS")
        .setSslClientCertificateKeyStorePassword(sslPwd)
        .setSslTrustCertificateKeyStorePath(store)
        .setSslTrustCertificateKeyStoreType("JKS")
        .setSslTrustCertificateKeyStorePassword(sslPwd)
        .setSslKeyAlgorithm("SunX509")
        .setSslTrustAll(false)
        .setSslProtocol(SslProtocol.TLS);

try (IgniteClient igniteClient = Ignition.startClient(cfg)) {
    final String CACHE_NAME = "put-get-example";

    ClientCache<Integer, String> cache = igniteClient.getOrCreateCache(CACHE_NAME);

    System.out.format(">>> Created cache [%s].\n", CACHE_NAME);

    Integer key = 1;
    String val = "Hello";

    cache.put(key, val);

    System.out.format(">>> Saved [%s] in the cache.\n", val);

    String cachedVal = cache.get(key);

    System.out.format(">>> Loaded [%s] from the cache.\n", cachedVal);
}
catch (Exception e) {
    System.err.format("Unexpected failure: %s\n", e);

    e.printStackTrace();
}

.NET Thin Client

NET applications can use the .NET thin client API to connect to the cluster running on GridGain Cloud.

To use this API:

  • Install .NET Thin Client dependencies.

  • Download the SSL Certificate named client.pfx from the Cluster Info dialog. Then, in your code, set the cluster address - host and port, username, password, as well as SSL certificate information in IgniteClientConfiguration.

  • Provide this configuration in the Ignition.StartClient(ClientConfiguration) method to establish a secure connection to the cluster and obtain an instance of ICacheClient.

Here is an example code snippet:

IgniteClientConfiguration cfg = new IgniteClientConfiguration()
{
    Host = "18.144.56.147", // Provide actual thin client host address from the "Cluster Info" dialog.
    Port = 9790, // Provide actual thin client port from the "Cluster Info" dialog.
    Username = "ignite", // This is a pre-defined username provided by GG Cloud.
    Password = "myclusterpassword", // Provide actual cluster password from the "Cluster Info" dialog.

    SslStreamFactory = new SslStreamFactory
    {
        CertificatePath = @"C:\path\to\client.pfx", // Provide the path where the file is stored after downloading from GG Cloud.
        CertificatePassword = "jb5GtvpSfWVjQZ84T1ud", // Provide actual SSL password from the "Cluster Info" dialog.
        SkipServerCertificateValidation = true
    }
};

using (var cli = Ignition.StartClient(cfg))
{
    ICacheClient<Int32, String> cache = cli.GetOrCreateCache<Int32, String>("myCache");

    Console.WriteLine(">>> Created cache");

    cache.Put(1, "Hello");

    Console.WriteLine(">>> Saved value to cache");

    String val = cache.Get(1);

    Console.WriteLine(">>> Loaded value from cache: " + val);

    cli.DestroyCache("myCache");
}

C++ Thin Client

C applications can use the C thin client API to connect to the cluster running on GridGain Cloud. To use this API:

  • Follow the C++ Thin Client installation instructions.

  • Download the SSL Certificate named client.pem from the Cluster Info dialog. Then, in your code, set the cluster address - host and port, username, password, as well as SSL certificate information in IgniteClientConfiguration.

  • Provide this configuration in the IgnitionClient.Start(ClientConfiguration) method to establish a secure connection to the cluster and obtain an instance of ICacheClient.

Here is an example code snippet:

int main()
{
    using namespace ignite::thin;
    using namespace boost::chrono;

    IgniteClientConfiguration cfg;
    cfg.SetEndPoints("[CONNECTION_STRING]");
    cfg.SetSslMode(SslMode::REQUIRE);
    cfg.SetSslCertFile("/path/to/SSL/client.pem"); // Provide the path where the file is stored after downloading from GG Cloud.
    cfg.SetSslCaFile("/path/to/SSL/client.pem");
    cfg.SetSslKeyFile("/path/to/SSL/client.pem");
    cfg.SetUser("ignite"); // This is a pre-defined username provided by GG Cloud.
    cfg.SetPassword("myclusterpassword"); // Provide actual cluster password from the "Cluster Info" dialog.

    int retcode = 0;

    try
    {
        IgniteClient client = IgniteClient::Start(cfg);
        cache::CacheClient<int32_t, int32_t> intCache = client.GetOrCreateCache<int32_t, int32_t>("test");

        intCache.Put(1, 1);

    }
    catch (const ignite::IgniteError& err)
    {
        std::cout << err.GetText() << std::endl;

        retcode = err.GetCode();
    }
    catch (const std::exception& err)
    {
        std::cout << err.what() << std::endl;

        retcode = -1;
    }

    std::cout << std::endl;
    std::cout << std::endl;

    return retcode;
}

Python Thin Client

Python applications can use the Python thin client API to connect to the cluster running on GridGain Cloud. To use this API:

  • Install the Python Thin client as explained here.

  • Download the SSL Certificate named client.pem from the Cluster Info dialog. In your code, set the cluster address - host and port, username, password, as well as SSL certificate information in Client and establish a secure connection to the cluster.

Here is an example code snippet:

from pyignite import Client

client = Client(
    username='ignite', # This is a pre-defined username provided by GG Cloud.
    Password = "myclusterpassword", # Provide actual cluster password from the "Cluster Info" dialog.
    use_ssl=True,
    ssl_keyfile='/path/to/SSL/client.pem', # Provide the path where the file is stored after downloading from GG Cloud.
    ssl_certfile='/path/to/SSL/client.pem'
)
client.connect('13.57.50.182', 9490) # Provide actual thinClient address from the "Cluster Info" dialog.

my_cache = client.create_cache('myCache')

my_cache.put('my key', 42)

result = my_cache.get('my key')
print(result)

PHP Thin Client

PHP applications can use PHP thin client API to connect to the cluster running on GridGain Cloud. To use this API:

  • Follow the PHP Thin Client installation instructions.

  • Download the SSL Certificate named client.pem from the Cluster Info dialog.

  • In your code, set the cluster address - host and port, username, password, as well as SSL certificate information in ClientConfiguration and establish a secure connection to the cluster.

Here is an example code snippet:

<?php

require_once '/src/vendor/autoload.php';

use Apache\Ignite\Client;
use Apache\Ignite\ClientConfiguration;

class PhpBench
{
    public function start(): void
    {
        $client = new Client();
        $client->connect(new ClientConfiguration("CONNECTION_STRING"));
        $tlsOptions = [
            'local_cert' => '/path/to/SSL/client.pem', // Provide the path where the file is stored after downloading from GG Cloud.
            'cafile' => '/path/to/SSL/client.pem',
            'verify_peer' => false, // This is a workaround; shouldn't be used in production
            'verify_peer_name' => false // This is a workaround; shouldn't be used in production
        ];
        $config = (new ClientConfiguration("CONNECTION_STRING"))
                ->setUserName("ignite") // This is a pre-defined username provided by GG Cloud.
                ->setPassword("myclusterpassword") // Provide actual cluster password from the "Cluster Info" dialog.
                ->setTLSOptions($tlsOptions);

        $client->connect($config);
        $cache = $client->getOrCreateCache("myCache");
        $cache->put(1, 1);
    }
}

(new PhpBench())->start();

Node.JS Thin Client

Node.JS applications can use Node.JS thin client API to connect to the cluster running on GridGain Cloud. To use this API:

  • Follow the Node.JS Thin Client installation instructions.

  • Download the SSL Certificate named client.pem from the Cluster Info dialog.

  • In your code, set the cluster address - host and port, username, password, as well as SSL certificate information in IgniteClientConfiguration and establish a secure connection to the cluster.

Here is an example code snippet:

const FS = require('fs');

IgniteClient = require('apache-ignite-client');
IgniteClientConfiguration = IgniteClient.IgniteClientConfiguration;

igniteClient = new IgniteClient();

async function start() {
   const connectionOptions = {
       'cert' : FS.readFileSync('/path/to/SSL/client.pem'),
       'ca' : FS.readFileSync('/path/to/SSL/client.pem'),
       'key' : FS.readFileSync('/path/to/SSL/client.pem'),
       'rejectUnauthorized': false
    };

    await igniteClient.connect(new IgniteClientConfiguration("[CONNECTION_STRING]")
        .setUserName("ignite") // This is a pre-defined username provided by GG Cloud.
        .setPassword("myclusterpassword") // Provide actual cluster password from the "Cluster Info" dialog.
        .setConnectionOptions(true, connectionOptions));
    setTimeout(run, 7);
}

async function run() {
    cache = await igniteClient.getOrCreateCache("test");
    await cache.put(1, 1);
}
start();