Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
grpc-kafka fetch changes
  • Loading branch information
ankitk-me committed Jul 10, 2024
commit 0d7af5b2b8a6fa3176e5ecf61ba81fe375f2e45c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ protected void onKafkaAbort(
long traceId,
long authorization)
{
if (!GrpcKafkaState.replyOpening(state))
{
doGrpcBegin(traceId, authorization, 0L, emptyRO);
}

cleanup(traceId, authorization);
}

Expand Down Expand Up @@ -569,6 +574,15 @@ protected void onKafkaData(
int length,
OctetsFW extension)
{
if (!GrpcKafkaState.replyOpening(state))
{
final ExtensionFW dataEx = extension.get(extensionRO::tryWrap);
final KafkaDataExFW kafkaDataEx =
dataEx != null && dataEx.typeId() == kafkaTypeId ? extension.get(kafkaDataExRO::tryWrap) : null;

doGrpcBegin(traceId, authorization, 0L, kafkaDataEx.merged().fetch().headers());
Comment thread
ankitk-me marked this conversation as resolved.
Outdated
}

doGrpcData(traceId, authorization, budgetId, reserved, flags, buffer, offset, length);
}

Expand Down Expand Up @@ -623,6 +637,50 @@ private void doGrpcBegin(
traceId, authorization, affinity, extension);
}

private void doGrpcBegin(
long traceId,
long authorization,
long affinity,
Array32FW<KafkaHeaderFW> headers)
{
state = GrpcKafkaState.openingReply(state);

Array32FW.Builder<GrpcMetadataFW.Builder, GrpcMetadataFW> builder =
grpcMetadataRW.wrap(metaBuffer, 0, metaBuffer.capacity());

headers.forEach(h ->
{
final OctetsFW name = h.name();
final DirectBuffer buffer = name.buffer();
final int offset = name.offset();
final int limit = name.limit();
buffer.getBytes(offset, headerPrefix);
buffer.getBytes(limit - BIN_SUFFIX.length, headerSuffix);
if (Arrays.equals(META_PREFIX, headerPrefix))
{
final GrpcType type = Arrays.equals(BIN_SUFFIX, headerSuffix) ? BASE64 : TEXT;
final int nameLen = type == BASE64
? h.nameLen() - META_PREFIX_LENGTH - BIN_SUFFIX_LENGTH
: h.nameLen() - META_PREFIX_LENGTH;
builder.item(m -> m
.type(t -> t.set(type))
.nameLen(nameLen)
.name(name.value(), META_PREFIX_LENGTH, nameLen)
.valueLen(h.valueLen())
.value(h.value()));
}
});

GrpcBeginExFW beginEx = grpcBeginExRW
.wrap(extBuffer, 0, extBuffer.capacity())
.typeId(grpcTypeId)
.metadata(builder.build())
.build();

doBegin(grpc, originId, routedId, replyId, replySeq, replyAck, replyMax,
traceId, authorization, affinity, beginEx);
}

private void doGrpcData(
long traceId,
long authorization,
Expand Down Expand Up @@ -865,8 +923,6 @@ private void onKafkaBegin(
int lenSize = len.sizeof();
replyPad = result.fieldId().sizeof() + lenSize + partitions.sizeof();
}

delegate.onKafkaBegin(traceId, authorization, extension);
}

private void onKafkaData(
Expand Down Expand Up @@ -939,7 +995,7 @@ private void onKafkaData(
}

int length = encodeProgress - encodeOffset;
delegate.onKafkaData(traceId, authorization, budgetId, reserved, flags,
delegate.onKafkaData(traceId, authorization, budgetId, reserved + length, flags,
encodeBuffer, encodeOffset, length, extension);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
connect "zilla://streams/grpc0"
option zilla:window 8192
option zilla:transmission "half-duplex"
option zilla:update "proactive"

write zilla:begin.ext ${grpc:beginEx()
.typeId(zilla:id("grpc"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
connect "zilla://streams/grpc0"
option zilla:window 8192
option zilla:transmission "half-duplex"
option zilla:update "proactive"

write zilla:begin.ext ${grpc:beginEx()
.typeId(zilla:id("grpc"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
connect "zilla://streams/grpc0"
option zilla:window 8192
option zilla:transmission "half-duplex"
option zilla:update "proactive"

write zilla:begin.ext ${grpc:beginEx()
.typeId(zilla:id("grpc"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
connect "zilla://streams/grpc0"
option zilla:window 8192
option zilla:transmission "half-duplex"
option zilla:update "proactive"

write zilla:begin.ext ${grpc:beginEx()
.typeId(zilla:id("grpc"))
Expand All @@ -32,6 +33,12 @@ write flush

write close

read zilla:begin.ext ${grpc:matchBeginEx()
.typeId(zilla:id("grpc"))
.metadata("custom", "value")
.metadata("BASE64", "customProperty", "dGVzdA==")
Comment thread
ankitk-me marked this conversation as resolved.
Outdated
.build()}

read ${grpc:protobuf()
.string(1, "Hello World")
.bytes(32767, grpc_kafka:messageId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ read zilla:data.empty

read closed

write zilla:begin.ext ${grpc:beginEx()
.typeId(zilla:id("grpc"))
.metadata("custom", "value")
.metadata("BASE64", "customProperty", "dGVzdA==")
.build()}

write ${grpc:protobuf()
.string(1, "Hello World")
.bytes(32767, grpc_kafka:messageId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
connect "zilla://streams/grpc0"
option zilla:window 8192
option zilla:transmission "half-duplex"
option zilla:update "proactive"

write zilla:begin.ext ${grpc:beginEx()
.typeId(zilla:id("grpc"))
Expand All @@ -31,6 +32,12 @@ write flush

write close

read zilla:begin.ext ${grpc:matchBeginEx()
.typeId(zilla:id("grpc"))
.metadata("custom", "value")
.metadata("BASE64", "customProperty", "dGVzdA==")
.build()}

read ${grpc:protobuf()
.string(1, "Hello World")
.bytes(32767, grpc_kafka:messageId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ read zilla:data.empty

read closed

write zilla:begin.ext ${grpc:beginEx()
.typeId(zilla:id("grpc"))
.metadata("custom", "value")
.metadata("BASE64", "customProperty", "dGVzdA==")
.build()}

write ${grpc:protobuf()
.string(1, "Hello World")
.bytes(32767, grpc_kafka:messageId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ read zilla:data.ext ${kafka:matchDataEx()
.progress(0, 2)
.progress(1, 1)
.key("test")
.header("meta:custom", "value")
.header("meta:customProperty-bin", "dGVzdA==")
.build()
.build()}
read ${grpc:protobuf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ write zilla:data.ext ${kafka:dataEx()
.progress(0, 2)
.progress(1, 1)
.key("test")
.header("meta:custom", "value")
.header("meta:customProperty-bin", "dGVzdA==")
.build()
.build()}
write ${grpc:protobuf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ read zilla:data.ext ${kafka:matchDataEx()
.progress(0, 2)
.progress(1, 1)
.key("test")
.header("meta:custom", "value")
.header("meta:customProperty-bin", "dGVzdA==")
.build()
.build()}
read ${grpc:protobuf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ write zilla:data.ext ${kafka:dataEx()
.progress(0, 2)
.progress(1, 1)
.key("test")
.header("meta:custom", "value")
.header("meta:customProperty-bin", "dGVzdA==")
.build()
.build()}
write ${grpc:protobuf()
Expand Down