GridGain Developers Hub

Connecting to Your Cluster

You can connect to your cluster by using the following clients:

Java Thin Client

Java thin client is a lightweight client that connects to the cluster via a standard socket connection. It does not become a part of the cluster topology, never holds any data, and is not used as a destination for compute calculations. The thin client simply establishes a socket connection to a standard node​ and performs all operations through that node.

  1. Add the following dependencies to your Maven project:

    <repositories>
        <repository>
            <id>GridGain External Repository</id>
            <url>http://www.gridgainsystems.com/nexus/content/repositories/external</url>
        </repository>
    </repositories>
    
    <dependencies>
        <dependency>
            <groupId>org.gridgain</groupId>
            <artifactId>ignite-core</artifactId>
            <version>8.8.10</version>
        </dependency>
    </dependencies>
  2. Create client configuration: Replace the ${HIDDEN_LOGIN} and ${HIDDEN_PASSWORD} with your cluster credentials.

    ClientConfiguration cfg = new ClientConfiguration()
            .setAddresses("${connectionInfo?.urls[0]}:10800")
            .setUserName("${HIDDEN_LOGIN}")
            .setUserPassword("${HIDDEN_PASSWORD}")
            .setSslMode(SslMode.REQUIRED);
  3. Connect to the cluster.

    try (IgniteClient client = Ignition.startClient(cfg)) {
        // Use the API.
        ClientCache<Integer, String> cache =  client.getOrCreateCache(new ClientCacheConfiguration()
                .setName("Test")
                .setBackups(1)
        );
        cache.put(1, "foo");
        System.out.println(">>>    " + cache.get(1));
    }

For more information on thin clients, please see this article.

.NET Thin Client

Prerequisites:

  • Supported runtimes: .NET 4.0+, .NET Core 2.0+

  • Supported OS: Windows, Linux, macOS (any OS supported by .NET Core 2.0+)

    1. Install the GridGain package:

      dotnet add package GridGain --version 8.8.10
    2. Add the following class to your project:

      class SimpleSslStreamFactory : ISslStreamFactory {
          public SslStream Create(Stream stream, string targetHost)
          {
              var sslStream = new SslStream(stream, false, null, null);
              sslStream.AuthenticateAsClient(targetHost);
              return sslStream;
          }
      }

      This class is required to simplify SSL configuration on the client (compared to Apache.Ignite.Core.Client.SSLStreamFactory).

    3. Create client configuration: Replace the ${HIDDEN_LOGIN} and ${HIDDEN_PASSWORD} with your cluster credentials.

      var cfg = new IgniteClientConfiguration
      {
          Endpoints = new[] { "${connectionInfo?.urls[0]}:10800" },
          UserName = "${HIDDEN_LOGIN}",
          Password = "${HIDDEN_PASSWORD}",
          SslStreamFactory = new SimpleSslStreamFactory()
      };
    4. Connect to the cluster.

      using (var client = Ignition.StartClient(cfg))
      {
          // Use the API.
          var cache = client.GetOrCreateCache<int, string>(new CacheClientConfiguration("test") { Backups = 1 });
          cache.Put(1, "foo");
          Console.Out.WriteLine(">>>    " + cache.Get(1));
      }

For more information on .NET Thin Client, please see this article.

Python Thin Client

Please note the following client prerequisites: Python 3.4 or above.

Setting Up

You can install the Python thin client either using pip or from a zip archive.

Using PIP

The python thin client package is called pygridgain. You can install it using the following command:

pip3 install pygridgain
pip install pygridgain

Using ZIP Archive

The thin client can be installed from the zip archive available for download from the GridGain website:

  • Go to the website and download the GridGain Python Thin Client archive.

  • Unpack the archive and navigate to the root folder.

  • Install the client using the command below.

pip3 install .
pip install .

This will install pygridgain in your environment in the so-called "develop" or "editable" mode. Learn more about the mode from the official documentation.

After that, import the GridGain Python thin client:

from pygridgain import Client

Connecting to the Cluster

  1. Create client configuration: Replace the {login} and {password} with your cluster credentials.

    client = Client(username='{login}', password='{password}', use_ssl=True)
  2. Connect to the cluster.

    client.connect('${connectionInfo.urls?.[0]}', 10800)
  3. Use the API.

    my_cache = client.get_or_create_cache('test')
    my_cache.put(1, 'foo')
    result = my_cache.get(1)
    print(result)

For more information on Python Thin Client, please see this article.

Node.js Thin Client

Prerequisites: Node.js version 8 or higher.

  1. Install the GridGain package: npm install -g @gridgain/thin-client:

    const IgniteClient = require('@gridgain/thin-client');
    const IgniteClientConfiguration = IgniteClient.IgniteClientConfiguration;
    const ObjectType = IgniteClient.ObjectType;
    async function performCacheKeyValueOperations() {
  2. Create client configuration: Replace the ${HIDDEN_LOGIN} and ${HIDDEN_PASSWORD} with your cluster credentials.

    const igniteClientConfiguration = new IgniteClientConfiguration('${connectionInfo?.urls[0]}:10800').
        setUserName('${HIDDEN_LOGIN}').
        setPassword('${HIDDEN_PASSWORD}').
        setConnectionOptions(true);
      // Connect to the cluster.
      const igniteClient = new IgniteClient();
      try {
        await igniteClient.connect(igniteClientConfiguration);
        // Use the API.
        const cache = (await igniteClient.getOrCreateCache('test')).
                  setKeyType(ObjectType.PRIMITIVE_TYPE.INTEGER);
        await cache.put(1, 'foo');
        const value = await cache.get(1);
        console.log(value);
      }
      catch (err) {
        console.log(err.message);
      }
      finally {
        igniteClient.disconnect();
      }
    }

For more information on Node.js Thin Client, please see this article.

JDBC

GridGain is shipped with JDBC drivers that allow processing of distributed data using standard SQL statements like SELECT, INSERT, UPDATE or DELETE directly from the JDBC side.

  1. Open a JDBC connection: Replace the ${HIDDEN_LOGIN} and ${HIDDEN_PASSWORD} with your cluster credentials.

    try (Connection connection = DriverManager
        .getConnection("jdbc:ignite:thin://${connectionInfo?.urls[0]}:10800" +
        "?user=${HIDDEN_LOGIN}&password=${HIDDEN_PASSWORD}&sslMode=require")) {
  2. Use the API:

    try (Statement stmt = connection.createStatement()) {
        stmt.executeUpdate("CREATE TABLE IF NOT EXISTS person (id LONG PRIMARY KEY, name VARCHAR) WITH \"backups=1\"");
        stmt.execute("INSERT INTO person (id, name) VALUES (1, 'John Doe')");
        stmt.execute("INSERT INTO person (id, name) VALUES (2, 'Jane Doe')")
    
        try (ResultSet rs = stmt.executeQuery("SELECT id, name FROM person")) {
            while (rs.next())
                System.out.println(">>>    " + rs.getString(1) + ", " + rs.getString(2));
        }
    }

For more information on JDBC driver, please see this article.

Java Thick Client

Java thick client (client node) joins the cluster via an internal protocol, receives all of the cluster-wide updates such as topology changes, is aware of data distribution, and can direct a query/operation to a server node that owns a required data set. Plus, Java thick client supports all of the GridGain APIs.

  1. Add the following dependencies to your Maven project:

    <repositories>
        <repository>
            <id>GridGain External Repository</id>
            <url>http://www.gridgainsystems.com/nexus/content/repositories/external</url>
        </repository>
    </repositories>
    
    <dependencies>
        <dependency>
            <groupId>org.gridgain</groupId>
            <artifactId>gridgain-core</artifactId>
            <version>8.8.10</version>
        </dependency>
        <dependency>
            <groupId>org.gridgain</groupId>
            <artifactId>ignite-indexing</artifactId>
                <version>8.8.10</version>
            </dependency>
    </dependencies>
  2. Create client configuration: Replace the {login} and {password} with your cluster credentials.

    System.setProperty("IGNITE_EVENT_DRIVEN_SERVICE_PROCESSOR_ENABLED", "true");
    SecurityCredentials clientCredentials = new SecurityCredentials("{login}", "{password}");
    IgniteConfiguration cfg = new IgniteConfiguration()
            .setClientMode(true)
            .setDiscoverySpi(new TcpDiscoverySpi()
                    .setIpFinder(new TcpDiscoveryVmIpFinder()
                            .setAddresses(Collections.singleton(
                                    "${connectionInfo?.urls[0]}:47500"))))
            .setCommunicationSpi(new TcpCommunicationSpi()
                    .setForceClientToServerConnections(true))
            .setPluginConfigurations(new GridGainConfiguration()
                    .setSecurityCredentialsProvider(new SecurityCredentialsBasicProvider(clientCredentials))
                    .setRollingUpdatesEnabled(true))
            .setSslContextFactory(new SslContextFactory());
  3. Connect to the cluster.

    try (Ignite client = Ignition.start(cfg)) {
        // Use the API.
        IgniteCache<Integer, String> cache =  client.getOrCreateCache(new CacheConfiguration<Integer, String>()
            .setName("Test")
            .setBackups(1)
        );
        cache.put(1, "foo");
        System.out.println(">>>    " + cache.get(1));
    }

REST API

GridGain provides an HTTP REST client that gives you the ability to communicate with the grid over HTTP and HTTPS protocols using the REST approach.

Run the following to test your connection:

  1. Replace the {login} and {password} with your cluster credentials. The response will contain a sessionToken.

    curl "https://${connectionInfo.urls[0]}:8080/ignite?cmd=version&ignite.login={login}&ignite.password={password}"
  2. Use the sessionToken in subsequent requests to avoid authenticating every time.

    curl "https://${connectionInfo.urls[0]}:8080/ignite?cmd=version&sessionToken={sessionToken}"