Skip to content

Pulsar Sink

License Required

The Apache Pulsar Sink connector writes records from your KurrentDB stream to a specified Pulsar topic.

Before using the Pulsar sink connector, ensure you have:

  • A data protection token configured in your KurrentDB instance (required to encrypt sensitive fields like authentication tokens)
  • A Pulsar cluster with an accessible service URL
  • Appropriate authentication token if your Pulsar cluster requires authentication

Create the Pulsar sink with client.Connectors. Replace example-pulsar with your own connector id:

Dictionary<string, string> settings = new() {
["instanceTypeName"] = "pulsar-sink",
["topic"] = "customers",
["url"] = "pulsar://localhost:6650",
["subscription:filter:scope"] = "stream",
["subscription:filter:filterType"] = "streamId",
["subscription:filter:expression"] = "example-stream"
};
await client.Connectors.Create("example-pulsar", settings);
await client.Connectors.Start("example-pulsar");

Check the connector’s state with client.Connectors.List, or read the connector logs. Managing Connectors covers the rest of the lifecycle.

These settings control how the connector interacts with Pulsar, partitions messages, and stays resilient while handling them.

Name Details
topic required

Description:
The Pulsar topic that the connector publishes records to.
url Description:
The service URL for the Pulsar cluster.

Default: "pulsar://localhost:6650"
defaultHeaders Description:
Headers included in all produced messages.

Default: Empty
authentication:token Description:
A JSON web token for authenticating the connector with Pulsar.

Partitioning options determine how the connector assigns partition keys, which affect message routing and topic compaction.

Name Details
partitionKeyExtraction:enabled Description:
Enables partition key extraction.

Default: "false"
partitionKeyExtraction:source Description:
The source for extracting the partition key.

Accepted Values:"partitionKey", "stream", "streamSuffix", "headers"

Default: "partitionKey"
partitionKeyExtraction:expression Description:
A regex (for stream source) or a comma-separated list of header keys (for headers source) used to extract or combine values for the partition key. When using headers, values are concatenated with a hyphen (for example, value1-value2).

The Pulsar sink connector relies on its own retry mechanism and doesn’t include the configuration from Resilience configuration.

Name Details
resilience:enabled Description:
Enables resilience features for message handling.

Default: "true"
resilience:retryInterval Description:
Retry interval in seconds. Must be greater than 0.

Format: seconds or "HH:MM:SS".

Default: "00:00:03"

The Pulsar sink connector lets you include custom headers in the message headers it sends to your topic. To add custom headers, use the defaultHeaders setting in your connector configuration. Specify each custom header with the prefix defaultHeaders: followed by the header name.

Example:

{
"defaultHeaders:X-API-Key": "your-api-key-here",
"defaultHeaders:X-Tenant-ID": "production-tenant",
"defaultHeaders:X-Source-System": "KurrentDB"
}

The connector includes these headers in every message it sends, alongside the default headers its plugin adds automatically.

The Pulsar sink connector lets you customize the partition keys sent with the message.

partitionKeyExtraction:enabled defaults to "false", so the connector extracts no key unless you enable it. Without a key, Pulsar distributes messages round-robin across the available partitions in the topic.

Partition using Stream ID

You can extract part of the stream name using a regular expression (regex) to define the partition key. The expression is optional, and you can adapt it to your naming convention. In this example, the expression captures the stream name up to _data.

{
"partitionKeyExtraction:enabled": "true",
"partitionKeyExtraction:source": "stream",
"partitionKeyExtraction:expression": "^(.*)_data$"
}

Alternatively, if you need only the last segment of the stream name (after a hyphen), you can use the streamSuffix source. This doesn’t require an expression since it automatically extracts the suffix.

{
"partitionKeyExtraction:enabled": "true",
"partitionKeyExtraction:source": "streamSuffix"
}

The streamSuffix source is useful when stream names follow a structured format, and you want to use only the trailing part as the partition key. For example, if the stream is named user-123, the partition key is 123.

Partition using header values

You can create partition keys by combining values from a record’s metadata.

{
"partitionKeyExtraction:enabled": "true",
"partitionKeyExtraction:source": "headers",
"partitionKeyExtraction:expression": "key1,key2"
}

Specify the header keys you want to use in the partitionKeyExtraction:expression field (e.g., key1,key2). The connector concatenates the header values with a hyphen (-) to create the partition key.

For example, if your record has headers key1: regionA and key2: zone1, the partition key is regionA-zone1.