11package io .kurrent .dbclient ;
22
33import com .google .protobuf .ByteString ;
4- import io .grpc .ManagedChannel ;
54import io .grpc .Metadata ;
65import io .grpc .StatusRuntimeException ;
76import io .grpc .stub .StreamObserver ;
@@ -25,12 +24,18 @@ public MultiStreamAppend(GrpcClient client, Iterator<AppendStreamRequest> reques
2524 }
2625
2726 public CompletableFuture <MultiAppendWriteResult > execute () {
28- return this .client .run (this ::append );
27+ return this .client .runWithArgs (this ::append );
2928 }
3029
31- private CompletableFuture <MultiAppendWriteResult > append (ManagedChannel channel ) {
30+ private CompletableFuture <MultiAppendWriteResult > append (WorkItemArgs args ) {
3231 CompletableFuture <MultiAppendWriteResult > result = new CompletableFuture <>();
33- StreamsServiceGrpc .StreamsServiceStub client = GrpcUtils .configureStub (StreamsServiceGrpc .newStub (channel ), this .client .getSettings (), new OptionsBase <>());
32+
33+ if (!args .supportFeature (FeatureFlags .MULTI_STREAM_APPEND )) {
34+ result .completeExceptionally (new UnsupportedOperationException ("Multi-stream append is not supported by the server" ));
35+ return result ;
36+ }
37+
38+ StreamsServiceGrpc .StreamsServiceStub client = GrpcUtils .configureStub (StreamsServiceGrpc .newStub (args .getChannel ()), this .client .getSettings (), new OptionsBase <>(), null , false );
3439 StreamObserver <io .kurrentdb .v2 .AppendStreamRequest > requestStream = client .multiStreamAppendSession (GrpcUtils .convertSingleResponse (result , this ::onResponse ));
3540
3641 try {
@@ -44,15 +49,15 @@ private CompletableFuture<MultiAppendWriteResult> append(ManagedChannel channel)
4449 builder .addRecords (AppendRecord .newBuilder ()
4550 .setData (ByteString .copyFrom (event .getEventData ()))
4651 .setRecordId (event .getEventId ().toString ())
47- .putProperties (SystemMetadataKeys .CONTENT_TYPE , DynamicValueOuterClass
52+ .putProperties (SystemMetadataKeys .DATA_FORMAT , DynamicValueOuterClass
4853 .DynamicValue
4954 .newBuilder ()
50- .setStringValue ( event .getContentType ())
55+ .setBytesValue ( ByteString . copyFromUtf8 ( event .getContentType () ))
5156 .build ())
52- .putProperties (SystemMetadataKeys .TYPE , DynamicValueOuterClass
57+ .putProperties (SystemMetadataKeys .SCHEMA_NAME , DynamicValueOuterClass
5358 .DynamicValue
5459 .newBuilder ()
55- .setStringValue ( event .getEventType ())
60+ .setBytesValue ( ByteString . copyFromUtf8 ( event .getEventType () ))
5661 .build ())
5762 .build ());
5863 }
0 commit comments