通过 Kafka Connect 连接到 MSSQL 服务器的 Kafka 主题 - 无法连接

问题描述 投票:0回答:1

我正在尝试通过 docker 将示例记录从 Kafka 主题推送到本地托管的 MSSQL。

所有服务都运行良好,但是当我尝试使用以下配置创建接收器连接器时,它会抛出错误:

{
  "name": "JdbcSinkConnectorConnector_0",
  "config": {
    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
    "topics": "test01",
    "connection.url": "jdbc:sqlserver://localhost:1433;databaseName=sample",
    "connection.user": "sa",
    "connection.password": "Admin123",
    "insert.mode": "insert",
    "table.name.format": "${topic}",
    "auto.create": "true"
  }
}

我参考这个 official 存储库来获取 docker-compose 文件。除此之外,我还在 docker-compose 中添加了以下块:

mssql:
    image: mcr.microsoft.com/mssql/server
    container_name: mssql
    user: root
    ports: 
      - 1433:1433
    environment: 
      - SA_PASSWORD=Admin123
      - ACCEPT_EULA=Y
      - MSSQL_PID=Standard
      - MSSQL_AGENT_ENABLED=true
    volumes:
     - ".mssql:/var/mssql"

我正在使用 Azure Data Studio 连接到 MSSQL,并且我能够连接和查询。

