github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/dmlsink/mq/dmlproducer/dml_producer.go (about) 1 // Copyright 2022 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package dmlproducer 15 16 import ( 17 "context" 18 19 "github.com/apache/pulsar-client-go/pulsar" 20 "github.com/pingcap/tiflow/cdc/model" 21 "github.com/pingcap/tiflow/pkg/config" 22 "github.com/pingcap/tiflow/pkg/sink/codec/common" 23 "github.com/pingcap/tiflow/pkg/sink/kafka" 24 ) 25 26 // DMLProducer is the interface for message producer. 27 type DMLProducer interface { 28 // AsyncSendMessage sends a message asynchronously. 29 AsyncSendMessage( 30 ctx context.Context, topic string, partition int32, message *common.Message, 31 ) error 32 33 // Close closes the producer and client(s). 34 Close() 35 } 36 37 // Factory is a function to create a producer. 38 // errCh is used to report error to the caller(i.e. processor,owner). 39 // Because the caller passes errCh to many goroutines, 40 // there is no way to safely close errCh by the sender. 41 // So we let the GC close errCh. 42 // It's usually a buffered channel. 43 type Factory func(ctx context.Context, changefeedID model.ChangeFeedID, 44 asyncProducer kafka.AsyncProducer, 45 metricsCollector kafka.MetricsCollector, 46 errCh chan error, 47 failpointCh chan error, 48 ) DMLProducer 49 50 // PulsarFactory is a function to create a pulsar producer. 51 type PulsarFactory func(ctx context.Context, changefeedID model.ChangeFeedID, 52 client pulsar.Client, sinkConfig *config.SinkConfig, errCh chan error, 53 failpointCh chan error) (DMLProducer, error)