我正在构建一个客户端服务器以使用fabric-go-sdk
. 要使用自定义日志记录系统,我使用函数获取一个FabricSDK
对象,fabsdk.New()
然后将其注入到一个Gateway
对象中gateway.WithSDK
。检查下面的代码:
ccpPath := getPath("connection-profile.json", staticPath)
sdk, err := fabsdk.New(config.FromFile(ccpPath),
fabsdk.WithLoggerPkg(&FabSDKLoggerProvider{}), // using my custom logging system
)
if err != nil {
return nil, errors.Wrap(err, "failed to create a new fabsdk")
}
gw, err := gateway.Connect(
gateway.WithSDK(sdk),
gateway.WithIdentity(wallet, "admin"),
)
if err != nil {
return nil, errors.Wrap(err, "failed to connect the network via a fabric gateway")
}
当我运行测试时,我收到一个错误:
Failed to submit: error registering for TxStatus event: could not create client conn: could not connect to peer0.test.bpl:7051: dialing connection on target [peer0.test.bpl:7051]: connection is in TRANSIENT_FAILURE
我运行的测试是使用Gateway
对象及其Submit
方法发送事务的测试。
当我定义一个没有 的Gateway
对象时FabricSDK
,它工作正常。也就是说,如果我使用下面的代码,测试就会顺利通过。但是,在这种情况下,我无法使用我的自定义日志记录系统。(我只想禁用 Fabric SDK 的日志系统。)
ccpPath := getPath("connection-profile.json", staticPath)
gw, err := gateway.Connect(
gateway.WithConfig(config.FromFile(ccpPath)),
gateway.WithIdentity(wallet, "admin"),
)
if err != nil {
return nil, errors.Wrap(err, "failed to connect the network via a fabric gateway")
}
根据我的调查,由和FabricSDK
初始化的对象之间的区别在于,由 和 创建的对象具有选项,而另一个则没有。我尝试为我的代码提供相同的选项,但我找不到如何去做。fabsdk.New()
gateway.Connect(gateway.WithConfig())
FabricSDK
gateway.Connect(gateway.WithConfig())
fabsdk.WithMSPPkg(gw.mspfactory)
fabsdk.New()
所以,我的问题是:
- 我该如何处理“TRANSIENT_FAILURE”错误,或者
- 如何禁用 Fabric SDK 的默认日志系统?
谢谢。