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

The following examples show how to use org.eclipse.microprofile.reactive.messaging.Incoming. 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: PublisherBean.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("publisher-for-processor-publisher-payload")
@Outgoing("processor-publisher-payload")
public Publisher<String> processorOfPayloads(int value) {
    return ReactiveStreams.of(value)
        .map(i -> i + 1)
        .flatMap(i -> ReactiveStreams.of(i, i))
        .map(i -> Integer.toString(i))
        .buildRs();
}
 
Example #2
Source File: StreamSkipTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("in")
@Outgoing("out-2")
public Multi<Message<String>> processMessage(Message<String> m) {
    String s = m.getPayload();
    if (s.equalsIgnoreCase("skip")) {
        return Multi.createFrom().empty();
    }
    return Multi.createFrom().item(m.withPayload(s.toUpperCase()));
}
 
Example #3
Source File: TransformerSignatureTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Incoming("A")
@Outgoing("AA")
public Publisher<Message<String>> process(Publisher<Message<Integer>> publisher) {
    return ReactiveStreams.fromPublisher(publisher)
            .flatMapCompletionStage(m -> CompletableFuture
                    .supplyAsync(() -> Message.of(Integer.toString(m.getPayload())), executor))
            .buildRs();
}
 
Example #4
Source File: BeanConsumingItemAsMultiAndPublishingItemAsPublisher.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("count")
@Outgoing("sink")
public Publisher<String> process(Multi<Integer> source) {
    return source
            .map(i -> i + 1)
            .flatMap(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i));
}
 
Example #5
Source File: InvalidBlockingProcessorShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Blocking
@Incoming("count")
@Outgoing("sink")
public CompletionStage<Message<String>> process(Message<Integer> value) {
    return CompletableFuture.supplyAsync(() -> Integer.toString(value.getPayload() + 1))
            .thenApply(Message::of);
}
 
Example #6
Source File: FailOverflowStrategyTest.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;
            });
}
 
Example #7
Source File: BeanWithProcessorsProducingMessageStreams.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(MANUAL_ACKNOWLEDGMENT_BUILDER)
@Acknowledgment(Acknowledgment.Strategy.MANUAL)
@Outgoing("sink-" + MANUAL_ACKNOWLEDGMENT_BUILDER)
public PublisherBuilder<Message<String>> processorWithAckWithBuilder(Message<String> message) {
    return ReactiveStreams.of(message)
            .flatMapCompletionStage(m -> m.ack().thenApply(x -> m))
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())))
            .peek(m -> processed(MANUAL_ACKNOWLEDGMENT_BUILDER, m));
}
 
Example #8
Source File: MyBean.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("my-dummy-stream")
@Outgoing("toUpperCase")
public Multi<Message<String>> toUppercase(Multi<Message<String>> input) {
    return input
            .map(Message::getPayload)
            .map(String::toUpperCase)
            .map(Message::of);
}
 
Example #9
Source File: StreamAckExamples.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("in")
@Outgoing("out")
public Publisher<String> transformPayload(Multi<String> stream) {
    return stream
        // The incoming messages are already acknowledged
        .map(String::toUpperCase);
}
 
Example #10
Source File: StreamSkip.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 #11
Source File: MultiLevelIncomingsTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("a")
@Incoming("b")
@Incoming("c")
@Outgoing("out")
public Message<String> process(Message<String> s) {
    return Message.of(s.getPayload().toUpperCase());
}
 
Example #12
Source File: InvalidBlockingSubscriberShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Blocking
@Incoming("count")
public Uni<Void> consume(Message<String> message) {
    return Uni.createFrom().item(() -> {
        list.add(message.getPayload());
        return null;
    });
}
 
Example #13
Source File: PriceConverter.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Incoming("prices")
@Outgoing("my-data-stream")
@Broadcast
public double process(byte[] priceRaw) {
    int priceInUsd = Integer.parseInt(new String(priceRaw));
    System.out.println("Receiving price: " + priceInUsd);
    return priceInUsd * CONVERSION_RATE;
}
 
Example #14
Source File: InvalidBlockingProcessorShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Blocking
@Incoming("count")
@Outgoing("sink")
public ProcessorBuilder<Message<Integer>, Message<String>> process() {
    return ReactiveStreams.<Message<Integer>> builder()
            .map(Message::getPayload)
            .map(i -> i + 1)
            .flatMapRsPublisher(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i))
            .map(Message::of);
}
 
Example #15
Source File: CollectorOnly.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("sink")
public Subscriber<Message<String>> sink() {
    CompletionSubscriber<Message<String>, List<Message<String>>> subscriber = ReactiveStreams.<Message<String>> builder()
            .toList().build();
    subscriber.getCompletion().thenAccept(result::addAll);
    return subscriber;
}
 
