Java Code Examples for org.eclipse.microprofile.reactive.messaging.Outgoing

The following examples show how to use org.eclipse.microprofile.reactive.messaging.Outgoing. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Incoming(NO_ACKNOWLEDGMENT)
@Acknowledgment(Acknowledgment.Strategy.NONE)
@Outgoing("sink-" + NO_ACKNOWLEDGMENT)
public String processorWithNoAck(String input) {
    processed(NO_ACKNOWLEDGMENT, input);
    return input + "1";
}
 
Example 2
@Incoming(MANUAL_ACKNOWLEDGMENT_UNI)
@Acknowledgment(Acknowledgment.Strategy.MANUAL)
@Outgoing("sink")
public Uni<Message<String>> processorWithAckUni(Message<String> input) {
    processed(MANUAL_ACKNOWLEDGMENT_UNI, input);
    return Uni.createFrom().completionStage(() -> input.ack()
            .thenApply(x -> Message.of(input.getPayload() + "1")));
}
 
Example 3
Source Project: quarkus-quickstarts   Source File: ValuesGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@Outgoing("temperature-values")
public Flowable<KafkaRecord<Integer, String>> generate() {

    return Flowable.interval(500, TimeUnit.MILLISECONDS)
            .onBackpressureDrop()
            .map(tick -> {
                WeatherStation station = stations.get(random.nextInt(stations.size()));
                double temperature = BigDecimal.valueOf(random.nextGaussian() * 15 + station.averageTemperature)
                        .setScale(1, RoundingMode.HALF_UP)
                        .doubleValue();

                LOG.infov("station: {0}, temperature: {1}", station.name, temperature);
                return KafkaRecord.of(station.id, Instant.now() + ";" + temperature);
            });
}
 
Example 4
@Incoming(MANUAL_ACKNOWLEDGMENT)
@Acknowledgment(Acknowledgment.Strategy.MANUAL)
@Outgoing("sink-" + MANUAL_ACKNOWLEDGMENT)
public Publisher<Message<String>> processorWithAck(Message<String> input) {
    return ReactiveStreams.of(input)
            .flatMapCompletionStage(m -> m.ack().thenApply(x -> m))
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())))
            .peek(i -> processed(MANUAL_ACKNOWLEDGMENT, input))
            .buildRs();
}
 
Example 5
@Outgoing(PRE_ACKNOWLEDGMENT_BUILDER)
public Publisher<Message<String>> sourceToPreAckBuilder() {
    return Multi.createFrom().items("a", "b", "c", "d", "e")
            .map(payload -> Message.of(payload, () -> {
                nap();
                acknowledged(PRE_ACKNOWLEDGMENT_BUILDER, payload);
                return CompletableFuture.completedFuture(null);
            }));
}
 
Example 6
@Incoming("publisher-for-publisher-message")
@Outgoing("publisher-message")
public Publisher<Message<String>> processorOfMessages(Publisher<Message<Integer>> stream) {
  increment("publisher-message");
  return ReactiveStreams.fromPublisher(stream)
    .map(Message::getPayload)
    .map(i -> i + 1)
    .flatMap(i -> ReactiveStreams.of(i, i))
    .map(i -> Integer.toString(i))
    .map(Message::of)
    .buildRs();
}
 
Example 7
@Incoming(NO_ACKNOWLEDGMENT_BUILDER)
@Acknowledgment(Acknowledgment.Strategy.NONE)
@Outgoing("sink-" + NO_ACKNOWLEDGMENT_BUILDER)
public PublisherBuilder<Message<String>> processorWithNoAckWithBuilder(PublisherBuilder<Message<String>> input) {
    return input
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())))
            .peek(m -> processed(NO_ACKNOWLEDGMENT_BUILDER, m.getPayload()));
}
 
Example 8
@Incoming("count")
@Outgoing("sink")
public Publisher<String> process(Flowable<Integer> source) {
    return source
            .map(i -> i + 1)
            .flatMap(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i));
}
 
Example 9
@Incoming("source")
@Outgoing("p1")
public Message<Integer> processMessage(Message<Integer> input) {
    JmsProperties properties = JmsProperties.builder().with("prop", "bar").build();
    return Message.of(input.getPayload())
            .withMetadata(Metadata.of(OutgoingJmsMessageMetadata.builder()
                    .withProperties(properties)
                    .withCorrelationId("my-correlation-" + input.getPayload())
                    .withDestination(queue)
                    .build()));
}
 
