how retrieve network information #595
-
I'm trying to retrieve some information from the network, but the method below apparently doesn't work or I'm using it incorrectly, most methods are using the CloseableIterator Is the form below correct? do we have an example to recover the same new version try (var gateway = builder.connect()) {
var network = gateway.getNetwork(CHANNEL_NAME);
int idx = 0;
while(network.getBlockEvents().hasNext()) {
Block next = network.getBlockEvents().next();
infos.add(InfoNetworkDTO.builder()
.dataCount(next.getData().getDataCount())
.dataList(next.getData().getDataList())
.data(next.getData().getData(0))
.build()
);
idx++;
}
} old version Channel channel = network.getChannel();
Collection<Peer> peersOrganizationMSPIDs = channel.getPeersForOrganization(mspid);
List<PeerModel> peerModels = new ArrayList<>();
peersOrganizationMSPIDs.forEach(peer -> peerModels.add(
new PeerModel(peer.getName(),
peer.getUrl(),
peer.getProperties().toString(),
peer.getProtocol(),
peer.getPeerEventingServiceDisconnected().toString())
)); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You have mixed two very different capabilities here. Your old version is accessing information obtained by the client SDK using the Fabric discovery service about the network topology. Your new version is using block eventing (incorrectly) to obtain committed block from the blockchain, which is useful for tasks like building an off-chain data store. Legacy SDKs needed to use the discovery service in order to identify and then connect to network peers required for transaction endorsement. The Fabric Gateway client API does not deal with service discovery at the client. Instead, the work of identifying endorsing peer is handled by the gateway service in the peer, which already holds locally all the information returned by the discovery service. The comparison of the transaction flow between legacy SDKs and using Fabric Gateway in the full-stack-asset-transfer-guide sample provides a more detailed description. In addition to the off_chain_data sample mentioned above, the API documentation contains code examples demonstrating how to use block eventing correctly. |
Beta Was this translation helpful? Give feedback.
You have mixed two very different capabilities here. Your old version is accessing information obtained by the client SDK using the Fabric discovery service about the network topology. Your new version is using block eventing (incorrectly) to obtain committed block from the blockchain, which is useful for tasks like building an off-chain data store.
Legacy SDKs needed to use the discovery service in order to identify and then connect to network peers required for transaction endorsement. The Fabric Gateway client API does not deal with service discovery at the client. Instead, the work of identifying endorsing peer is handled by the gateway service in the peer, which already holds locally…