Example #16
Source File: AmqpPriceMessageConsumer.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("prices")
public CompletionStage<Void> consume(Message<Double> price) {
    // process your price.

    // Acknowledge the incoming message, marking the AMQP message as `accepted`.
    return price.ack();
}
 
Example #17
Source File: SubscriberBeanWithMethodsReturningSubscribers.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(NO_ACKNOWLEDGMENT_PAYLOAD)
@Acknowledgment(Acknowledgment.Strategy.NONE)
public Subscriber<String> subWithNoAckWithPayload() {
    return ReactiveStreams.<String> builder()
            .forEach(m -> {
                processed(NO_ACKNOWLEDGMENT_PAYLOAD, m);
                microNap();
            })
            .build();
}
 
Example #18
Source File: ProcessorBean.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("publisher-for-processor-builder-message")
@Outgoing("processor-builder-message")
public ProcessorBuilder<Message<Integer>, Message<String>> processorBuilderOfMessages() {
  increment("publisher-for-processor-builder-message");
  return ReactiveStreams.<Message<Integer>>builder()
    .map(Message::getPayload)
    .map(i -> i + 1)
    .flatMap(i -> ReactiveStreams.of(i, i))
    .map(i -> Integer.toString(i))
    .map(Message::of);
}
 
Example #19
Source File: BeanWithProcessorsManipulatingPayloads.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(POST_ACKNOWLEDGMENT)
@Acknowledgment(Acknowledgment.Strategy.POST_PROCESSING)
@Outgoing("sink-" + POST_ACKNOWLEDGMENT)
public String processorWithPostAck(String input) {
    processed(POST_ACKNOWLEDGMENT, input);
    return input + "1";
}
 
Example #20
Source File: BeanWithProcessorsManipulatingMessages.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")
public Message<String> processorWithPreAck(Message<String> input) {
    processed(PRE_ACKNOWLEDGMENT, input);
    return Message.of(input.getPayload() + "1");
}
 
Example #21
Source File: KafkaPriceMessageConsumer.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes" })
@Incoming("prices")
public CompletionStage<Void> consume(Message<Double> price) {
    // process your price.
    list.add(price.getPayload());
    Optional<IncomingKafkaRecordMetadata> metadata = price.getMetadata(IncomingKafkaRecordMetadata.class);
    metadata.orElseThrow(() -> new IllegalArgumentException("Metadata are missing"));
    // Acknowledge the incoming message (commit the offset)
    return price.ack();
}
 
Example #22
Source File: InvalidBlockingProcessorShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Blocking
@Incoming("count")
@Outgoing("sink")
public PublisherBuilder<Message<String>> process(Message<Integer> message) {
    return ReactiveStreams.of(message)
            .map(Message::getPayload)
            .map(i -> i + 1)
            .flatMapRsPublisher(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i))
            .map(Message::of);
}
 
Example #23
Source File: BeanWithProcessorsManipulatingMessages.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(DEFAULT_ACKNOWLEDGMENT_UNI)
@Outgoing("sink")
public Uni<Message<String>> processorWithDefaultAckUni(Message<String> input) {
    return Uni.createFrom().item(() -> {
        processed(DEFAULT_ACKNOWLEDGMENT_UNI, input);
        return input.withPayload(input.getPayload() + "1");
    });
}
 
Example #24
Source File: TransformerSignatureTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Incoming("C")
@Outgoing("CC")
public PublisherBuilder<Message<String>> process(PublisherBuilder<Message<Integer>> publisher) {
    return publisher
            .flatMapCompletionStage(m -> CompletableFuture
                    .supplyAsync(() -> Message.of(Integer.toString(m.getPayload())), executor));
}
 
Example #25
Source File: BeanConsumingMsgAsFluxAndPublishingMsgAsPublisher.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("count")
@Outgoing("sink")
public Publisher<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 #26
Source File: SingleSkip.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("in")
@Outgoing("out")
public Message<String> processMessage(Message<String> m) {
    String s = m.getPayload();
    if (s.equalsIgnoreCase("skip")) {
        return null;
    }
    return m.withPayload(s.toUpperCase());
}
 
Example #27
Source File: MetricsTestBean.java    From microprofile-reactive-messaging with Apache License 2.0 4 votes vote down vote up
@Incoming(CHANNEL_APP_B)
public void receive(String input) {
    inAppMessagesReceived.incrementAndGet();
}
 
Example #28
Source File: EmitterWithBroadcastExample.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Incoming("sink")
public void consume(String s) {
    list.add(s);
}
 
Example #29
Source File: PublisherBean.java    From microprofile-reactive-messaging with Apache License 2.0 4 votes vote down vote up
@Incoming("processor-publisher-builder-payload")
public void getMessgesFromProcessorBuilderOfPayloads(String value) {
    add("processor-builder-payload", value);
}
 
Example #30
Source File: MergeExamples.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
@Incoming("in2")
@Outgoing("out")
public int multiply(int i) {
    return i * 2;
}