postgres://root:root@127.0.0.1:5432/root
(node:12744) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
TypeError: Channel's second argument must be a ChannelCredentials
at ServiceClient.Client (/home/wdrfxy/blockchain-explorer/node_modules/grpc/src/client.js:410:23)
at new ServiceClient (/home/wdrfxy/blockchain-explorer/node_modules/grpc/src/client.js:936:12)
at new AdminPeer (/home/wdrfxy/blockchain-explorer/app/platform/fabric/AdminPeer.js:65:30)
at FabricClient.newAdminPeer (/home/wdrfxy/blockchain-explorer/app/platform/fabric/FabricClient.js:546:25)
at FabricClient.initializeChannelFromDiscover (/home/wdrfxy/blockchain-explorer/app/platform/fabric/FabricClient.js:499:38)
at
Received kill signal, shutting down gracefully
Closed out connections
1条回答 默认 最新
- 你知我知皆知 2024-08-08 02:59关注
以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
在使用
grpc.proto-loader
代替grpc.loadPackageDefinition
的情况下,你可能遇到的错误信息是TypeError: Channel's second argument must be a ChannelCredentials
. 这是因为grpc.proto-loader
不支持直接加载 Protobuf 协议文件。你需要将你的 Protobuf 文件编译成.proto
格式,并使用@grpc/proto-loader
加载它。以下是一个示例:
package main import ( "context" "flag" "github.com/grpc-ecosystem/go-grpc-middleware" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "github.com/gorilla/mux" "github.com/wdrfxy/blockchain-explorer/app/platform/fabric" "github.com/wdrfxy/blockchain-explorer/app/platform/fabric/admin" "github.com/wdrfxy/blockchain-explorer/app/platform/fabric/config" "github.com/wdrfxy/blockchain-explorer/app/platform/fabric/service" "github.com/wdrfxy/blockchain-explorer/app/platform/fabric/util" "github.com/wdrfxy/blockchain-explorer/common/logger" "github.com/wdrfxy/blockchain-explorer/common/models" "github.com/wdrfxy/blockchain-explorer/common/services" ) func init() { flag.BoolVar(&log, "debug", false, "Enable debug mode") } var log = logger.New("blockchain-explorer") // CreateAdminPeer returns an instance of AdminPeer. func CreateAdminPeer(ctx context.Context, mux *mux.Mux, serviceName string) (*admin.AdminPeer, error) { adminPeer := admin.NewAdminPeer(serviceName) return adminPeer, nil } func main() { flag.Parse() // Load configuration from config file config.LoadConfig() // Create the service client svc := services.GetService() if svc == nil { log.Fatal(status.Errorf(codes.Internal, "service not found")) } adminPeer, err := CreateAdminPeer(context.Background(), mux, config.ServiceName) if err != nil { log.Fatalf("failed to create admin peer: %v", err) } defer adminPeer.Close() // Start the service err = adminPeer.Start(svc) if err != nil { log.Fatalf("failed to start service: %v", err) } defer func() { _ = adminPeer.Stop() }() // Register routes for the service routes := make([]runtime.ServeMuxEntry, len(mux.Router().Paths)) for i, path := range mux.Router().Paths { routes[i] = runtime.NewServeMuxEntry(path) } adminPeer.RegisterRoutes(routes) // Wait for the service to close adminPeer.Wait() }
在这个例子中,我们创建了一个
CreateAdminPeer
函数,用于根据服务名称获取一个实例的AdminPeer
。然后,我们在主函数中调用这个函数来初始化和运行服务。注意:这段代码只是一个示例,实际使用时你可能需要根据你的具体需求进行修改。
解决 无用评论 打赏 举报