Search in sources :

Example 21 with MessageConsumer

use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.

the class KafkaCacheServerProduceFactory 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;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)

Example 22 with MessageConsumer

use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.

the class KafkaCacheServerProduceFactory 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 KafkaProduceBeginExFW kafkaProduceBeginEx = kafkaBeginEx.produce();
    final String16FW beginTopic = kafkaProduceBeginEx.topic();
    final int partitionId = kafkaProduceBeginEx.partition().partitionId();
    final int remoteIndex = supplyRemoteIndex.applyAsInt(initialId);
    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);
        KafkaCacheServerProduceFan fan = cacheRoute.serverProduceFansByTopicPartition.get(partitionKey);
        if (fan == null) {
            final KafkaCacheServerProduceFan newFan = new KafkaCacheServerProduceFan(resolvedId, authorization, affinity, partitionId, topicName);
            cacheRoute.serverProduceFansByTopicPartition.put(partitionKey, newFan);
            fan = newFan;
        }
        final int leaderId = cacheRoute.leadersByPartitionId.get(partitionId);
        final String cacheName = String.format("%s.%s", supplyNamespace.apply(routeId), supplyLocalName.apply(routeId));
        final KafkaCache cache = supplyCache.apply(cacheName);
        final KafkaCacheTopic topic = cache.supplyTopic(topicName);
        final KafkaCachePartition partition = topic.supplyProducePartition(partitionId, remoteIndex);
        newStream = new KafkaCacheServerProduceStream(fan, sender, routeId, initialId, leaderId, authorization, partition)::onServerMessage;
    }
    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) 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)

Example 23 with MessageConsumer

use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.

the class KafkaCacheServerFactory 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 OctetsFW extension = begin.extension();
    final ExtensionFW beginEx = extension.get(extensionRO::tryWrap);
    assert beginEx != null;
    final int typeId = beginEx.typeId();
    assert beginEx != null && typeId == kafkaTypeId;
    MessageConsumer newStream = null;
    final KafkaBeginExFW kafkaBeginEx = extension.get(kafkaBeginExRO::tryWrap);
    if (kafkaBeginEx != null) {
        final BindingHandler streamFactory = factories.get(kafkaBeginEx.kind());
        if (streamFactory != null) {
            newStream = streamFactory.newStream(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof(), sender);
        }
    }
    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) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW) BindingHandler(io.aklivity.zilla.runtime.engine.binding.BindingHandler)

Example 24 with MessageConsumer

use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.

the class KafkaClientDescribeFactory 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_DESCRIBE;
    final KafkaDescribeBeginExFW kafkaDescribeBeginEx = kafkaBeginEx.describe();
    final String16FW beginTopic = kafkaDescribeBeginEx.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 List<String> configs = new ArrayList<>();
        kafkaDescribeBeginEx.configs().forEach(c -> configs.add(c.asString()));
        newStream = new KafkaDescribeStream(application, routeId, initialId, affinity, resolvedId, topicName, configs)::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) ArrayList(java.util.ArrayList) 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) KafkaDescribeBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaDescribeBeginExFW) KafkaRouteConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)

Example 25 with MessageConsumer

use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.

the class KafkaClientFetchFactory 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;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)

Aggregations

MessageConsumer (io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer)77 BeginFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)31 OctetsFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW)17 ExtensionFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW)17 KafkaBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW)17 KafkaBindingConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig)14 String16FW (io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)14 BindingHandler (io.aklivity.zilla.runtime.engine.binding.BindingHandler)13 KafkaRouteConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig)11 BindingConfig (io.aklivity.zilla.runtime.engine.config.BindingConfig)10 MutableDirectBuffer (org.agrona.MutableDirectBuffer)10 EngineContext (io.aklivity.zilla.runtime.engine.EngineContext)9 LongUnaryOperator (java.util.function.LongUnaryOperator)9 DirectBuffer (org.agrona.DirectBuffer)9 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)9 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 BeginFW (io.aklivity.zilla.runtime.binding.tls.internal.types.stream.BeginFW)4