63 Star 183 Fork 3

Gitee 极速下载/hyperledger-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
consenter.go 2.52 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package kafka
import (
"github.com/Shopify/sarama"
"github.com/hyperledger/fabric/common/flogging"
localconfig "github.com/hyperledger/fabric/orderer/localconfig"
"github.com/hyperledger/fabric/orderer/multichain"
cb "github.com/hyperledger/fabric/protos/common"
logging "github.com/op/go-logging"
)
const pkgLogID = "orderer/kafka"
var logger *logging.Logger
func init() {
logger = flogging.MustGetLogger(pkgLogID)
}
// New creates a Kafka-based consenter. Called by orderer's main.go.
func New(tlsConfig localconfig.TLS, retryOptions localconfig.Retry, kafkaVersion sarama.KafkaVersion) multichain.Consenter {
brokerConfig := newBrokerConfig(tlsConfig, retryOptions, kafkaVersion, defaultPartition)
return &consenterImpl{
brokerConfigVal: brokerConfig,
tlsConfigVal: tlsConfig,
retryOptionsVal: retryOptions,
kafkaVersionVal: kafkaVersion}
}
// consenterImpl holds the implementation of type that satisfies the
// multichain.Consenter interface --as the HandleChain contract requires-- and
// the commonConsenter one.
type consenterImpl struct {
brokerConfigVal *sarama.Config
tlsConfigVal localconfig.TLS
retryOptionsVal localconfig.Retry
kafkaVersionVal sarama.KafkaVersion
}
// HandleChain creates/returns a reference to a multichain.Chain object for the
// given set of support resources. Implements the multichain.Consenter
// interface. Called by multichain.newChainSupport(), which is itself called by
// multichain.NewManagerImpl() when ranging over the ledgerFactory's
// existingChains.
func (consenter *consenterImpl) HandleChain(support multichain.ConsenterSupport, metadata *cb.Metadata) (multichain.Chain, error) {
lastOffsetPersisted := getLastOffsetPersisted(metadata.Value, support.ChainID())
return newChain(consenter, support, lastOffsetPersisted)
}
// commonConsenter allows us to retrieve the configuration options set on the
// consenter object. These will be common across all chain objects derived by
// this consenter. They are set using using local configuration settings. This
// interface is satisfied by consenterImpl.
type commonConsenter interface {
brokerConfig() *sarama.Config
retryOptions() localconfig.Retry
}
func (consenter *consenterImpl) brokerConfig() *sarama.Config {
return consenter.brokerConfigVal
}
func (consenter *consenterImpl) retryOptions() localconfig.Retry {
return consenter.retryOptionsVal
}
// closeable allows the shut down of the calling resource.
type closeable interface {
close() error
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/hyperledger-fabric.git
git@gitee.com:mirrors/hyperledger-fabric.git
mirrors
hyperledger-fabric
hyperledger-fabric
v1.0.0

搜索帮助

0d507c66 1850385 C8b1a773 1850385