Search in sources :

Example 1 with KafkaDeltaType

use of io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType in project zilla by aklivity.

the class KafkaWithConfigAdapter method adaptFromJson.

@Override
public WithConfig adaptFromJson(JsonObject object) {
    KafkaOffsetType defaultOffset = object.containsKey(DEFAULT_OFFSET_NAME) ? KafkaOffsetType.valueOf(object.getString(DEFAULT_OFFSET_NAME).toUpperCase()) : null;
    KafkaDeltaType deltaType = object.containsKey(DELTA_TYPE_NAME) ? KafkaDeltaType.valueOf(object.getString(DELTA_TYPE_NAME).toUpperCase()) : null;
    return new KafkaWithConfig(defaultOffset, deltaType);
}
Also used : KafkaDeltaType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType) KafkaOffsetType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType)

Example 2 with KafkaDeltaType

use of io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType in project zilla by aklivity.

the class KafkaCacheClientFetchFactory 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_FETCH;
    final KafkaFetchBeginExFW kafkaFetchBeginEx = kafkaBeginEx.fetch();
    final String16FW beginTopic = kafkaFetchBeginEx.topic();
    final KafkaOffsetFW progress = kafkaFetchBeginEx.partition();
    final ArrayFW<KafkaFilterFW> filters = kafkaFetchBeginEx.filters();
    final KafkaDeltaType deltaType = kafkaFetchBeginEx.deltaType().get();
    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 int partitionId = progress.partitionId();
        final long partitionOffset = progress.partitionOffset();
        final KafkaCacheRoute cacheRoute = supplyCacheRoute.apply(resolvedId);
        final long partitionKey = cacheRoute.topicPartitionKey(topicName, partitionId);
        KafkaCacheClientFetchFanout fanout = cacheRoute.clientFetchFanoutsByTopicPartition.get(partitionKey);
        if (fanout == null) {
            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.supplyFetchPartition(partitionId);
            final long defaultOffset = resolved.with != null ? resolved.with.defaultOffset.value() : KafkaOffsetType.HISTORICAL.value();
            final KafkaCacheClientFetchFanout newFanout = new KafkaCacheClientFetchFanout(resolvedId, authorization, affinity, partition, defaultOffset);
            cacheRoute.clientFetchFanoutsByTopicPartition.put(partitionKey, newFanout);
            fanout = newFanout;
        }
        final KafkaFilterCondition condition = cursorFactory.asCondition(filters);
        final long latestOffset = kafkaFetchBeginEx.partition().latestOffset();
        final KafkaOffsetType maximumOffset = KafkaOffsetType.valueOf((byte) latestOffset);
        final int leaderId = cacheRoute.leadersByPartitionId.get(partitionId);
        newStream = new KafkaCacheClientFetchStream(fanout, sender, routeId, initialId, leaderId, authorization, partitionOffset, condition, maximumOffset, deltaType)::onClientMessage;
    }
    return newStream;
}
Also used : KafkaCachePartition(io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCachePartition) KafkaDeltaType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType) 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) KafkaCache(io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCache) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW) ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) 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) KafkaRouteConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig) KafkaOffsetFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetFW) KafkaOffsetType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType) KafkaFilterCondition(io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCacheCursorFactory.KafkaFilterCondition) KafkaFilterFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaFilterFW)

Example 3 with KafkaDeltaType

use of io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType in project zilla by aklivity.

