0

我们在 Amazon Managed Blockchain (AMB) 上运行 Hyperledger Fabric,最近我们决定从 1.2(长期以来一直是 AMB 上唯一可用的版本)迁移到 1.4。我们使用 Java SDK 连接到 Hyperledger,在旧版本上很好。重要的是,即使使用 HF 版本 1.2,我们也使用 HF SDK 版本 1.4.0,并且我们计划继续。

在 1.4 中,基本上没问题:我们可以执行主要活动,例如创建/加入通道、安装链代码、查询/调用它们。但是,围绕事件的功能不起作用:当我们注册侦听器时它不起作用并且我们收到以下错误:

2021-05-19 15:29:06.840 WARN 7 --- [ault-executor-0] org.hyperledger.fabric.sdk.EventHub : EventHub{id: 4, name: eventHub0, channelName: testchanone, url: grpcs://nd-ggqg7wmp4rgwjgab5cze4cjlba.m-vbe43tw4wbg2tgenuudpgzmfg4.n-4jqyvyxtlrc3hhe7u6jwxhsxge.managedblockchain.us-east-1.amazonaws.com:30004} terminated is false shutdown is false, retry count 601 has error UNAVAILABLE: io exception.
2021-05-19 15:29:06.841 WARN 7 --- [ault-executor-0] org.hyperledger.fabric.sdk.EventHub : EventHub{id: 4, name: eventHub0, channelName: testchanone, url: grpcs://nd-ggqg7wmp4rgwjgab5cze4cjlba.m-vbe43tw4wbg2tgenuudpgzmfg4.n-4jqyvyxtlrc3hhe7u6jwxhsxge.managedblockchain.us-east-1.amazonaws.com:30004} :StatusRuntimeException Status Status{code=UNAVAILABLE, description=io exception, cause=io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: nd-ggqg7wmp4rgwjgab5cze4cjlba.m-vbe43tw4wbg2tgenuudpgzmfg4.n-4jqyvyxtlrc3hhe7u6jwxhsxge.managedblockchain.us-east-1.amazonaws.com/10.0.1.167:30004
2021-05-19T18:29:06.841+03:00   Caused by: java.net.ConnectException: Connection refused
2021-05-19T18:29:06.841+03:00   at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
2021-05-19T18:29:06.841+03:00   at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716)
2021-05-19T18:29:06.841+03:00   at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327)
2021-05-19T18:29:06.841+03:00   at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:336)
2021-05-19T18:29:06.841+03:00   at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:685)
2021-05-19T18:29:06.841+03:00   at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:632)
2021-05-19T18:29:06.841+03:00   at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:549)
2021-05-19T18:29:06.841+03:00   at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:511)
2021-05-19T18:29:06.841+03:00   at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
2021-05-19T18:29:06.841+03:00   at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
2021-05-19T18:29:06.841+03:00   at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
2021-05-19T18:29:06.841+03:00   at java.lang.Thread.run(Thread.java:748)
2021-05-19T18:29:06.841+03:00   }. Description io exception

最糟糕的部分是该错误没有说明导致它的具体原因:相同的配置和设置适用于 HF 1.2(并且它适用于其他功能),并且类似的设置适用于 HF 1.4 时很久以前,我们将其用作自托管解决方案。

这是我们在创建通道时注册事件中心的方式:

...
        Properties channelProperties = new Properties();
        channelProperties.put("pemBytes", commonCaPem.getBytes());
        channelProperties.setProperty("sslProvider", "openSSL");
        channelProperties.setProperty("negotiationType", "TLS");
        channelProperties.put("grpc.NettyChannelBuilderOption.keepAliveTime", new Object[]{5L, TimeUnit.MINUTES});
        channelProperties.put("grpc.NettyChannelBuilderOption.keepAliveTimeout", new Object[]{60L, TimeUnit.SECONDS});
        channelProperties.put("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", new Object[]{true});

...

        ChannelConfiguration channelConfiguration = new ChannelConfiguration(
                    new File(generatedGenesisFile));
        byte[] channelConfigSigs = client.getChannelConfigurationSignature(channelConfiguration, adminUserContext);
        channel = client.newChannel(params.getChannelName(), orderers.stream().findAny()
                    .orElseThrow(() -> new InvalidArgumentException("Could not find any orderer within configuration")), channelConfiguration, channelConfigSigs);

...

        List<String> eventHubList = new ArrayList<>(this.eventHubs);
        for (int i = 0; i < eventHubList.size(); i++) {
            EventHub hub = client.newEventHub("eventHub" + i, eventHubList.get(i), channelProperties);
            channel.addEventHub(hub);
        }

        for (Orderer orderer : orderers) {
            channel.addOrderer(orderer);
        }

        channel.initialize();
...

事件中心地址始终是已知且正确的,我们从 HF 节点配置中自动设置它们。

这就是我们注册事件监听器的方式:

...
        String listenerHandle = container.getChannel().registerChaincodeEventListener(
                Pattern.compile(params.getChaincodeName() + ".*"),
                Pattern.compile(params.getQuotePattern() ? Pattern.quote(params.getPattern()) : params.getPattern()),
                (handle, blockEvent, chaincodeEvent) -> {
                    // actual event handler
                }
        );
...

如果您需要更多详细信息,我会添加它们。对于当前的问题,我不确定处理它的正确方法。

先感谢您!

4

0 回答 0