Example 10
@Outgoing("prices")
public Multi<Message<Double>> generate() {
    // Build an infinite stream of random prices
    // It emits a price every second
    return Multi.createFrom().ticks().every(Duration.ofSeconds(1))
        .map(x -> Message.of(random.nextDouble()));
}
 
Example 11
Source Project: smallrye-reactive-messaging   Source File: HttpSinkTest.java    License: Apache License 2.0 5 votes vote down vote up
@Incoming("numbers")
@Outgoing("http")
public HttpMessage<JsonObject> sink(int i) {
    return HttpMessage.HttpMessageBuilder.<JsonObject> create()
            .withMethod("PUT")
            .withPayload(new JsonObject().put("value", i + 1))
            .withHeader("Content-Type", "application/json")
            .build();
}
 
Example 12
@Incoming("count")
@Outgoing("sink")
public Flux<Message<String>> process(Flux<Message<Integer>> source) {
    return source
            .map(Message::getPayload)
            .map(i -> i + 1)
            .flatMap(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i))
            .map(Message::of);
}
 
Example 13
@Outgoing("temperature-values")
public Flowable<KafkaRecord<String, String>> generate() {

    return Flowable.interval(10, TimeUnit.MILLISECONDS)
            .map(tick -> {
                double temperature = BigDecimal.valueOf(random.nextGaussian() * 15)
                        .setScale(1, RoundingMode.HALF_UP)
                        .doubleValue();
                return KafkaRecord.of("1", Instant.now().toEpochMilli() + ";" + temperature);
            });
}
 
Example 14
@Incoming(PAYLOAD_PRE_ACKNOWLEDGMENT)
@Acknowledgment(Acknowledgment.Strategy.PRE_PROCESSING)
@Outgoing("sink-" + PAYLOAD_PRE_ACKNOWLEDGMENT)
public Publisher<String> processorWithPrePayloadAck(Publisher<String> input) {
    return ReactiveStreams.fromPublisher(input)
            .flatMap(p -> ReactiveStreams.of(p, p))
            .peek(m -> processed(PAYLOAD_PRE_ACKNOWLEDGMENT, m))
            .buildRs();
}
 
