Skip to content

Commit

Permalink
Reactive Messaging codestart
Browse files Browse the repository at this point in the history
 * fix #20872
 * created `MyReactiveMessagingApplication` to demonstrates `@Emitter`, `@Incoming` and `@Outgoing` annotations.
  • Loading branch information
vgallet committed Oct 28, 2021
1 parent fa595c7 commit aa29e9c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#include readme-header /}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: reactive-messaging-codestart
ref: reactive-messaging-codestart
tags: extension-codestart
type: code
metadata:
title: Reactive Messaging codestart
description: Use SmallRye Reactive Messaging to interact with Apache Kafka
related-guide-section: https://quarkus.io/guides/kafka
language:
base:
dependencies:
- io.quarkus:quarkus-smallrye-reactive-messaging
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.acme;

import io.quarkus.runtime.StartupEvent;
import org.eclipse.microprofile.reactive.messaging.*;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import java.util.stream.Stream;

@ApplicationScoped
public class MyReactiveMessagingApplication {

@Inject
@Channel("source")
Emitter<String> emitter;

/** Sends message to the source channel, can be used from a JAX-RS resource or any bean of your application **/
void onStart(@Observes StartupEvent ev) {
Stream.of("Hello", "with", "SmallRye", "reactive", "message").forEach(string -> emitter.send(string));
}

/** Consume the message from the source channel, uppercase it and send it to the uppercase channel **/
@Incoming("source")
@Outgoing("uppercase")
public Message<String> toUpperCase(Message<String> message) {
return message.withPayload(message.getPayload().toUpperCase());
}

/** Consume the uppercase channel and print the message **/
@Incoming("uppercase")
public void sink(String word) {
System.out.println(">> " + word);
}
}

0 comments on commit aa29e9c

Please sign in to comment.