io.gravitee.gateway.reactive.api.context.kafka.KafkaMessageResponse Maven / Gradle / Ivy
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.gateway.reactive.api.context.kafka;
import io.gravitee.gateway.reactive.api.message.kafka.KafkaMessage;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.FlowableTransformer;
import io.reactivex.rxjava3.core.Maybe;
import java.util.function.Function;
/**
* Represents a response that can manipulate a flow of messages that is mapped from a Kafka native FetchResponse.
*
* @author Jeoffrey HAEYAERT (jeoffrey.haeyaert at graviteesource.com)
* @author GraviteeSource Team
*/
public interface KafkaMessageResponse {
/**
* Get the flow of messages.
* Messages are extracted from the ProduceRequest.
* WARN: you should not keep a direct reference on the message flow as it could be overridden by others at anytime.
*
* @return a {@link Flowable} of {@link KafkaMessage}.
*/
Flowable messages();
/**
* Set the request message flow.
* WARN:
*
* - Replacing the message flow DOES NOT take care of the previous message flow in place.
* - You MUST ensure to consume the previous message flow when using it.
* - You SHOULD consider using {@link #onMessages(FlowableTransformer)} or {@link #onMessage(Function)} that may be more appropriate for message transformation.
*
*
* @see #onMessage(Function)
* @see #onMessages(FlowableTransformer)
* @param messages the flow of messages.
*/
void messages(final Flowable messages);
/**
* Applies a given transformation on each message.
* Messages are extracted from the ProduceRequest.
* Ex:
*
* request.onMessages(messages -> messages.flatMap(message -> transformMyMessage(message)));
*
*
* @param onMessages the transformer that will be applied on each message.
* @return a {@link Completable} that completes once the message transformation has been set up on the message flow (not executed).
*/
Completable onMessages(final FlowableTransformer onMessages);
/**
* Applies a given transformation on each message.
* Messages are extracted from the ProduceRequest.
* Ex:
* Discard a message:
*
* request.onMessage(message -> Maybe.empty());
*
*
* Update a message:
*
* request.onMessage(message -> transformMyMessage(message));
*
*
* @param onMessage the transformer that will be applied on each message.
* @return a {@link Completable} that completes once the message transformation has been set up on the message flow (not executed).
*/
default Completable onMessage(Function> onMessage) {
return onMessages(messages -> messages.concatMapMaybe(onMessage::apply));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy