Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Kurrent Docs
or

Getting started


Getting started

Get started by connecting your application to KurrentDB.

Connecting to KurrentDB

For your application to start communicating with KurrentDB, you need to instantiate the client and configure it accordingly. Below are instructions for supported SDKs.

Insecure clusters

All our GRPC clients are secure by default and must be configured to connect to an insecure server viaa connection string or the client's configuration.

Required packages

Install the client SDK package to your project.

Python

Install thekurrentdbclient package from PyPI or use Poetry:

pip
pip install kurrentdbclient

NodeJS

Install the@kurrent/kurrentdb-client package using NPM, Yarn or PNPM:

npm
npm install --save @kurrent/kurrentdb-client

TypeScript Declarations are included in the package.

Java

Add thekurrentdb-client dependency to your Maven or Gradle project.

Maven
<dependency>  <groupId>io.kurrent</groupId>  <artifactId>kurrentdb-client</artifactId>  <version>1.0.0</version></dependency>

.NET

Add theKurrentDB.Client package to your project:

dotnet add package KurrentDB.Client

Go

Install thekurrentdb package using Go modules:

go get github.com/kurrent-io/KurrentDB-Client-Go/kurrentdb

Rust

No additional configuration is needed having Rust installed. Go checkhttps://rustup.rs.

Connection string

Each SDK has its own way of configuring the client, but the connection string can always be used. The KurrentDB connection string supports two schemas:kurrentdb:// for connecting to a single-node server, andkurrentdb+discover:// for connecting to a multi-node cluster. The difference between the two schemas is that when usingkurrentdb://, the client will connect directly to the node; withkurrentdb+discover:// schema the client will use the gossip protocol to retrieve the cluster information and choose the right node to connect to. Since version 22.10, ESDB supports gossip on single-node deployments, sokurrentdb+discover:// schema can be used for connecting to any topology.

The connection string has the following format:

kurrentdb+discover://admin:[email protected]:2113

There,cluster.dns.name is the name of a DNSA record that points to all the cluster nodes. Alternatively, you can list cluster nodes separated by comma instead of the cluster DNS name:

kurrentdb+discover://admin:[email protected]:2113,node2.dns.name:2113,node3.dns.name:2113

There are a number of query parameters that can be used in the connection string to instruct the cluster how and where the connection should be established. All query parameters are optional.

ParameterAccepted valuesDefaultDescription
tlstrue,falsetrueUse secure connection, set tofalse when connecting to a non-secure server or cluster.
connectionNameAny stringNoneConnection name
maxDiscoverAttemptsNumber10Number of attempts to discover the cluster.
discoveryIntervalNumber100Cluster discovery polling interval in milliseconds.
gossipTimeoutNumber5Gossip timeout in seconds, when the gossip call times out, it will be retried.
nodePreferenceleader,follower,random,readOnlyReplicaleaderPreferred node role. When creating a client for write operations, always useleader.
tlsVerifyCerttrue,falsetrueIn secure mode, set totrue when using an untrusted connection to the node if you don't have the CA file available. Don't use in production.
tlsCaFileString, file pathNonePath to the CA file when connecting to a secure cluster with a certificate that's not signed by a trusted CA.
defaultDeadlineNumberNoneDefault timeout for client operations, in milliseconds. Most clients allow overriding the deadline per operation.
keepAliveIntervalNumber10Interval between keep-alive ping calls, in seconds.
keepAliveTimeoutNumber10Keep-alive ping call timeout, in seconds.
userCertFileString, file pathNoneUser certificate file for X.509 authentication.
userKeyFileString, file pathNoneKey file for the user certificate used for X.509 authentication.

When connecting to an insecure instance, specifytls=false parameter. For example, for a node running locally usekurrentdb://localhost:2113?tls=false. Note that usernames and passwords aren't provided there because insecure deployments don't support authentication and authorisation.

Creating a client

First, create a client and get it connected to the database.

Python
client= KurrentDBClient(    uri=connection_string)

The client instance can be used as a singleton across the whole application. It doesn't need to open or close the connection.

Creating an event

You can write anything to KurrentDB as events. The client needs a byte array as the event payload. Normally, you'd use a serialized object, and it's up to you to choose the serialization method.

Server-side projections

User-defined server-side projections require events to be serialized in JSON format.

We use JSON for serialization in the documentation examples.

The code snippet below creates an event object instance, serializes it, and adds it as a payload to theEventData structure, which the client can then write to the database.

Python
new_event= NewEvent(    id=uuid4(),    type="TestEvent",    data=b"I wrote my first event",)

Appending events

Each event in the database has its own unique identifier (UUID). The database uses it to ensure idempotent writes, but it only works if you specify the stream revision when appending events to the stream.

In the snippet below, we append the event to the streamsome-stream.

Python
client.append_to_stream(    stream_name=stream_name,    events=[new_event],    current_version=StreamState.ANY,)

Here we are appending events without checking if the stream exists or if the stream version matches the expected event version. See more advanced scenarios inappending events documentation.

Reading events

Finally, we can read events back from thesome-stream stream.

Python
events= client.read_stream(stream_name)

When you read events from the stream, you get a collection ofResolvedEvent structures. The event payload is returned as a byte array and needs to be deserialized. See more advanced scenarios inreading events documentation.

Last Updated:

[8]ページ先頭

©2009-2025 Movatter.jp