github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/dmlsink/mq/manager/pulsar_manager.go (about) 1 // Copyright 2023 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 manager 15 16 import ( 17 "context" 18 "sync" 19 20 "github.com/apache/pulsar-client-go/pulsar" 21 "github.com/pingcap/tiflow/pkg/config" 22 ) 23 24 // PulsarTopicManager is a manager for pulsar topics. 25 type PulsarTopicManager func( 26 cfg *config.PulsarConfig, 27 client pulsar.Client, 28 ) (TopicManager, error) 29 30 // pulsarTopicManager is a manager for pulsar topics. 31 type pulsarTopicManager struct { 32 client pulsar.Client 33 partitions sync.Map // key : topic, value : partition-name 34 cfg *config.PulsarConfig 35 } 36 37 // NewPulsarTopicManager creates a new topic manager. 38 func NewPulsarTopicManager( 39 cfg *config.PulsarConfig, 40 client pulsar.Client, 41 ) (TopicManager, error) { 42 mgr := &pulsarTopicManager{ 43 client: client, 44 cfg: cfg, 45 partitions: sync.Map{}, 46 } 47 48 return mgr, nil 49 } 50 51 // GetPartitionNum always return 1 because we pass a message key to pulsar producer, 52 // and pulsar producer will hash the key to a partition. 53 // This method is only used to meet the requirement of mq sink's interface. 54 func (m *pulsarTopicManager) GetPartitionNum(ctx context.Context, topic string) (int32, error) { 55 return 1, nil 56 } 57 58 // CreateTopicAndWaitUntilVisible no need to create first 59 func (m *pulsarTopicManager) CreateTopicAndWaitUntilVisible(ctx context.Context, topicName string) (int32, error) { 60 return 0, nil 61 } 62 63 // Close 64 func (m *pulsarTopicManager) Close() { 65 } 66 67 // str2Pointer returns the pointer of the string. 68 func str2Pointer(str string) *string { 69 return &str 70 }