Search in sources :

Example 1 with KafkaMetaBeginExFW

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

the class KafkaCacheMetaFactory 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 = extension.get(extensionRO::tryWrap);
    assert beginEx != null && beginEx.typeId() == kafkaTypeId;
    final KafkaBeginExFW kafkaBeginEx = extension.get(kafkaBeginExRO::wrap);
    assert kafkaBeginEx.kind() == KafkaBeginExFW.KIND_META;
    final KafkaMetaBeginExFW kafkaMetaBeginEx = kafkaBeginEx.meta();
    final String16FW beginTopic = kafkaMetaBeginEx.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) {
        final long resolvedId = resolved.id;
        final KafkaCacheRoute cacheRoute = supplyCacheRoute.apply(resolvedId);
        final int topicKey = cacheRoute.topicKey(topicName);
        KafkaCacheMetaFanout fanout = cacheRoute.metaFanoutsByTopic.get(topicKey);
        if (fanout == null) {
            final long cacheId = supplyCacheId.applyAsLong(routeId, resolvedId);
            final String cacheName = String.format("%s.%s", supplyNamespace.apply(cacheId), supplyLocalName.apply(cacheId));
            final KafkaCache cache = supplyCache.apply(cacheName);
            final KafkaCacheTopic topic = cache.supplyTopic(topicName);
            final KafkaCacheMetaFanout newFanout = new KafkaCacheMetaFanout(resolvedId, authorization, topic);
            cacheRoute.metaFanoutsByTopic.put(topicKey, newFanout);
            fanout = newFanout;
        }
        if (fanout != null) {
            newStream = new KafkaCacheMetaStream(fanout, sender, routeId, initialId, affinity, authorization)::onMetaMessage;
        }
    }
    return newStream;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) KafkaMetaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaMetaBeginExFW) 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

KafkaCache (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCache)1 KafkaCacheTopic (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCacheTopic)1 KafkaBindingConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig)1 KafkaRouteConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig)1 OctetsFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW)1 String16FW (io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)1 BeginFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)1 ExtensionFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW)1 KafkaBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW)1 KafkaMetaBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaMetaBeginExFW)1 MessageConsumer (io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer)1