Example 15
Source Project: quarkus   Source File: BeanReturningPayloads.java    License: Apache License 2.0 5 votes vote down vote up
@Blocking
@Outgoing("infinite-producer-payload")
public int create() {
    try {
        Thread.sleep(200);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    threads.add(Thread.currentThread().getName());
    return count.incrementAndGet();
}
 
Example 16
@Incoming("in")
@Outgoing("out")
public Multi<Message<String>> processMessageStream(Multi<Message<Integer>> stream) {
    return
        stream
            .onItem().produceUni(message ->
            invokeService(message.getPayload())
                .onFailure().recoverWithItem("fallback")
                .onItem().apply(message::withPayload)
        )
            .concatenate();

}
 
Example 17
@Outgoing(PAYLOAD_PRE_ACKNOWLEDGMENT_BUILDER)
public Publisher<Message<String>> sourceToPreWithPayloadAckWithBuilder() {
    return Multi.createFrom().items("a", "b", "c", "d", "e")
            .map(payload -> Message.of(payload, () -> {
                nap();
                acknowledged(PAYLOAD_PRE_ACKNOWLEDGMENT_BUILDER, payload);
                return CompletableFuture.completedFuture(null);
            }));
}
 
Example 18
@Incoming(PRE_ACKNOWLEDGMENT)
@Acknowledgment(Acknowledgment.Strategy.PRE_PROCESSING)
@Outgoing("sink-" + PRE_ACKNOWLEDGMENT)
public Processor<String, String> processorWithPreAck() {
    return ReactiveStreams.<String> builder()
            .flatMap(m -> ReactiveStreams.of(m, m))
            .peek(m -> processed(PRE_ACKNOWLEDGMENT, m))
            .buildRs();
}
 
Example 19
@Incoming("hello")
@Outgoing("out")
public Flowable<String> consume(Flowable<String> values) {
    Scheduler scheduler = Schedulers.from(executor);
    return values
            .observeOn(scheduler)
            .delay(1, TimeUnit.MILLISECONDS, scheduler)
            .doOnError(err -> {
                downstreamFailure = err;
            });
}
 
Example 20
@Incoming("in")
@Outgoing("out")
@Acknowledgment(Acknowledgment.Strategy.PRE_PROCESSING)
public String process(String input) {
    // The message wrapping the payload is already acknowledged
    // The default would have waited the produced message to be
    // acknowledged
    return input.toUpperCase();
}
 
Example 21
@Outgoing(NO_ACKNOWLEDGMENT_BUILDER)
public Publisher<Message<String>> sourceToNoAckWithBuilder() {
    return Multi.createFrom().items("a", "b", "c", "d", "e")
            .map(payload -> Message.of(payload, () -> {
                nap();
                acknowledged(NO_ACKNOWLEDGMENT_BUILDER, payload);
                return CompletableFuture.completedFuture(null);
            }));
}
 
Example 22
@Blocking
@Incoming("count")
@Outgoing("sink")
public String process(Message<Integer> value) {
    try {
        Thread.sleep(200);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    threads.add(Thread.currentThread().getName());
    return Integer.toString(value.getPayload() + 1);
}
 
Example 23
@Incoming("count")
@Outgoing("sink")
public PublisherBuilder<String> process(PublisherBuilder<Integer> source) {
    return source
            .map(i -> i + 1)
            .flatMapRsPublisher(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i));
}
 
Example 24
@Incoming("source")
@Outgoing("output")
public Message<Integer> processMessage(Message<Integer> input) {
    return KafkaRecord.from(input)
            .withNack(cause -> {
                assertThat(cause).isNotNull();
                m2Nack.incrementAndGet();
                input.nack(cause);
                return CompletableFuture.completedFuture(null);
            });
}
 
Example 25
@Outgoing(PRE_ACKNOWLEDGMENT_UNI)
public Publisher<Message<String>> sourceToPreAckUni() {
    return Multi.createFrom().items("a", "b", "c", "d", "e")
            .map(payload -> Message.of(payload, () -> {
                nap();
                acknowledged(PRE_ACKNOWLEDGMENT_UNI, payload);
                return CompletableFuture.completedFuture(null);
            }));
}
 
Example 26
@Outgoing(PRE_ACKNOWLEDGMENT_BUILDER)
public Publisher<Message<String>> sourceToPreAckBuilder() {
    return Multi.createFrom().items("a", "b", "c", "d", "e")
            .map(payload -> Message.of(payload, () -> {
                nap();
                acknowledged(PRE_ACKNOWLEDGMENT_BUILDER, payload);
                return CompletableFuture.completedFuture(null);
            }));
}
 
Example 27
@Outgoing(MANUAL_ACKNOWLEDGMENT_BUILDER)
public PublisherBuilder<Message<String>> sourceToManualAckWithBuilder() {
    return ReactiveStreams.of("a", "b", "c", "d", "e")
            .map(payload -> Message.of(payload, () -> CompletableFuture.runAsync(() -> {
                nap();
                acknowledged(MANUAL_ACKNOWLEDGMENT_BUILDER, payload);
            })));
}
 
Example 28
@Outgoing(POST_ACKNOWLEDGMENT)
public Publisher<Message<String>> sourceToPostAck() {
    return Multi.createFrom().items("a", "b", "c", "d", "e")
            .map(payload -> Message.of(payload, () -> {
                nap();
                acknowledged(POST_ACKNOWLEDGMENT, payload);
                return CompletableFuture.completedFuture(null);
            }));
}
 
Example 29
@Outgoing("prices")
public Multi<Message<String>> generate() {
    // Build an infinite stream of random prices
    return Multi.createFrom().ticks().every(Duration.ofMillis(100))
            .on().overflow().drop()
            .map(x -> random.nextDouble())
            .map(p -> Double.toString(p))
            .map(Message::of);
}
 
Example 30
@Incoming(NO_ACKNOWLEDGMENT)
@Acknowledgment(Acknowledgment.Strategy.NONE)
@Outgoing("sink-" + NO_ACKNOWLEDGMENT)
public Publisher<Message<String>> processorWithNoAck(Publisher<Message<String>> input) {
    return ReactiveStreams.fromPublisher(input)
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())))
            .peek(m -> processed(NO_ACKNOWLEDGMENT, m.getPayload()))
            .buildRs();
}