Search in sources :

Example 11 with MessageConsumer

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

the class ProxyServerFactory 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();
    MessageConsumer newStream = null;
    final ProxyBindingConfig binding = router.lookup(routeId);
    if (binding != null) {
        newStream = new ProxyNetServer(routeId, initialId, sender, affinity)::onNetMessage;
    }
    return newStream;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) ProxyBindingConfig(io.aklivity.zilla.runtime.binding.proxy.internal.config.ProxyBindingConfig) BeginFW(io.aklivity.zilla.runtime.binding.proxy.internal.types.stream.BeginFW)

Example 12 with MessageConsumer

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

the class ProxyServerFactory method newStream.

private MessageConsumer newStream(MessageConsumer sender, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Flyweight extension) {
    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.buffer(), extension.offset(), extension.sizeof()).build();
    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.proxy.internal.types.stream.BeginFW)

Example 13 with MessageConsumer

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

the class SseServerFactory method doHttpBegin.

private void doHttpBegin(MessageConsumer receiver, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Consumer<Array32FW.Builder<HttpHeaderFW.Builder, HttpHeaderFW>> mutator) {
    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(e -> e.set(visitHttpBeginEx(mutator))).build();
    receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
}
Also used : NO_DEBITOR_INDEX(io.aklivity.zilla.runtime.engine.budget.BudgetDebitor.NO_DEBITOR_INDEX) URLDecoder(java.net.URLDecoder) LongSupplier(java.util.function.LongSupplier) BindingHandler(io.aklivity.zilla.runtime.engine.binding.BindingHandler) Flags(io.aklivity.zilla.runtime.binding.sse.internal.util.Flags) SseConfiguration(io.aklivity.zilla.runtime.binding.sse.internal.SseConfiguration) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Capability(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.Capability) FIN(io.aklivity.zilla.runtime.binding.sse.internal.util.Flags.FIN) Matcher(java.util.regex.Matcher) ToLongFunction(java.util.function.ToLongFunction) SIZE_OF_BYTE(org.agrona.BitUtil.SIZE_OF_BYTE) OctetsFW(io.aklivity.zilla.runtime.binding.sse.internal.types.OctetsFW) EngineContext(io.aklivity.zilla.runtime.engine.EngineContext) BufferPool(io.aklivity.zilla.runtime.engine.buffer.BufferPool) ChallengeFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.ChallengeFW) SseDataExFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.SseDataExFW) AbortFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.AbortFW) BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) SseBindingConfig(io.aklivity.zilla.runtime.binding.sse.internal.config.SseBindingConfig) SseRouteConfig(io.aklivity.zilla.runtime.binding.sse.internal.config.SseRouteConfig) INIT(io.aklivity.zilla.runtime.binding.sse.internal.util.Flags.INIT) WindowFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.WindowFW) MutableDirectBuffer(org.agrona.MutableDirectBuffer) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Array32FW(io.aklivity.zilla.runtime.binding.sse.internal.types.Array32FW) DirectBuffer(org.agrona.DirectBuffer) HttpBeginExFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.HttpBeginExFW) LangUtil.rethrowUnchecked(org.agrona.LangUtil.rethrowUnchecked) SseEventFW(io.aklivity.zilla.runtime.binding.sse.internal.types.codec.SseEventFW) String16FW(io.aklivity.zilla.runtime.binding.sse.internal.types.String16FW) DataFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.DataFW) Long2ObjectHashMap(org.agrona.collections.Long2ObjectHashMap) ResetFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.ResetFW) HttpHeaderFW(io.aklivity.zilla.runtime.binding.sse.internal.types.HttpHeaderFW) EndFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.EndFW) SseEndExFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.SseEndExFW) LongFunction(java.util.function.LongFunction) FlushFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.FlushFW) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Flyweight(io.aklivity.zilla.runtime.binding.sse.internal.types.Flyweight) BudgetDebitor(io.aklivity.zilla.runtime.engine.budget.BudgetDebitor) Json(jakarta.json.Json) SseBeginExFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.SseBeginExFW) Consumer(java.util.function.Consumer) JsonObjectBuilder(jakarta.json.JsonObjectBuilder) HttpChallengeExFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.HttpChallengeExFW) SseBinding(io.aklivity.zilla.runtime.binding.sse.internal.SseBinding) BeginFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.BeginFW) LongUnaryOperator(java.util.function.LongUnaryOperator) String8FW(io.aklivity.zilla.runtime.binding.sse.internal.types.String8FW) NO_SLOT(io.aklivity.zilla.runtime.engine.buffer.BufferPool.NO_SLOT) BeginFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.BeginFW)

