Java Apps can use BlockStreamer to stream blocks from a Cardano node. BlockStreamer.fromLatest(NetworkType).stream() returns an instance of Flux. An application can subscribe to the Flux to receive incoming Block data and also can apply various Flux specific operators supported by Project Reactor
BlockStreamer streamer = BlockStreamer.fromLatest(NetworkType.MAINNET);
Flux< Block> blockFlux = streamer.stream();
blockFlux.subscribe(block -> {
System.out.println("Received Block >> " + block.getHeader().getHeaderBody().getBlockNumber());
System.out.println("Total # of Txns >> " + block.getTransactionBodies().size());
});
streamer.shutdown();
NetworkType enum has 4 network types.
Application just needs to specify the network type to connect to the public relay of the network. To connect to a custom node or a private network, app needs to provide informations like host, port, a well known point and protocol magic.
BlockStreamer fromPoint(NetworkType networkType, Point point)
BlockStreamer fromPoint(String host, int port, Point point, VersionTable versionTable)
BlockStreamer forRange(NetworkType networkType, Point fromPoint, Point toPoint)
BlockStreamer forRange(String host, int port, Point fromPoint, Point toPoint, VersionTable versionTable)