Confluent HTTP sink connector

[Edit this page](https://github.com/ClickHouse/clickhouse-docs/blob/main/docs/integrations/data-ingestion/kafka/confluent/kafka-connect-http.md)

The HTTP Sink Connector is data type agnostic and thus doesn't need a Kafka schema as well as supporting ClickHouse specific data types such as Maps and Arrays. This additional flexibility comes at a slight increase in configuration complexity.

Below we describe a simple installation, pulling messages from a single Kafka topic and inserting rows into a ClickHouse table.

Note

The HTTP Connector is distributed under the [Confluent Enterprise License](https://docs.confluent.io/kafka-connect-http/current/overview.html#license).

### Quick start steps[​](#quick-start-steps "Direct link to Quick start steps")

#### 1. Gather your connection details[​](#1-gather-your-connection-details "Direct link to 1. Gather your connection details")

To connect to ClickHouse with HTTP(S) you need this information:

|  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Parameter(s) Description|  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | | `HOST` and `PORT` Typically, the port is 8443 when using TLS or 8123 when not using TLS.|  |  |  |  | | --- | --- | --- | --- | | `DATABASE NAME` Out of the box, there is a database named `default`, use the name of the database that you want to connect to.| `USERNAME` and `PASSWORD` Out of the box, the username is `default`. Use the username appropriate for your use case. | | | | | | | |

The details for your ClickHouse Cloud service are available in the ClickHouse Cloud console.
Select a service and click **Connect**:

Choose **HTTPS**. Connection details are displayed in an example `curl` command.

If you're using self-managed ClickHouse, the connection details are set by your ClickHouse administrator.

#### 2. Run Kafka Connect and the HTTP sink connector[​](#2-run-kafka-connect-and-the-http-sink-connector "Direct link to 2. Run Kafka Connect and the HTTP sink connector")

You have two options:

- **Self-managed:** Download the Confluent package and install it locally. Follow the installation instructions for installing the connector as documented [here](https://docs.confluent.io/kafka-connect-http/current/overview.html).
  If you use the confluent-hub installation method, your local configuration files will be updated.
- **Confluent Cloud:** A fully managed version of HTTP Sink is available for those using Confluent Cloud for their Kafka hosting. This requires your ClickHouse environment to be accessible from Confluent Cloud.

Note

The following examples are using Confluent Cloud.

#### 3. Create destination table in ClickHouse[​](#3-create-destination-table-in-clickhouse "Direct link to 3. Create destination table in ClickHouse")

Before the connectivity test, let's start by creating a test table in ClickHouse Cloud, this table will receive the data from Kafka:

```
CREATE TABLE default.my_table
(
    `side` String,
    `quantity` Int32,
    `symbol` String,
    `price` Int32,
    `account` String,
    `userid` String
)
ORDER BY tuple()
```

#### 4. Configure HTTP Sink[​](#4-configure-http-sink "Direct link to 4. Configure HTTP Sink")

Create a Kafka topic and an instance of HTTP Sink Connector:

  

Configure HTTP Sink Connector:

- Provide the topic name you created
- Authentication
  - `HTTP Url` - ClickHouse Cloud URL with a `INSERT` query specified `<protocol>://<clickhouse_host>:<clickhouse_port>?query=INSERT%20INTO%20<database>.<table>%20FORMAT%20JSONEachRow`. **Note**: the query must be encoded.
  - `Endpoint Authentication type` - BASIC
  - `Auth username` - ClickHouse username
  - `Auth password` - ClickHouse password

Note

This HTTP Url is error-prone. Ensure escaping is precise to avoid issues.

  

- Configuration
  - `Input Kafka record value format`Depends on your source data but in most cases JSON or Avro. We assume `JSON` in the following settings.
  - In `advanced configurations` section:
    - `HTTP Request Method` - Set to POST
    - `Request Body Format` - json
    - `Batch batch size` - Per ClickHouse recommendations, set this to **at least 1000**.
    - `Batch json as array` - true
    - `Retry on HTTP codes` - 400-500 but adapt as required e.g. this may change if you have an HTTP proxy in front of ClickHouse.
    - `Maximum Reties` - the default (10) is appropriate but feel to adjust for more robust retries.

#### 5. Testing the connectivity[​](#5-testing-the-connectivity "Direct link to 5. Testing the connectivity")

Create an message in a topic configured by your HTTP Sink

  

and verify the created message's been written to your ClickHouse instance.

### Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting")

#### HTTP Sink doesn't batch messages[​](#http-sink-doesnt-batch-messages "Direct link to HTTP Sink doesn't batch messages")

From the [Sink documentation](https://docs.confluent.io/kafka-connectors/http/current/overview.html#http-sink-connector-for-cp):

> The HTTP Sink connector doesn't batch requests for messages containing Kafka header values that are different.

1. Verify your Kafka records have the same key.
2. When you add parameters to the HTTP API URL, each record can result in a unique URL. For this reason, batching is disabled when using additional URL parameters.

#### 400 bad request[​](#400-bad-request "Direct link to 400 bad request")

##### CANNOT\_PARSE\_QUOTED\_STRING[​](#cannot_parse_quoted_string "Direct link to CANNOT_PARSE_QUOTED_STRING")

If HTTP Sink fails with the following message when inserting a JSON object into a `String` column:

```
Code: 26. DB::ParsingException: Cannot parse JSON string: expected opening quote: (while reading the value of key key_name): While executing JSONEachRowRowInputFormat: (at row 1). (CANNOT_PARSE_QUOTED_STRING)
```

Set `input_format_json_read_objects_as_strings=1` setting in URL as encoded string `SETTINGS%20input_format_json_read_objects_as_strings%3D1`

### Load the GitHub dataset (optional)[​](#load-the-github-dataset-optional "Direct link to Load the GitHub dataset (optional)")

Note that this example preserves the Array fields of the Github dataset. We assume you have an empty github topic in the examples and use [kcat](https://github.com/edenhill/kcat) for message insertion to Kafka.

##### 1. Prepare configuration[​](#1-prepare-configuration "Direct link to 1. Prepare configuration")

Follow [these instructions](https://docs.confluent.io/cloud/current/cp-component/connect-cloud-config.html#set-up-a-local-connect-worker-with-cp-install) for setting up Connect relevant to your installation type, noting the differences between a standalone and distributed cluster. If using Confluent Cloud, the distributed setup is relevant.

The most important parameter is the `http.api.url`. The [HTTP interface](/docs/interfaces/http) for ClickHouse requires you to encode the INSERT statement as a parameter in the URL. This must include the format (`JSONEachRow` in this case) and target database. The format must be consistent with the Kafka data, which will be converted to a string in the HTTP payload. These parameters must be URL escaped. An example of this format for the Github dataset (assuming you're running ClickHouse locally) is shown below:

```
<protocol>://<clickhouse_host>:<clickhouse_port>?query=INSERT%20INTO%20<database>.<table>%20FORMAT%20JSONEachRow

http://localhost:8123?query=INSERT%20INTO%20default.github%20FORMAT%20JSONEachRow
```

The following additional parameters are relevant to using the HTTP Sink with ClickHouse. A complete parameter list can be found [here](https://docs.confluent.io/kafka-connect-http/current/connector_config.html):