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

The following examples show how to use org.eclipse.microprofile.reactive.messaging.Outgoing. 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
Source File: BeanReturningPayloads.java    From quarkus with 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 #2
Source File: HeaderPropagationTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #3
Source File: StreamSkipTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("in")
@Outgoing("out-1")
public Multi<String> processPayload(String s) {
    if (s.equalsIgnoreCase("skip")) {
        return Multi.createFrom().empty();
    }
    return Multi.createFrom().item(s.toUpperCase());
}
 
Example #4
Source File: BeanWithProcessorsProducingMessageStreams.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(NO_ACKNOWLEDGMENT)
@Acknowledgment(Acknowledgment.Strategy.NONE)
@Outgoing("sink-" + NO_ACKNOWLEDGMENT)
public Publisher<Message<String>> processorWithNoAck(Message<String> input) {
    return ReactiveStreams.of(input)
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())))
            .peek(m -> processed(NO_ACKNOWLEDGMENT, m))
            .buildRs();
}
 
Example #5
Source File: BeanWithStreamTransformers.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(MANUAL_ACKNOWLEDGMENT)
@Acknowledgment(Acknowledgment.Strategy.MANUAL)
@Outgoing("sink-" + MANUAL_ACKNOWLEDGMENT)
public Publisher<Message<String>> processorWithAck(Publisher<Message<String>> input) {
    return ReactiveStreams.fromPublisher(input)
            .flatMapCompletionStage(m -> m.ack().thenApply(x -> m))
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())))
            .peek(m -> processed(MANUAL_ACKNOWLEDGMENT, m.getPayload()))
            .buildRs();
}
 
Example #6
Source File: AmqpPriceProducer.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Outgoing("prices")
public Multi<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 -> random.nextDouble());
}
 
Example #7
Source File: BeanWithProcessorsProducingMessageStreams.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: BeanConsumingItemAsFluxAndPublishingItemAsPublisher.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("count")
@Outgoing("sink")
public Publisher<String> process(Flux<Integer> source) {
    return source
            .map(i -> i + 1)
            .flatMap(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i));
}
 
Example #9
Source File: ValuesGenerator.java    From quarkus-quickstarts with 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 #10
Source File: HttpSinkTest.java    From smallrye-reactive-messaging with 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 #11
Source File: BeanWithStreamTransformers.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #12
Source File: BeanConsumingMsgAsFluxAndPublishingMsgAsFlux.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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
Source File: MissingBackPressureTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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
Source File: BeanWithStreamTransformers.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 File: PriceMessageProducer.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: StreamSkipTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("in")
@Outgoing("out-3")
public Multi<String> processPayloadStream(Multi<String> stream) {
    return stream
            .transform().byFilteringItemsWith(s -> !s.equalsIgnoreCase("skip"))
            .onItem().apply(String::toUpperCase);
}
 
Example #17
Source File: StreamExamples.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: BeanWithProcessorsManipulatingPayloads.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: BeanWithProcessorsProducingMessageStreams.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: BeanWithProcessorsProducingPayloadStreams.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: BeanWithProcessorsManipulatingMessages.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: KafkaNackPropagationTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: BeanConsumingItemAsPublisherBuilderAndPublishingItemAsPublisherBuilder.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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
Source File: BeanWithProcessorsManipulatingPayloads.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(NO_ACKNOWLEDGMENT)
@Acknowledgment(Acknowledgment.Strategy.NONE)
@Outgoing("sink-" + NO_ACKNOWLEDGMENT)
public String processorWithNoAck(String input) {
    processed(NO_ACKNOWLEDGMENT, input);
    return input + "1";
}
 
Example #25
Source File: BeanConsumingMessagesAndProducingItems.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #26
Source File: BeanWithStreamTransformers.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #27
Source File: BeanWithPayloadProcessors.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #28
Source File: PreAckExamples.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #29
Source File: BeanWithPayloadProcessors.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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 #30
Source File: LegacyDropOverflowStrategyTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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;
            });
}