Search in sources :

Example 6 with KafkaBindingConfig

use of io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig in project zilla by aklivity.

the class KafkaClientFactory method attach.

@Override
public void attach(BindingConfig binding) {
    KafkaBindingConfig kafkaBinding = new KafkaBindingConfig(binding);
    bindings.put(binding.id, kafkaBinding);
}
Also used : KafkaBindingConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig)

Example 7 with KafkaBindingConfig

use of io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig in project zilla by aklivity.

the class KafkaClientProduceFactory 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 long routeId = begin.routeId();
    final long initialId = begin.streamId();
    final long affinity = begin.affinity();
    final long authorization = begin.authorization();
    final OctetsFW extension = begin.extension();
    final ExtensionFW beginEx = extensionRO.tryWrap(extension.buffer(), extension.offset(), extension.limit());
    final KafkaBeginExFW kafkaBeginEx = beginEx.typeId() == kafkaTypeId ? extension.get(kafkaBeginExRO::wrap) : null;
    assert kafkaBeginEx == null || kafkaBeginEx.kind() == KafkaBeginExFW.KIND_PRODUCE;
    final KafkaProduceBeginExFW kafkaProduceBeginEx = kafkaBeginEx != null ? kafkaBeginEx.produce() : null;
    MessageConsumer newStream = null;
    if (kafkaProduceBeginEx != null) {
        final String16FW beginTopic = kafkaProduceBeginEx.topic();
        final String topicName = beginTopic.asString();
        final KafkaBindingConfig binding = supplyBinding.apply(routeId);
        final KafkaRouteConfig resolved = binding != null ? binding.resolve(authorization, topicName) : null;
        if (resolved != null && kafkaBeginEx != null) {
            final long resolvedId = resolved.id;
            final int partitionId = kafkaProduceBeginEx.partition().partitionId();
            newStream = new KafkaProduceStream(application, routeId, initialId, affinity, resolvedId, topicName, partitionId)::onApplication;
        }
    }
    return newStream;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) KafkaProduceBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaProduceBeginExFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) KafkaBindingConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW) KafkaRouteConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)

Example 8 with KafkaBindingConfig

use of io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig in project zilla by aklivity.

the class KafkaClientFetchFactory 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 long routeId = begin.routeId();
    final long initialId = begin.streamId();
    final long leaderId = begin.affinity();
    final long authorization = begin.authorization();
    final OctetsFW extension = begin.extension();
    final ExtensionFW beginEx = extensionRO.tryWrap(extension.buffer(), extension.offset(), extension.limit());
    final KafkaBeginExFW kafkaBeginEx = beginEx.typeId() == kafkaTypeId ? extension.get(kafkaBeginExRO::wrap) : null;
    assert kafkaBeginEx == null || kafkaBeginEx.kind() == KafkaBeginExFW.KIND_FETCH;
    final KafkaFetchBeginExFW kafkaFetchBeginEx = kafkaBeginEx != null ? kafkaBeginEx.fetch() : null;
    MessageConsumer newStream = null;
    if (beginEx != null && kafkaFetchBeginEx != null && kafkaFetchBeginEx.filters().isEmpty()) {
        final String16FW beginTopic = kafkaFetchBeginEx.topic();
        final String topicName = beginTopic.asString();
        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 KafkaOffsetFW partition = kafkaFetchBeginEx.partition();
            final int partitionId = partition.partitionId();
            final long initialOffset = partition.partitionOffset();
            final long latestOffset = partition.latestOffset();
            newStream = new KafkaFetchStream(application, routeId, initialId, resolvedId, topicName, partitionId, latestOffset, leaderId, initialOffset)::onApplication;
        }
    }
    return newStream;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) KafkaFetchBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaFetchBeginExFW) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) KafkaBindingConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW) KafkaRouteConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig) KafkaOffsetFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetFW) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)

Example 9 with KafkaBindingConfig

use of io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig in project zilla by aklivity.

the class KafkaClientMetaFactory 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 long routeId = begin.routeId();
    final long initialId = begin.streamId();
    final long affinity = begin.affinity();
    final long authorization = begin.authorization();
    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.kind() == KafkaBeginExFW.KIND_META;
    final String16FW beginTopic = kafkaBeginEx.meta().topic();
    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 && kafkaBeginEx != null) {
        final long resolvedId = resolved.id;
        newStream = new KafkaMetaStream(application, routeId, initialId, affinity, resolvedId, topicName)::onApplication;
    }
    return newStream;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) KafkaRouteConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) KafkaBindingConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW)

Example 10 with KafkaBindingConfig

use of io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig 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;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) KafkaProduceBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaProduceBeginExFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) KafkaCachePartition(io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCachePartition) KafkaCacheClientBudget(io.aklivity.zilla.runtime.binding.kafka.internal.budget.KafkaCacheClientBudget) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) KafkaBindingConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW) KafkaCacheTopic(io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCacheTopic) KafkaCache(io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCache) KafkaRouteConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)

Aggregations

KafkaBindingConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig)17 OctetsFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW)14 BeginFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)14 KafkaBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW)14 MessageConsumer (io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer)14 String16FW (io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)13 ExtensionFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW)13 KafkaRouteConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig)11 KafkaCache (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCache)6 KafkaCacheTopic (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCacheTopic)6 KafkaCachePartition (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCachePartition)4 KafkaOffsetFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetFW)4 KafkaDeltaType (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType)3 KafkaDescribeBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaDescribeBeginExFW)3 KafkaFetchBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaFetchBeginExFW)3 KafkaProduceBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaProduceBeginExFW)3 ArrayList (java.util.ArrayList)3 KafkaTopicConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaTopicConfig)2 KafkaOffsetType (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType)2 KafkaBinding (io.aklivity.zilla.runtime.binding.kafka.internal.KafkaBinding)1