1 Star 0 Fork 0

yangtxiang/mg-fw

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 933 Bytes
一键复制 编辑 原始数据 按行查看 历史
yangtxiang 提交于 2022-08-20 10:09 +08:00 . add sarama
package cluster
import (
"errors"
"sync/atomic"
"github.com/Shopify/sarama"
)
var errClientInUse = errors.New("cluster: client is already used by another consumer")
// Client is a group client
type Client struct {
sarama.Client
config Config
inUse uint32
}
// NewClient creates a new client instance
func NewClient(addrs []string, config *Config) (*Client, error) {
if config == nil {
config = NewConfig()
}
if err := config.Validate(); err != nil {
return nil, err
}
client, err := sarama.NewClient(addrs, &config.Config)
if err != nil {
return nil, err
}
return &Client{Client: client, config: *config}, nil
}
// ClusterConfig returns the cluster configuration.
func (c *Client) ClusterConfig() *Config {
cfg := c.config
return &cfg
}
func (c *Client) claim() bool {
return atomic.CompareAndSwapUint32(&c.inUse, 0, 1)
}
func (c *Client) release() {
atomic.CompareAndSwapUint32(&c.inUse, 1, 0)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/maglsoft/mg-fw.git
git@gitee.com:maglsoft/mg-fw.git
maglsoft
mg-fw
mg-fw
v0.0.5

搜索帮助