1111import s2 .config .Endpoints ;
1212import s2 .types .Batch ;
1313import s2 .types .ReadSessionRequest ;
14+ import s2 .types .Start ;
1415
1516public class ManagedReadSessionDemo {
1617
@@ -19,11 +20,11 @@ public class ManagedReadSessionDemo {
1920
2021 public static void main (String [] args ) throws Exception {
2122
22- final var authToken = System .getenv ("S2_AUTH_TOKEN " );
23+ final var authToken = System .getenv ("S2_ACCESS_TOKEN " );
2324 final var basinName = System .getenv ("S2_BASIN" );
2425 final var streamName = System .getenv ("S2_STREAM" );
2526 if (authToken == null ) {
26- throw new IllegalStateException ("S2_AUTH_TOKEN not set" );
27+ throw new IllegalStateException ("S2_ACCESS_TOKEN not set" );
2728 }
2829 if (basinName == null ) {
2930 throw new IllegalStateException ("S2_BASIN not set" );
@@ -32,11 +33,7 @@ public static void main(String[] args) throws Exception {
3233 throw new IllegalStateException ("S2_STREAM not set" );
3334 }
3435
35- var config =
36- Config .newBuilder (authToken )
37- .withEndpoints (Endpoints .fromEnvironment ())
38- .withCompression (true )
39- .build ();
36+ var config = Config .newBuilder (authToken ).withEndpoints (Endpoints .fromEnvironment ()).build ();
4037
4138 try (final var executor = new ScheduledThreadPoolExecutor (12 );
4239 final var channel = ManagedChannelFactory .forBasinOrStreamService (config , basinName )) {
@@ -49,7 +46,10 @@ public static void main(String[] args) throws Exception {
4946
5047 try (final var managedSession =
5148 streamClient .managedReadSession (
52- ReadSessionRequest .newBuilder ().withHeartbeats (true ).build (),
49+ ReadSessionRequest .newBuilder ()
50+ .withHeartbeats (true )
51+ .withStart (Start .seqNum (0 ))
52+ .build (),
5353 1024 * 1024 * 1024 * 5 )) {
5454
5555 AtomicLong receivedBytes = new AtomicLong ();
@@ -61,10 +61,12 @@ public static void main(String[] args) throws Exception {
6161 if (elem instanceof Batch batch ) {
6262 var size = batch .meteredBytes ();
6363 logger .info (
64- "batch of {} bytes, seqnums {}..={}" ,
64+ "batch of {} bytes, seqnums {}..={} / instants {}..={} " ,
6565 size ,
6666 batch .firstSeqNum (),
67- batch .lastSeqNum ());
67+ batch .lastSeqNum (),
68+ batch .firstTimestamp (),
69+ batch .lastTimestamp ());
6870 receivedBytes .addAndGet (size );
6971 } else {
7072 logger .info ("non batch received: {}" , elem );
0 commit comments