curtisp
curtisp

Reputation: 2315

Debezium Connector for SQL Server - connection refused

I want to use Kafka to publish MSSQL CDC events.

I am using Docker containers for:

Containers started as follows:

docker run -it --name zookeeper -p 2181:2181 -p 2888:2888 -p 3888:3888 debezium/zookeeper

docker run -it --name kafka -p 9092:9092 --link zookeeper:zookeeper debezium/kafka

docker run -it --name connect -p 8083:8083 -e GROUP_ID=1 -e CONFIG_STORAGE_TOPIC=my-connect-configs -e OFFSET_STORAGE_TOPIC=my-connect-offsets -e ADVERTISED_HOST_NAME="localhost" --link zookeeper:zookeeper --link kafka:kafka debezium/connect

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=xxxxxxxxxxxxx" -p 1433:1433 --name sql1 -d mcr.microsoft.com/mssql/server:2017-CU8-ubuntu

All containers start running successfully.

Then I created new MSSQL db in SQL Server container. Created 1 table in new db and turned on CDC for that table. CDC is working fine.

Then I send connector configuration below to Kafka Connect REST API as follows:

curl -X POST -H "Content-Type: application/json" -d @test-mssql-connector.json http://localhost:8083/connectors

using test-mssql-connector.json

{
  "name": "test-mssql-connector5",  
  "config": {
    "connector.class": "io.debezium.connector.sqlserver.SqlServerConnector", 
    "database.hostname": "localhost", 
    "database.port": "1433", 
    "database.user": "SA",
    "database.password": "xxxxxxxxxxxxx",
    "database.dbname": "test",
    "database.server.name": "sql1", 
    "table.whitelist": "dbo.Persons", 
    "database.history.kafka.bootstrap.servers": "kafka:9092", 
    "database.history.kafka.topic": "dbhistory.sql1" 
  }
}

However, Kafka connector cannot connect to the MSSQL db giving error message below:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: \"Connection refused. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.

Most troubleshooting are if database actually running, or port is blocked, but there is no problem with new MSSQL db. It's container is active, and the db is successfully running. The port is not blocked. I can successfully connect to it from host machine using DbVisualizer or other query tools with following configuration:

I can successfully use telnet localhost 1433 to connect to server.

Is there something missing in the connector configuration above?

Upvotes: 2

Views: 3423

Answers (2)

ShanksPranks
ShanksPranks

Reputation: 417

You need to first set up your sql container and THEN only start the connect service specifying the sql server as an additional link:

docker run -it --name connect -p 8083:8083 -e GROUP_ID=1 -e CONFIG_STORAGE_TOPIC=my-connect-configs -e OFFSET_STORAGE_TOPIC=my-connect-offsets -e ADVERTISED_HOST_NAME="localhost" --link zookeeper:zookeeper --link kafka:kafka --link kafka:kafka debezium/connect

Upvotes: 0

Jiri Pechanec
Jiri Pechanec

Reputation: 1976

IMHO the localhost is not correct as localhost is something else in Connect container and in SQL Server container. You should link the database container into Connect container and use the appropriate hostname.

Upvotes: 3

Related Questions