63 Star 183 Fork 3

Gitee 极速下载/hyperledger-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
producer.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package producer
import (
"fmt"
"io"
"time"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/core/comm"
pb "github.com/hyperledger/fabric/protos/peer"
)
var logger = flogging.MustGetLogger("eventhub_producer")
// EventsServer implementation of the Peer service
type EventsServer struct {
eventProcessor *eventProcessor
}
// EventsServerConfig contains the setup config for the events server
type EventsServerConfig struct {
BufferSize uint
Timeout time.Duration
SendTimeout time.Duration
TimeWindow time.Duration
BindingInspector comm.BindingInspector
}
// singleton - if we want to create multiple servers, we need to subsume
// events.gEventConsumers into EventsServer
var globalEventsServer *EventsServer
// NewEventsServer returns an EventsServer
func NewEventsServer(config *EventsServerConfig) *EventsServer {
if globalEventsServer != nil {
panic("Cannot create multiple event hub servers")
}
eventProcessor := initializeEvents(config)
globalEventsServer := &EventsServer{eventProcessor: eventProcessor}
return globalEventsServer
}
func (e *EventsServer) Chat(stream pb.Events_ChatServer) error {
handler := newHandler(stream, e.eventProcessor)
defer e.eventProcessor.cleanupHandler(handler)
for {
in, err := stream.Recv()
if err == io.EOF {
logger.Debug("Received EOF, ending Chat")
return nil
}
if err != nil {
err := fmt.Errorf("error during Chat, stopping handler: %s", err)
logger.Error(err.Error())
return err
}
err = handler.HandleMessage(in)
if err != nil {
logger.Errorf("Error handling message: %s", err)
return err
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/hyperledger-fabric.git
git@gitee.com:mirrors/hyperledger-fabric.git
mirrors
hyperledger-fabric
hyperledger-fabric
v1.2.0

搜索帮助