the class KafkaCacheServerFetchFactory 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::wrap);
    assert beginEx != null && beginEx.typeId() == kafkaTypeId;
    final KafkaBeginExFW kafkaBeginEx = extension.get(kafkaBeginExRO::wrap);
    final KafkaFetchBeginExFW kafkaFetchBeginEx = kafkaBeginEx.fetch();
    final String16FW beginTopic = kafkaFetchBeginEx.topic();
    final KafkaOffsetFW progress = kafkaFetchBeginEx.partition();
    final int partitionId = progress.partitionId();
    final long partitionOffset = progress.partitionOffset();
    final KafkaDeltaType deltaType = kafkaFetchBeginEx.deltaType().get();
    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 partitionKey = cacheRoute.topicPartitionKey(topicName, partitionId);
        KafkaCacheServerFetchFanout fanout = cacheRoute.serverFetchFanoutsByTopicPartition.get(partitionKey);
        if (fanout == null) {
            final KafkaTopicConfig topic = binding.topic(topicName);
            final KafkaDeltaType routeDeltaType = topic != null ? topic.deltaType : deltaType;
            final KafkaOffsetType defaultOffset = topic != null ? topic.defaultOffset : HISTORICAL;
            final String cacheName = String.format("%s.%s", supplyNamespace.apply(routeId), supplyLocalName.apply(routeId));
            final KafkaCache cache = supplyCache.apply(cacheName);
            final KafkaCacheTopic cacheTopic = cache.supplyTopic(topicName);
            final KafkaCachePartition partition = cacheTopic.supplyFetchPartition(partitionId);
            final KafkaCacheServerFetchFanout newFanout = new KafkaCacheServerFetchFanout(resolvedId, authorization, affinity, partition, routeDeltaType, defaultOffset);
            cacheRoute.serverFetchFanoutsByTopicPartition.put(partitionKey, newFanout);
            fanout = newFanout;
        }
        final int leaderId = cacheRoute.leadersByPartitionId.get(partitionId);
        newStream = new KafkaCacheServerFetchStream(fanout, sender, routeId, initialId, leaderId, authorization, partitionOffset)::onServerMessage;
    }
    return newStream;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) KafkaCachePartition(io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCachePartition) KafkaDeltaType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType) KafkaTopicConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaTopicConfig) 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) 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) KafkaOffsetFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetFW) KafkaOffsetType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)

Example 4 with KafkaDeltaType

use of io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType in project zilla by aklivity.

the class KafkaTopicConfigAdapter method adaptFromJson.

@Override
public KafkaTopicConfig adaptFromJson(JsonObject object) {
    String name = object.containsKey(NAME_NAME) ? object.getString(NAME_NAME) : null;
    KafkaOffsetType defaultOffset = object.containsKey(DEFAULT_OFFSET_NAME) ? KafkaOffsetType.valueOf(object.getString(DEFAULT_OFFSET_NAME).toUpperCase()) : null;
    KafkaDeltaType deltaType = object.containsKey(DELTA_TYPE_NAME) ? KafkaDeltaType.valueOf(object.getString(DELTA_TYPE_NAME).toUpperCase()) : null;
    return new KafkaTopicConfig(name, defaultOffset, deltaType);
}
Also used : KafkaDeltaType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType) KafkaOffsetType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType)

Example 5 with KafkaDeltaType

use of io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType 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;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) KafkaDeltaType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) KafkaMergedBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaMergedBeginExFW) 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) Long2LongHashMap(org.agrona.collections.Long2LongHashMap) KafkaCapabilities(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaCapabilities) KafkaOffsetFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetFW) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)

Aggregations

KafkaDeltaType (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType)5 KafkaOffsetType (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType)4 KafkaBindingConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig)3 KafkaOffsetFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetFW)3 OctetsFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW)3 String16FW (io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)3 BeginFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)3 ExtensionFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW)3 KafkaBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW)3 MessageConsumer (io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer)3 KafkaCache (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCache)2 KafkaCachePartition (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCachePartition)2 KafkaCacheTopic (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCacheTopic)2 KafkaRouteConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig)2 KafkaFetchBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaFetchBeginExFW)2 KafkaFilterCondition (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCacheCursorFactory.KafkaFilterCondition)1 KafkaTopicConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaTopicConfig)1 KafkaCapabilities (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaCapabilities)1 KafkaFilterFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaFilterFW)1 KafkaMergedBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaMergedBeginExFW)1