唯一的问题是当我使用 Kafka 的控制中心并尝试推送通过 KSQLDB 生成的数据时。它抛出以下错误:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused (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.".

我使用下面的代码通过 KSQL 生成数据并将其推送到 Kafka 主题:

CREATE STREAM TEST01 (KEY_COL VARCHAR KEY, COL1 INT, COL2 VARCHAR)
  WITH (KAFKA_TOPIC='test01', PARTITIONS=1, VALUE_FORMAT='AVRO');
INSERT INTO TEST01 (KEY_COL, COL1, COL2) VALUES ('X',1,'FOO');
INSERT INTO TEST01 (KEY_COL, COL1, COL2) VALUES ('Y',2,'BAR');
SHOW TOPICS;
PRINT test01 FROM BEGINNING LIMIT 2;

那么我在这里错过了什么?我同样尝试使用以下配置的 Postgres,效果很好。没有错误。

{
  "name": "JdbcSinkConnectorConnector_1",
  "config": {
    "name": "JdbcSinkConnectorConnector_1",
    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
    "topics": "test01",
    "connection.url": "jdbc:postgresql://postgres:5432/",
    "connection.user": "postgres",
    "connection.password": "********",
    "insert.mode": "insert",
    "table.name.format": "${topic}",
    "auto.create": "true"
  }
}

请参阅以下

docker ps
命令的详细信息:

CONTAINER ID   IMAGE                                             COMMAND                  CREATED       STATUS       PORTS                                            NAMES
9df3ab7c2b45   confluentinc/cp-enterprise-control-center:7.7.1   "/etc/confluent/dock…"   4 hours ago   Up 3 hours   0.0.0.0:9021->9021/tcp                           control-center
b2b62be89f51   confluentinc/ksqldb-examples:7.7.1                "bash -c 'echo Waiti…"   4 hours ago   Up 3 hours                                                    ksql-datagen
e4ec71324a96   confluentinc/cp-ksqldb-cli:7.7.1                  "/bin/sh"                4 hours ago   Up 3 hours                                                    ksqldb-cli
9465e50f88b9   confluentinc/cp-ksqldb-server:7.7.1               "/etc/confluent/dock…"   4 hours ago   Up 3 hours   0.0.0.0:8088->8088/tcp                           ksqldb-server
f24a78454b0d   cnfldemos/cp-server-connect-datagen:0.6.4-7.6.0   "/etc/confluent/dock…"   4 hours ago   Up 3 hours   0.0.0.0:8083->8083/tcp, 9092/tcp                 connect
44ab10d9aea0   confluentinc/cp-kafka-rest:7.7.1                  "/etc/confluent/dock…"   4 hours ago   Up 3 hours   0.0.0.0:8082->8082/tcp                           rest-proxy
44260494a1a2   confluentinc/cp-schema-registry:7.7.1             "/etc/confluent/dock…"   4 hours ago   Up 3 hours   0.0.0.0:8081->8081/tcp                           schema-registry
1cbed4ee96c8   confluentinc/cp-server:7.7.1                      "/etc/confluent/dock…"   4 hours ago   Up 3 hours   0.0.0.0:9092->9092/tcp, 0.0.0.0:9101->9101/tcp   broker
d4b9c746cd22   mcr.microsoft.com/mssql/server                    "/opt/mssql/bin/perm…"   4 hours ago   Up 3 hours   0.0.0.0:1433->1433/tcp                           mssql
0a40688df2a9   confluentinc/cp-zookeeper:7.7.1                   "/etc/confluent/dock…"   4 hours ago   Up 3 hours   2888/tcp, 0.0.0.0:2181->2181/tcp, 3888/tcp       zookeeper

以下是标记到 1433 端口的进程列表的详细信息:

(base) Downloads % lsof -i:1433
COMMAND     PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Microsoft  5986  sid  202u  IPv4 0xcefd609a054dba17      0t0  TCP localhost:56403->localhost:ms-sql-s (ESTABLISHED)
Microsoft  5986  sid  209u  IPv4 0x3ef2d4b92ede00d1      0t0  TCP localhost:55888->localhost:ms-sql-s (ESTABLISHED)
Microsoft  5986  sid  216u  IPv4 0xffb8266d91d81130      0t0  TCP localhost:55872->localhost:ms-sql-s (ESTABLISHED)
Microsoft  5986  sid  221u  IPv4 0xc8b862a268eebba7      0t0  TCP localhost:50971->localhost:ms-sql-s (CLOSE_WAIT)
Microsoft  5986  sid  224u  IPv4 0x48fc815e90723a46      0t0  TCP localhost:51715->localhost:ms-sql-s (CLOSE_WAIT)
Microsoft  5986  sid  235u  IPv4 0x9497d278ff6dfdf7      0t0  TCP localhost:56349->localhost:ms-sql-s (ESTABLISHED)
com.docke 87546  sid    8u  IPv6 0x318017db2858b995      0t0  TCP localhost:ms-sql-s->localhost:56349 (ESTABLISHED)
com.docke 87546  sid  118u  IPv6 0x2b03aa9d6fa879df      0t0  TCP localhost:ms-sql-s->localhost:56403 (ESTABLISHED)
com.docke 87546  sid  129u  IPv6 0x799d7c3441e270bc      0t0  TCP localhost:ms-sql-s->localhost:51715 (FIN_WAIT_2)
com.docke 87546  sid  136u  IPv6 0xdaf881c413e5d1fd      0t0  TCP localhost:ms-sql-s->localhost:50971 (FIN_WAIT_2)
com.docke 87546  sid  153u  IPv6 0xb88afc126a1ddb32      0t0  TCP localhost:ms-sql-s->localhost:55888 (ESTABLISHED)
com.docke 87546  sid  181u  IPv6 0x5300c524e77fa45e      0t0  TCP *:ms-sql-s (LISTEN)
com.docke 87546  sid  187u  IPv6 0x54d6ec9bb58195f5      0t0  TCP localhost:ms-sql-s->localhost:55872 (ESTABLISHED)
docker docker-compose apache-kafka-connect
1个回答
0
投票

ADS 之所以有效,是因为它不是在容器中运行;它在您的主机上运行,并且您已将端口 1433 转发到您的主机。 Postgres 接收器运行良好,因为它没有在 URL 中使用

localhost
。您需要将其替换为
mssql

请参阅https://docs.docker.com/compose/how-tos/networking/

© www.soinside.com 2019 - 2024. All rights reserved.