You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/integrations/data-ingestion/dbms/jdbc-with-clickhouse.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ description: 'The ClickHouse JDBC Bridge allows ClickHouse to access data from a
7
7
title: 'Connecting ClickHouse to external data sources with JDBC'
8
8
---
9
9
10
+
import Image from '@theme/IdealImage';
10
11
import Tabs from '@theme/Tabs';
11
12
import TabItem from '@theme/TabItem';
12
13
import Jdbc01 from '@site/static/images/integrations/data-ingestion/dbms/jdbc-01.png';
@@ -21,7 +22,7 @@ Using JDBC requires the ClickHouse JDBC bridge, so you will need to use `clickho
21
22
22
23
**Overview:** The <ahref="https://github.com/ClickHouse/clickhouse-jdbc-bridge"target="_blank">ClickHouse JDBC Bridge</a> in combination with the [jdbc table function](/sql-reference/table-functions/jdbc.md) or the [JDBC table engine](/engines/table-engines/integrations/jdbc.md) allows ClickHouse to access data from any external data source for which a <ahref="https://en.wikipedia.org/wiki/JDBC_driver"target="_blank">JDBC driver</a> is available:
This is handy when there is no native built-in [integration engine](/engines/table-engines/integrations), table function, or external dictionary for the external data source available, but a JDBC driver for the data source exists.
26
27
27
28
You can use the ClickHouse JDBC Bridge for both reads and writes. And in parallel for multiple external data sources, e.g. you can run distributed queries on ClickHouse across multiple external and internal data sources in real time.
@@ -41,7 +42,7 @@ You have access to a machine that has:
41
42
42
43
## Install the ClickHouse JDBC Bridge locally {#install-the-clickhouse-jdbc-bridge-locally}
43
44
44
-
The easiest way to use the ClickHouse JDBC Bridge is to install and run it on the same host where also ClickHouse is running:<imgsrc={Jdbc02}class="image"alt="ClickHouse JDBC Bridge locally"/>
45
+
The easiest way to use the ClickHouse JDBC Bridge is to install and run it on the same host where also ClickHouse is running:<Imageimg={Jdbc02}size="lg"alt="ClickHouse JDBC Bridge locally deployment diagram"background='white'/>
45
46
46
47
Let's start by connecting to the Unix shell on the machine where ClickHouse is running and create a local folder where we will later install the ClickHouse JDBC Bridge into (feel free to name the folder anything you like and put it anywhere you like):
47
48
```bash
@@ -142,7 +143,7 @@ As the first parameter for the jdbc table function we are using the name of the
142
143
## Install the ClickHouse JDBC Bridge externally {#install-the-clickhouse-jdbc-bridge-externally}
143
144
144
145
For a distributed ClickHouse cluster (a cluster with more than one ClickHouse host) it makes sense to install and run the ClickHouse JDBC Bridge externally on its own host:
This has the advantage that each ClickHouse host can access the JDBC Bridge. Otherwise the JDBC Bridge would need to be installed locally for each ClickHouse instance that is supposed to access external data sources via the Bridge.
147
148
148
149
In order to install the ClickHouse JDBC Bridge externally, we do the following steps:
Copy file name to clipboardExpand all lines: docs/integrations/data-ingestion/emqx/index.md
+37-36Lines changed: 37 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,7 @@ import mqttx_new from '@site/static/images/integrations/data-ingestion/emqx/mqtt
32
32
import mqttx_publish from '@site/static/images/integrations/data-ingestion/emqx/mqttx-publish.png';
33
33
import rule_monitor from '@site/static/images/integrations/data-ingestion/emqx/rule_monitor.png';
34
34
import clickhouse_result from '@site/static/images/integrations/data-ingestion/emqx/clickhouse_result.png';
35
+
import Image from '@theme/IdealImage';
35
36
36
37
# Integrating EMQX with ClickHouse
37
38
@@ -43,7 +44,7 @@ import clickhouse_result from '@site/static/images/integrations/data-ingestion/e
43
44
44
45
With the infrastructure provided by cloud providers, EMQX Cloud serves dozens of countries and regions around the world, providing low-cost, secure, and reliable cloud services for 5G and Internet of Everything applications.
@@ -53,27 +54,27 @@ With the infrastructure provided by cloud providers, EMQX Cloud serves dozens of
53
54
* We are using [MQTT X](https://mqttx.app/) as an MQTT client testing tool to connect the deployment of EMQX Cloud to publish MQTT data. Or other methods connecting to the MQTT broker will do the job as well.
54
55
55
56
56
-
## Get Your ClickHouse CloudService {#get-your-clickhouse-cloudservice}
57
+
## Get Your ClickHouse CloudService {#get-your-clickhouse-cloudservice}
57
58
58
59
During this setup, we deployed the ClickHouse instance on AWS in N. Virginia (us-east -1), while an EMQX Cloud instance was also deployed in the same region.
59
60
60
-
<imgsrc={clickhouse_cloud_1}alt="ClickHouse Cloud Service Deployment" />
61
+
<Imageimg={clickhouse_cloud_1}size="sm"borderalt="ClickHouse Cloud Service Deployment interface showing AWS region selection" />
61
62
62
63
During the setup process, you will also need to pay attention to the connection settings. In this tutorial, we choose "Anywhere", but if you apply for a specific location, you will need to add the [NAT gateway](https://docs.emqx.com/en/cloud/latest/vas/nat-gateway.html) IP address you got from your EMQX Cloud deployment to the whitelist.
You can refer to the following SQL statement, or modify the SQL according to the actual situation.
79
80
@@ -90,7 +91,7 @@ ENGINE = MergeTree()
90
91
PRIMARY KEY (client_id, timestamp)
91
92
```
92
93
93
-
<imgsrc={clickhouse_cloud_6}alt="ClickHouse Cloud Create Database and Table" />
94
+
<Imageimg={clickhouse_cloud_6}size="lg"borderalt="ClickHouse Cloud Create Database and Table SQL query execution" />
94
95
95
96
## Create an MQTT service on EMQX Cloud {#create-an-mqtt-service-on-emqx-cloud}
96
97
@@ -102,41 +103,41 @@ EMQX Cloud provides a 14-day free trial for both standard deployment and profess
102
103
103
104
Start at the [EMQX Cloud sign up](https://accounts.emqx.com/signup?continue=https%3A%2F%2Fwww.emqx.com%2Fen%2Fcloud) page and click start free to register an account if you are new to EMQX Cloud.
In this tutorial, we will use the Professional deployment because only Pro version provides the data integration functionality, which can send MQTT data directly to ClickHouse without a single line of code.
114
115
115
-
Select Pro version and choose `N.Virginial` region and click `Create Now`. In justa few minutes, you will get a fully managed MQTT broker:
116
+
Select Pro version and choose `N.Virginial` region and click `Create Now`. In justa few minutes, you will get a fully managed MQTT broker:
EMQX Cloud does not allow anonymous connections by default,so you need add a client credential so you can use the MQTT client tool to send data to this broker.
126
127
127
128
Click ‘Authentication & ACL’ on the left menu and click ‘Authentication’ in the submenu. Click the ‘Add’ button on the right and give a username and password for the MQTT connection later. Here we will use `emqx` and `xxxxxx` for the username and password.
<Imageimg={emqx_cloud_auth}size="lg"borderalt="EMQX Cloud Authentication Setup interface for adding credentials" />
130
131
131
-
Click ‘Confirm’ and now we have a fully managed MQTT broker ready.
132
+
Click 'Confirm' and now we have a fully managed MQTT broker ready.
132
133
133
134
### Enable NAT gateway {#enable-nat-gateway}
134
135
135
136
Before we can start setting up the ClickHouse integration, we need to enable the NAT gateway first. By default, the MQTT broker is deployed in a private VPC, which can not send data to third-party systems over the public network.
136
137
137
138
Go back to the Overview page and scroll down to the bottom of the page where you will see the NAT gateway widget. Click the Subscribe button and follow the instructions. Note that NAT Gateway is a value-added service, but it also offers a 14-day free trial.
Once it has been created, you will find the public IP address in the widget. Please note that if you select "Connect from a specific location" during ClickHouse Cloud setup, you will need to add this IP address to the whitelist.
142
143
@@ -145,11 +146,11 @@ Once it has been created, you will find the public IP address in the widget. Ple
145
146
146
147
The [EMQX Cloud Data Integrations](https://docs.emqx.com/en/cloud/latest/rule_engine/introduction.html#general-flow) is used to configure the rules for handling and responding to EMQX message flows and device events. The Data Integrations not only provides a clear and flexible "configurable" architecture solution, but also simplifies the development process, improves user usability, and reduces the coupling degree between the business system and EMQX Cloud. It also provides a superior infrastructure for customization of EMQX Cloud's proprietary capabilities.
147
148
148
-
<imgsrc={emqx_cloud_data_integration}alt="EMQX Cloud Data Integration Options" />
149
+
<Imageimg={emqx_cloud_data_integration}size="lg"borderalt="EMQX Cloud Data Integration Options showing available connectors" />
149
150
150
151
EMQX Cloud offers more than 30 native integrations with popular data systems. ClickHouse is one of them.
151
152
152
-
<imgsrc={data_integration_clickhouse}alt="EMQX Cloud ClickHouse Data Integration" />
153
+
<Imageimg={data_integration_clickhouse}size="lg"borderalt="EMQX Cloud ClickHouse Data Integration connector details" />
<Imageimg={data_integration_resource}size="lg"borderalt="EMQX Cloud ClickHouse Resource Setup form with connection details" />
167
168
168
169
### Create A New Rule {#create-a-new-rule}
169
170
170
-
During the creation of the resource, you will see a popup, and clicking ‘New’ will leads you to the rule creation page.
171
+
During the creation of the resource, you will see a popup, and clicking 'New' will leads you to the rule creation page.
171
172
172
173
EMQX provides a powerful [rule engine](https://docs.emqx.com/en/cloud/latest/rule_engine/rules.html) that can transform, and enrich the raw MQTT message before sending it to third-party systems.
173
174
174
-
Here’s the rule used in this tutorial:
175
+
Here's the rule used in this tutorial:
175
176
176
177
```sql
177
178
SELECT
@@ -192,11 +193,11 @@ So, the raw JSON you send to the topic:
192
193
{"temp": 28.5, "hum": 0.68}
193
194
```
194
195
195
-
<imgsrc={data_integration_rule_1}alt="EMQX Cloud Data Integration Rule Creation Step 1" />
<imgsrc={data_integration_rule_action}alt="EMQX Cloud Data Integration Rule Action Setup" />
213
+
<Imageimg={data_integration_rule_action}size="md"borderalt="EMQX Cloud Data Integration Rule Action Setup with SQL template" />
213
214
214
215
This is a template for inserting data into Clickhouse, you can see the variables are used here.
215
216
216
217
### View Rules Details {#view-rules-details}
217
218
218
219
Click "Confirm" and "View Details". Now, everything should be well set. You can see the data integration works from rule details page.
219
220
220
-
<imgsrc={data_integration_details}alt="EMQX Cloud Data Integration Rule Details" />
221
+
<Imageimg={data_integration_details}size="md"borderalt="EMQX Cloud Data Integration Rule Details showing configuration summary" />
221
222
222
223
All the MQTT messages sent to the `temp_hum/emqx` topic will be persisted into your ClickHouse Cloud database.
223
224
224
225
## Saving Data into ClickHouse {#saving-data-into-clickhouse}
225
226
226
227
We will simulate temperature and humidity data and report these data to EMQX Cloud via the MQTT X and then use the EMQX Cloud Data Integrations to save the data into ClickHouse Cloud.
227
228
228
-
<imgsrc={work_flow}alt="EMQX Cloud to ClickHouse Workflow" />
229
+
<Imageimg={work_flow}size="lg"borderalt="EMQX Cloud to ClickHouse Workflow diagram showing data flow" />
229
230
230
231
### Publish MQTT messages to EMQX Cloud {#publish-mqtt-messages-to-emqx-cloud}
231
232
232
233
You can use any MQTT client or SDK to publish the message. In this tutorial, we will use [MQTT X](https://mqttx.app/), a user friendly MQTT client application provided by EMQ.
233
234
234
-
<imgsrc={mqttx_overview}alt="MQTTX Overview" />
235
+
<Imageimg={mqttx_overview}size="lg"borderalt="MQTTX Overview showing the client interface" />
235
236
236
237
Click "New Connection" on MQTTX and fill the connection form:
237
238
@@ -240,15 +241,15 @@ Click "New Connection" on MQTTX and fill the connection form:
240
241
- Port: MQTT broker connection port. You can get it from the EMQX Cloud overview page.
241
242
- Username/Password: Use the credential created above, which should be `emqx` and `xxxxxx` in this tutorial.
242
243
243
-
<imgsrc={mqttx_new}alt="MQTTX New Connection Setup" />
244
+
<Imageimg={mqttx_new}size="lg"borderalt="MQTTX New Connection Setup form with connection details" />
244
245
245
246
Click the "Connect" button on top right and the connection should be established.
246
247
247
248
Now you can send messages to the MQTT broker using this tool.
248
249
Inputs:
249
-
1.Set payload format to "JSON".
250
-
2.Set to topic: `temp_hum/emqx` (the topic we just set in the rule)
251
-
3.JSON body:
250
+
1.Set payload format to "JSON".
251
+
2.Set to topic: `temp_hum/emqx` (the topic we just set in the rule)
252
+
3.JSON body:
252
253
253
254
```bash
254
255
{"temp": 23.1, "hum": 0.68}
@@ -258,17 +259,17 @@ Click the send button on the right. You can change the temperature value and sen
258
259
259
260
The data sent to EMQX Cloud should be processed by the rule engine and inserted into ClickHouse Cloud automatically.
### Check the data persisted {#check-the-data-persisted}
270
271
271
-
Now it’s time to take a look at the data on the ClickHouse Cloud. Ideally, the data you send using MQTTX will go to the EMQX Cloud and persist to the ClickHouse Cloud’s database with the help of native data integration.
272
+
Now it's time to take a look at the data on the ClickHouse Cloud. Ideally, the data you send using MQTTX will go to the EMQX Cloud and persist to the ClickHouse Cloud's database with the help of native data integration.
272
273
273
274
You can connect to the SQL console on ClickHouse Cloud panel or use any client tool to fetch data from your ClickHouse. In this tutorial, we used the SQL console.
0 commit comments