Chapter 75. Microsoft SQL Server Sink
Send data to a Microsoft SQL Server Database.
In your Pipe file, you must explicitly declare the SQL Server driver dependency in spec→integration→dependencies:
- "mvn:com.microsoft.sqlserver:mssql-jdbc:<version>"
This Kamelet expects a JSON-formatted body. Use key:value pairs to map the JSON fields and parameters. For example, here is a query:
'INSERT INTO accounts (username,city) VALUES (:#username,:#city)'
Here is example input for the example query:
'{ "username":"oscerd", "city":"Rome"}'
75.1. Configuration Options Copy linkLink copied to clipboard!
The following table summarizes the configuration options available for the sqlserver-sink Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
| databaseName * | Database Name | The name of the SQL Server Database. | string | ||
| password * | Password | The password to access a secured SQL Server Database. | string | ||
| query * | Query | The query to execute against the SQL Server Database. | string | INSERT INTO accounts (username,city) VALUES (:#username,:#city) | |
| serverName * | Server Name | The server name for the data source. | string | localhost | |
| username * | Username | The username to access a secured SQL Server Database. | string | ||
| encrypt | Encrypt Connection | Encrypt the connection to SQL Server. | boolean | False | |
| serverPort | Server Port | The server port for the data source. | string | 1433 | |
| trustServerCertificate | Trust Server Certificate | Trust Server Certificate | boolean | True |
* = Fields marked with an asterisk are mandatory.
75.2. Dependencies Copy linkLink copied to clipboard!
75.2.1. Quarkus dependencies Copy linkLink copied to clipboard!
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifact>camel-quarkus-jackson</artifact>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifact>camel-quarkus-kamelet</artifact>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifact>camel-quarkus-sql</artifact>
</dependency>
<dependency>
<groupId>org.apache.camel.kamelets</groupId>
<artifact>camel-kamelets-utils</artifact>
<version>4.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifact>commons-dbcp2</artifact>
<version>2.13.0</version>
</dependency>
</dependencies>
75.3. Usage Copy linkLink copied to clipboard!
75.3.1. Camel JBang usage Copy linkLink copied to clipboard!
75.3.1.1. Prerequisites for JBang Copy linkLink copied to clipboard!
- Install JBang.
You have executed the following command:
jbang app install camel@apache/camel
75.3.1.2. Running a route with JBang Copy linkLink copied to clipboard!
Suppose you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:timer-source"
parameters:
period: 10000
message: 'test'
steps:
- to:
uri: "kamelet:log-sink"
You can now run it directly through the following command.
camel run route.yaml
75.3.2. Knative Sink Copy linkLink copied to clipboard!
You can use the sqlserver-sink Kamelet as a Knative sink by binding it to a Knative object.
sqlserver-sink-binding.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: sqlserver-sink-binding
spec:
source:
ref:
kind: Channel
apiVersion: messaging.knative.dev/v1
name: mychannel
sink:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: sqlserver-sink
properties:
databaseName: "The Database Name"
password: "The Password"
query: "INSERT INTO accounts (username,city) VALUES (:#username,:#city)"
serverName: "localhost"
username: "The Username"
75.3.3. Kafka Sink Copy linkLink copied to clipboard!
You can use the sqlserver-sink Kamelet as a Kafka sink by binding it to a Kafka topic.
sqlserver-sink-binding.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: sqlserver-sink-binding
spec:
source:
ref:
kind: KafkaTopic
apiVersion: kafka.strimzi.io/v1beta1
name: my-topic
sink:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: sqlserver-sink
properties:
databaseName: "The Database Name"
password: "The Password"
query: "INSERT INTO accounts (username,city) VALUES (:#username,:#city)"
serverName: "localhost"
username: "The Username"