-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.go
64 lines (53 loc) · 1.5 KB
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package pulsarKit
import (
"context"
"github.com/apache/pulsar-client-go/pulsar"
"github.com/richelieu-yang/chimera/v2/src/log/logrusKit"
"github.com/sirupsen/logrus"
)
var config *Config
// MustSetUp
/*
@param tmpDirPath 用于存放生成日志文件的临时目录(可以为空字符串,此时将采用默认值: 系统临时目录)
*/
func MustSetUp(config *Config) {
err := SetUp(config)
if err != nil {
logrusKit.DisableQuote(nil)
logrus.Fatalf("%+v", err)
}
}
func SetUp(pulsarConfig *Config) (err error) {
defer func() {
if err != nil {
config = nil
}
}()
config = pulsarConfig
err = verify(config.VerifyConfig)
return
}
// NewProducer
/*
前提: 成功调用 SetUp() || MustSetUp().
@param options 必需属性: Topic、SendTimeout
@param logPath 客户端的日志输出("": 输出到控制台)
*/
func NewProducer(ctx context.Context, options pulsar.ProducerOptions, clientLogPath string) (*Producer, error) {
if config == nil {
return nil, NotSetupError
}
return NewProducerOriginally(ctx, config.Addresses, options, clientLogPath)
}
// NewConsumer
/*
前提: 成功调用 SetUp() || MustSetUp().
@param options 必需属性: Topic、SubscriptionName、Type
@param logPath 客户端的日志输出("": 输出到控制台)
*/
func NewConsumer(ctx context.Context, options pulsar.ConsumerOptions, clientLogPath string) (*Consumer, error) {
if config == nil {
return nil, NotSetupError
}
return NewConsumerOriginally(ctx, config.Addresses, options, clientLogPath)
}