Ejemplo n.º 1
0
        private static SqlServerConnectorMetadata CreateConnectorMetadata()
        {
            var createConnector = new SqlServerConnectorMetadata(connectionString)
                                  .SetTableIncludeListPropertyName($"{schemaName}.{tableName}")
                                  .SetJsonKeyConverter()
                                  .SetJsonValueConverter()
                                  .SetProperty("database.history.kafka.bootstrap.servers", bootstrapServers)
                                  .SetProperty("database.history.kafka.topic", $"dbhistory.{tableName}")
                                  .SetProperty("database.server.name", "sqlserver2019")
                                  .SetProperty("key.converter.schemas.enable", "false")
                                  .SetProperty("value.converter.schemas.enable", "false")
                                  .SetProperty("include.schema.changes", "false");

            return(createConnector as SqlServerConnectorMetadata);
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            SqlServerConnectorMetadata connectorMetadata = CreateConnectorMetadata();

            string connectorName = "MSSQL_CDC_CONNECTOR";

            var httpClient = new HttpClient()
            {
                BaseAddress = new Uri(ConnectUrl)
            };

            var httpClientFactory = new HttpClientFactory(httpClient);

            var connectRestApiClient = new ConnectRestApiClient(httpClientFactory);

            var httpResponseMessage = await connectRestApiClient.PostConnectorAsync(connectorMetadata, connectorName);
        }
        public async Task CreateConnectorAsync_AndReceivesDatabaseChangeObjects()
        {
            //Arrange
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            var connectionStringBuilder = new SqlConnectionStringBuilder(connectionString)
            {
                DataSource = "sqlserver2019"
            };

            connectionString = connectionStringBuilder.ConnectionString;

            var    bootstrapServers   = Configuration["Kafka:BootstrapServers"];
            string databaseServerName = "sqlserver2019Tests";

            var connectorMetadata = new SqlServerConnectorMetadata(connectionString)
                                    .SetTableIncludeListPropertyName($"dbo.{tableName}")
                                    .SetJsonKeyConverter()
                                    .SetJsonValueConverter()
                                    .SetProperty("database.history.kafka.bootstrap.servers", bootstrapServers)
                                    .SetProperty("database.history.kafka.topic", $"dbhistory.test.{tableName}")
                                    .SetProperty("database.server.name", databaseServerName)
                                    //.SetProperty("topic.creation.enable", "true")
                                    .SetProperty("key.converter.schemas.enable", "false")
                                    .SetProperty("value.converter.schemas.enable", "false")
                                    .SetProperty("include.schema.changes", "false") as SqlServerConnectorMetadata;

            //Act
            var httpResponseMessage = await ClassUnderTest.CreateConnectorAsync(connectorName, connectorMetadata);

            //Assert
            //var statementResponse = httpResponseMessage.ToStatementResponse();
            httpResponseMessage.IsSuccessStatusCode.Should().BeTrue();

            await ReceivesDatabaseChangeObjectsAsync(databaseServerName);
        }
        /// <summary>
        /// Create a new connector in the Kafka Connect cluster with the configuration passed in the connectorMetadata parameter. The statement does not fail if a connector with the supplied name already exists.
        /// </summary>
        /// <param name="connectorName">Name of the connector.</param>
        /// <param name="connectorMetadata">Configuration passed in the WITH clause.</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <HttpResponseMessage> CreateConnectorIfNotExistsAsync(string connectorName, SqlServerConnectorMetadata connectorMetadata, CancellationToken cancellationToken = default)
        {
            var createConnector = connectorMetadata.ToCreateConnectorStatement(connectorName, ifNotExists: true);

            KSqlDbStatement ksqlDbStatement = new(createConnector);

            var httpResponseMessage = await ExecuteStatementAsync(ksqlDbStatement, cancellationToken).ConfigureAwait(false);

            return(httpResponseMessage);
        }