2.4. 验证部署


连接器启动后,它会对配置的数据库执行快照,并为您指定的每个表创建主题。

先决条件

  • 您已根据 第 2.3 节 “在 Red Hat Enterprise Linux 上使用 AMQ Streams 部署 Debezium” 中的说明在 Red Hat Enterprise Linux 上部署了一个连接器。

    1. 在主机上的终端窗口中输入以下命令从 Kafka Connect API 请求连接器列表:

      $ curl -H "Accept:application/json" localhost:8083/connectors/

      查询返回部署的连接器的名称,例如:

      ["inventory-connector"]
    2. 在主机的终端窗口中,输入以下命令查看连接器运行的任务:

      $ curl -i -X GET -H "Accept:application/json" localhost:8083/connectors/inventory-connector

      该命令返回类似以下示例的输出:

      HTTP/1.1 200 OK
      Date: Thu, 06 Feb 2020 22:12:03 GMT
      Content-Type: application/json
      Content-Length: 531
      Server: Jetty(9.4.20.v20190813)
      
      {
        "name": "inventory-connector",
        ...
        "tasks": [
          {
            "connector": "inventory-connector",
            "task": 0
          }
        ]
      }
    3. 显示 Kafka 集群中的主题列表。
      在终端窗口中进入 /opt/kafka/bin/ 并运行以下 shell 脚本:

      ./kafka-topics.sh --bootstrap-server=localhost:9092 --list

      Kafka 代理返回连接器创建的主题列表。可用的主题取决于连接器的 snapshot.modesnapshot.include.collection.listtable.include.list 配置属性的设置。默认情况下,连接器会为数据库中的每个非系统表创建一个主题。

    4. 查看主题的内容。
      在终端窗口中进入 /opt/kafka/bin/,并运行 kafka-console-consumer.sh shell 脚本来显示上一命令返回的其中一个主题的内容:

      例如:

      ./kafka-console-consumer.sh \
      >     --bootstrap-server localhost:9092 \
      >     --from-beginning \
      >     --property print.key=true \
      >     --topic=dbserver1.inventory.products_on_hand

      对于主题中的每个事件,命令会返回类似以下输出的信息:

      例 2.1. 集成更改事件的内容

      {"schema":{"type":"struct","fields":[{"type":"int32","optional":false,"field":"product_id"}],"optional":false,"name":"dbserver1.inventory.products_on_hand.Key"},"payload":{"product_id":101}}	{"schema":{"type":"struct","fields":[{"type":"struct","fields":[{"type":"int32","optional":false,"field":"product_id"},{"type":"int32","optional":false,"field":"quantity"}],"optional":true,"name":"dbserver1.inventory.products_on_hand.Value","field":"before"},{"type":"struct","fields":[{"type":"int32","optional":false,"field":"product_id"},{"type":"int32","optional":false,"field":"quantity"}],"optional":true,"name":"dbserver1.inventory.products_on_hand.Value","field":"after"},{"type":"struct","fields":[{"type":"string","optional":false,"field":"version"},{"type":"string","optional":false,"field":"connector"},{"type":"string","optional":false,"field":"name"},{"type":"int64","optional":false,"field":"ts_ms"},{"type":"string","optional":true,"name":"io.debezium.data.Enum","version":1,"parameters":{"allowed":"true,last,false"},"default":"false","field":"snapshot"},{"type":"string","optional":false,"field":"db"},{"type":"string","optional":true,"field":"sequence"},{"type":"string","optional":true,"field":"table"},{"type":"int64","optional":false,"field":"server_id"},{"type":"string","optional":true,"field":"gtid"},{"type":"string","optional":false,"field":"file"},{"type":"int64","optional":false,"field":"pos"},{"type":"int32","optional":false,"field":"row"},{"type":"int64","optional":true,"field":"thread"},{"type":"string","optional":true,"field":"query"}],"optional":false,"name":"io.debezium.connector.mysql.Source","field":"source"},{"type":"string","optional":false,"field":"op"},{"type":"int64","optional":true,"field":"ts_ms"},{"type":"struct","fields":[{"type":"string","optional":false,"field":"id"},{"type":"int64","optional":false,"field":"total_order"},{"type":"int64","optional":false,"field":"data_collection_order"}],"optional":true,"field":"transaction"}],"optional":false,"name":"dbserver1.inventory.products_on_hand.Envelope"},"payload":{"before":null,"after":{"product_id":101,"quantity":3},"source":{"version":"2.1.4.Final-redhat-00001","connector":"mysql","name":"inventory_connector_mysql","ts_ms":1638985247805,"snapshot":"true","db":"inventory","sequence":null,"table":"products_on_hand","server_id":0,"gtid":null,"file":"mysql-bin.000003","pos":156,"row":0,"thread":null,"query":null},"op":"r","ts_ms":1638985247805,"transaction":null}}

      在上例中,有效负载 值显示连接器快照从表 inventory.products_on_hand 中生成一个读取("op" ="r")事件。product_id 记录的 "before" 状态为 null,这表示记录没有之前的值。"after" 状态对于 product_id101 的项目的 quantity 显示为 3

后续步骤

有关每个连接器可用的配置设置的信息,以及如何配置源数据库以启用更改数据捕获,请参阅 Debezium 用户指南

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.