use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaClientProduceFactory method doBegin.
private void doBegin(MessageConsumer receiver, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Consumer<OctetsFW.Builder> extension) {
final BeginFW begin = beginRW.wrap(writeBuffer, 0, writeBuffer.capacity()).routeId(routeId).streamId(streamId).sequence(sequence).acknowledge(acknowledge).maximum(maximum).traceId(traceId).authorization(authorization).affinity(affinity).extension(extension).build();
receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
}
use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaClientDescribeFactory method doBegin.
private void doBegin(MessageConsumer receiver, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Consumer<OctetsFW.Builder> extension) {
final BeginFW begin = beginRW.wrap(writeBuffer, 0, writeBuffer.capacity()).routeId(routeId).streamId(streamId).sequence(sequence).acknowledge(acknowledge).maximum(maximum).traceId(traceId).authorization(authorization).affinity(affinity).extension(extension).build();
receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
}
use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaClientDescribeFactory method newStream.
private MessageConsumer newStream(MessageConsumer sender, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Consumer<OctetsFW.Builder> extension) {
final BeginFW begin = beginRW.wrap(writeBuffer, 0, writeBuffer.capacity()).routeId(routeId).streamId(streamId).sequence(sequence).acknowledge(acknowledge).maximum(maximum).traceId(traceId).authorization(authorization).affinity(affinity).extension(extension).build();
final MessageConsumer receiver = streamFactory.newStream(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof(), sender);
receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
return receiver;
}
use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaClientFactory method newStream.
@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer application) {
final BeginFW begin = beginRO.wrap(buffer, index, index + length);
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;
MessageConsumer newStream = null;
if (kafkaBeginEx != null) {
final BindingHandler factory = factories.get(kafkaBeginEx.kind());
if (factory != null) {
newStream = factory.newStream(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof(), application);
}
}
return newStream;
}
use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaCacheClientProduceFactory 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 affinity = begin.affinity();
final long authorization = begin.authorization();
assert (initialId & 0x0000_0000_0000_0001L) != 0L;
final OctetsFW extension = begin.extension();
final ExtensionFW beginEx = extension.get(extensionRO::tryWrap);
assert beginEx != null && beginEx.typeId() == kafkaTypeId;
final KafkaBeginExFW kafkaBeginEx = extension.get(kafkaBeginExRO::wrap);
assert kafkaBeginEx.kind() == KafkaBeginExFW.KIND_PRODUCE;
final KafkaProduceBeginExFW kafkaProduceBeginEx = kafkaBeginEx.produce();
final String16FW beginTopic = kafkaProduceBeginEx.topic();
final int partitionId = kafkaProduceBeginEx.partition().partitionId();
final String topicName = beginTopic.asString();
MessageConsumer newStream = null;
final KafkaBindingConfig binding = supplyBinding.apply(routeId);
final KafkaRouteConfig resolved = binding != null ? binding.resolve(authorization, topicName) : null;
if (resolved != null) {
final long resolvedId = resolved.id;
final KafkaCacheRoute cacheRoute = supplyCacheRoute.apply(resolvedId);
final long topicKey = cacheRoute.topicKey(topicName);
final long partitionKey = cacheRoute.topicPartitionKey(topicName, partitionId);
KafkaCacheClientProduceFan fan = cacheRoute.clientProduceFansByTopicPartition.get(partitionKey);
if (fan == null) {
KafkaCacheClientBudget budget = cacheRoute.clientBudgetsByTopic.get(topicKey);
if (budget == null) {
budget = new KafkaCacheClientBudget(creditor, supplyBudgetId.getAsLong(), bufferPool.slotCapacity());
cacheRoute.clientBudgetsByTopic.put(topicKey, budget);
}
final String cacheName = String.format("%s.%s", supplyNamespace.apply(resolvedId), supplyLocalName.apply(resolvedId));
final KafkaCache cache = supplyCache.apply(cacheName);
final KafkaCacheTopic topic = cache.supplyTopic(topicName);
final KafkaCachePartition partition = topic.supplyProducePartition(partitionId, localIndex);
final KafkaCacheClientProduceFan newFan = new KafkaCacheClientProduceFan(resolvedId, authorization, affinity, budget, partition);
cacheRoute.clientProduceFansByTopicPartition.put(partitionKey, newFan);
fan = newFan;
}
final int leaderId = cacheRoute.leadersByPartitionId.get(partitionId);
newStream = new KafkaCacheClientProduceStream(fan, sender, routeId, initialId, leaderId, authorization)::onClientMessage;
}
return newStream;
}
Aggregations