0

我正在构建一个客户端服务器以使用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())FabricSDKgateway.Connect(gateway.WithConfig())fabsdk.WithMSPPkg(gw.mspfactory)fabsdk.New()

所以,我的问题是:

  • 我该如何处理“TRANSIENT_FAILURE”错误,或者
  • 如何禁用 Fabric SDK 的默认日志系统?

谢谢。

4

1 回答 1

1

在编写一个小示例 CLI 来获取链码元数据时,我遇到了完全相同的两个问题

如何处理“TRANSIENT_FAILURE”错误

就我而言,dialing connection on target [peer0.org1.example.com:7051]: connection is in TRANSIENT_FAILURE错误是因为我使用的是 Fabric 测试网络 docker 环境,但我没有设置 DISCOVERY_AS_LOCALHOST 环境变量。DISCOVERY_AS_LOCALHOST 确定在服务发现期间找到的 IP 地址是否从 docker 网络转换到本地主机,这在用于开发应用程序的连接选项文档中进行了描述。

如何禁用 Fabric SDK 的默认日志系统?

我仍然想查看错误消息,但我能够更改日志记录级别以删除不需要的信息消息logging.SetLevel("", logging.ERROR)

ccmetadata示例在 GitHub 上,如果有帮助的话

于 2021-07-09T13:20:52.650 回答