如何使用apache camel的debezium sql server连接器实时报告事件?

bjp0bcyl  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(685)

我正在尝试通过以下spring引导启动程序使用apache camel的debezium sql server连接器将更改从一个数据库复制到另一个数据库:

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>3.5.0</version>
</dependency>
<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-debezium-sqlserver-starter</artifactId>
    <version>3.5.0</version>
</dependency>

到目前为止,我只是将生成的事件记录到一个特定的表中:

import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class MyRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("debezium-sqlserver:iwd" +
                "?databaseHostname=localhost" +
                "&databasePort=1433" +
                "&databaseServerName=iwd" +
                "&databaseDbname=iwd" +
                "&databaseUser=sa" +
                "&databasePassword=MyPassword-1" +
                "&tableWhitelist=dbo.MyTable-1" +
                "&offsetStorageFileName=./offset-file-1.dat" +
                "&databaseHistoryFileFilename=./history-file-1.dat")
        .routeId(MyRoute.class.getName() + ".DatabaseReader")
        .log(LoggingLevel.INFO, "Incoming message ${body} with headers ${headers}");
    }
}

初始化应用程序时,它会为表的每一行报告一个事件,问题是以后它不会实时报告事件,例如,如果我在表中插入或更新一行。

f2uvfpb9

f2uvfpb91#

请跟我来https://debezium.io/documentation/reference/1.3/connectors/sqlserver.html#setting-启动sqlserver并确保:
已为数据库启用cdc

USE MyDB
GO
EXEC sys.sp_cdc_enable_db
GO

已为要捕获的表启用cdc

EXEC sys.sp_cdc_enable_table
@source_schema = N'dbo',
@source_name   = N'MyTable',
@role_name     = N'MyRole',
GO

sql server代理正在运行
debezium用户具有读取源表和更改表的权限

相关问题