Example 14 with MessageConsumer

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

the class SseServerFactory method newInitialSseStream.

public MessageConsumer newInitialSseStream(final BeginFW begin, final MessageConsumer network, final HttpBeginExFW httpBeginEx) {
    final long routeId = begin.routeId();
    final long initialId = begin.streamId();
    final long traceId = begin.traceId();
    final long authorization = begin.authorization();
    final long affinity = begin.affinity();
    Array32FW<HttpHeaderFW> headers = httpBeginEx.headers();
    httpHelper.reset();
    headers.forEach(httpHelper::onHttpHeader);
    // TODO: ":pathinfo" ?
    String16FW pathInfo = httpHelper.path;
    String16FW lastEventId = httpHelper.lastEventId;
    // use query parameter value as default for missing Last-Event-ID header
    if (pathInfo != null) {
        Matcher matcher = QUERY_PARAMS_PATTERN.matcher(pathInfo.asString());
        if (matcher.matches()) {
            String path = matcher.group("path");
            String query = matcher.group("query");
            matcher = LAST_EVENT_ID_PATTERN.matcher(query);
            StringBuffer builder = new StringBuffer(path);
            while (matcher.find()) {
                if (lastEventId == null) {
                    lastEventId = decodeLastEventId(matcher.group("lastEventId"));
                }
                String replacement = matcher.group(3).isEmpty() ? "$3" : "$1";
                matcher.appendReplacement(builder, replacement);
            }
            matcher.appendTail(builder);
            pathInfo = new String16FW(builder.toString());
        }
    }
    MessageConsumer newStream = null;
    if (lastEventId == null || lastEventId.length() <= MAXIMUM_LAST_EVENT_ID_SIZE) {
        final SseBindingConfig binding = bindings.get(routeId);
        final SseRouteConfig resolved = binding != null ? binding.resolve(authorization, pathInfo.asString()) : null;
        if (resolved != null) {
            final boolean timestampRequested = httpBeginEx.headers().anyMatch(header -> HEADER_NAME_ACCEPT.equals(header.name()) && header.value().asString().contains("ext=timestamp"));
            final String8FW lastEventId8 = httpHelper.asLastEventId(lastEventId);
            final SseServer server = new SseServer(network, routeId, initialId, resolved.id, timestampRequested);
            server.onNetBegin(begin);
            server.stream.doAppBegin(traceId, authorization, affinity, pathInfo, lastEventId8);
            newStream = server::onNetMessage;
        }
    } else {
        doHttpResponse(begin, network, HEADER_VALUE_STATUS_400);
        newStream = (t, b, i, l) -> {
        };
    }
    return newStream;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) Matcher(java.util.regex.Matcher) SseBindingConfig(io.aklivity.zilla.runtime.binding.sse.internal.config.SseBindingConfig) String8FW(io.aklivity.zilla.runtime.binding.sse.internal.types.String8FW) HttpHeaderFW(io.aklivity.zilla.runtime.binding.sse.internal.types.HttpHeaderFW) String16FW(io.aklivity.zilla.runtime.binding.sse.internal.types.String16FW) SseRouteConfig(io.aklivity.zilla.runtime.binding.sse.internal.config.SseRouteConfig)

Example 15 with MessageConsumer

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

the class SseServerFactory method newStream.

@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer network) {
    final BeginFW begin = beginRO.wrap(buffer, index, index + length);
    final OctetsFW extension = begin.extension();
    final HttpBeginExFW httpBeginEx = extension.get(httpBeginExRO::tryWrap);
    MessageConsumer newStream = null;
    if (!isSseRequestMethod(httpBeginEx)) {
        doHttpResponse(begin, network, HEADER_VALUE_STATUS_405);
        newStream = (t, b, i, l) -> {
        };
    } else {
        newStream = newInitialSseStream(begin, network, httpBeginEx);
    }
    return newStream;
}
Also used : HttpBeginExFW(io.aklivity.zilla.runtime.binding.sse.internal.types.stream.HttpBeginExFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) OctetsFW(io.aklivity.zilla.runtime.binding.sse.internal.types.OctetsFW) BeginFW(io.aklivity.zilla.runtime.binding.sse.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