use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW in project zilla by aklivity.
the class KafkaMergedFactory method newStream.
@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer sender) {
final BeginFW begin = beginRO.wrap(buffer, index, index + length);
final long routeId = begin.routeId();
final long initialId = begin.streamId();
final long authorization = begin.authorization();
final long affinity = begin.affinity();
assert (initialId & 0x0000_0000_0000_0001L) != 0L;
final OctetsFW extension = begin.extension();
final ExtensionFW beginEx = extensionRO.tryWrap(extension.buffer(), extension.offset(), extension.limit());
final KafkaBeginExFW kafkaBeginEx = beginEx != null && beginEx.typeId() == kafkaTypeId ? kafkaBeginExRO.tryWrap(extension.buffer(), extension.offset(), extension.limit()) : null;
assert kafkaBeginEx != null;
assert kafkaBeginEx.kind() == KafkaBeginExFW.KIND_MERGED;
final KafkaMergedBeginExFW kafkaMergedBeginEx = kafkaBeginEx.merged();
final KafkaCapabilities capabilities = kafkaMergedBeginEx.capabilities().get();
final String16FW beginTopic = kafkaMergedBeginEx.topic();
final String topicName = beginTopic.asString();
final KafkaDeltaType deltaType = kafkaMergedBeginEx.deltaType().get();
MessageConsumer newStream = null;
final KafkaBindingConfig binding = supplyBinding.apply(routeId);
if (binding != null && binding.merged(topicName)) {
final long resolvedId = routeId;
final ArrayFW<KafkaOffsetFW> partitions = kafkaMergedBeginEx.partitions();
final KafkaOffsetFW partition = partitions.matchFirst(p -> p.partitionId() == -1L);
final long defaultOffset = partition != null ? partition.partitionOffset() : HISTORICAL.value();
final Long2LongHashMap initialOffsetsById = new Long2LongHashMap(-3L);
partitions.forEach(p -> {
final long partitionId = p.partitionId();
if (partitionId >= 0L) {
final long partitionOffset = p.partitionOffset();
initialOffsetsById.put(partitionId, partitionOffset);
}
});
newStream = new KafkaMergedStream(sender, routeId, initialId, affinity, authorization, topicName, resolvedId, capabilities, initialOffsetsById, defaultOffset, deltaType)::onMergedMessage;
}
return newStream;
}
Aggregations