-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix #20872 * created `MyReactiveMessagingApplication` to demonstrates `@Emitter`, `@Incoming` and `@Outgoing` annotations. * created dynamic application.yml based on selected extension * added codestart integration test
- Loading branch information
Showing
17 changed files
with
389 additions
and
3 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...arkus/extension-codestarts/reactive-messaging-codestart/base/README.tpl.qute.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{#include readme-header /} | ||
|
||
{#each input.selected-extensions-ga} | ||
{#switch it} | ||
{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-kafka'} | ||
[Related Apache Kafka guide section...](https://quarkus.io/guides/kafka-reactive-getting-started) | ||
|
||
{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-amqp'} | ||
[Related Apache AMQP 1.0 guide section...](https://quarkus.io/guides/amqp) | ||
|
||
{/switch} | ||
{/each} |
66 changes: 66 additions & 0 deletions
66
...-codestarts/reactive-messaging-codestart/base/src/main/resources/application.tpl.qute.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{#each input.selected-extensions-ga} | ||
{#switch it} | ||
{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-kafka'} | ||
mp: | ||
messaging: | ||
outgoing: | ||
source-out: | ||
connector: smallrye-kafka | ||
topic: word | ||
uppercase-out: | ||
connector: smallrye-kafka | ||
topic: uppercase-word | ||
incoming: | ||
source-in: | ||
connector: smallrye-kafka | ||
topic: word | ||
uppercase-in: | ||
connector: smallrye-kafka | ||
topic: uppercase-word | ||
|
||
{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-mqtt'} | ||
mp: | ||
messaging: | ||
outgoing: | ||
source-out: | ||
connector: smallrye-mqtt | ||
host: localhost | ||
port: '1883' | ||
topic: word | ||
uppercase-out: | ||
connector: smallrye-mqtt | ||
host: localhost | ||
port: '1883' | ||
topic: uppercase-word | ||
incoming: | ||
source-in: | ||
connector: smallrye-mqtt | ||
host: localhost | ||
port: '1883' | ||
topic: word | ||
uppercase-in: | ||
connector: smallrye-mqtt | ||
host: localhost | ||
port: '1883' | ||
topic: uppercase-word | ||
|
||
{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-amqp'} | ||
mp: | ||
messaging: | ||
outgoing: | ||
source-out: | ||
address: word | ||
connector: smallrye-amqp | ||
uppercase-out: | ||
connector: smallrye-amqp | ||
address: uppercase-word | ||
incoming: | ||
source-in: | ||
connector: smallrye-amqp | ||
address: word | ||
uppercase-in: | ||
address: uppercase-word | ||
connector: smallrye-amqp | ||
|
||
{/switch} | ||
{/each} |
12 changes: 12 additions & 0 deletions
12
...ources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/codestart.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: reactive-messaging-codestart | ||
ref: reactive-messaging | ||
tags: extension-codestart | ||
type: code | ||
metadata: | ||
title: Reactive Messaging codestart | ||
description: Use SmallRye Reactive Messaging | ||
language: | ||
base: | ||
dependencies: | ||
test-dependencies: | ||
- io.smallrye.reactive:smallrye-reactive-messaging-in-memory |
35 changes: 35 additions & 0 deletions
35
...ctive-messaging-codestart/java/src/main/java/org/acme/MyReactiveMessagingApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-out") | ||
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-in") | ||
@Outgoing("uppercase-out") | ||
public Message<String> toUpperCase(Message<String> message) { | ||
return message.withPayload(message.getPayload().toUpperCase()); | ||
} | ||
|
||
/** Consume the uppercase channel and print the message **/ | ||
@Incoming("uppercase-in") | ||
public void sink(String word) { | ||
System.out.println(">> " + word); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...e-messaging-codestart/java/src/test/java/org/acme/MyReactiveMessagingApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.acme; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.smallrye.reactive.messaging.connectors.InMemoryConnector; | ||
import io.smallrye.reactive.messaging.connectors.InMemorySink; | ||
import io.smallrye.reactive.messaging.connectors.InMemorySource; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.enterprise.inject.Any; | ||
import javax.inject.Inject; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(MyReactiveMessagingApplicationTest.InMemoryChannelTestResource.class) | ||
class MyReactiveMessagingApplicationTest { | ||
|
||
@Inject | ||
@Any | ||
InMemoryConnector connector; | ||
|
||
@Test | ||
void test() { | ||
InMemorySource<String> source = connector.source("source-in"); | ||
InMemorySink<String> uppercase = connector.sink("uppercase-out"); | ||
|
||
source.send("Hello"); | ||
source.send("In-memory"); | ||
source.send("Connectors"); | ||
|
||
assertEquals(3, uppercase.received().size()); | ||
assertTrue(uppercase.received().stream().anyMatch(message -> message.getPayload().equals("HELLO"))); | ||
assertTrue(uppercase.received().stream().anyMatch(message -> message.getPayload().equals("IN-MEMORY"))); | ||
assertTrue(uppercase.received().stream().anyMatch(message -> message.getPayload().equals("CONNECTORS"))); | ||
|
||
} | ||
|
||
public static class InMemoryChannelTestResource implements QuarkusTestResourceLifecycleManager { | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
Map<String, String> env = new HashMap<>(); | ||
env.putAll(InMemoryConnector.switchIncomingChannelsToInMemory("source-in")); | ||
env.putAll(InMemoryConnector.switchOutgoingChannelsToInMemory("uppercase-out")); | ||
return env; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
InMemoryConnector.clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ls/src/test/java/io/quarkus/devtools/codestarts/quarkus/ReactiveMessagingCodestartIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.devtools.codestarts.quarkus; | ||
|
||
import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; | ||
import io.quarkus.maven.ArtifactKey; | ||
|
||
public class ReactiveMessagingCodestartIT { | ||
|
||
@RegisterExtension | ||
public static QuarkusCodestartTest kafkaCodestartTest = QuarkusCodestartTest.builder() | ||
.extension(ArtifactKey.fromString("io.quarkus:quarkus-smallrye-reactive-messaging-kafka")) | ||
.languages(JAVA) | ||
.build(); | ||
|
||
@RegisterExtension | ||
public static QuarkusCodestartTest amqpCodestartTest = QuarkusCodestartTest.builder() | ||
.extension(ArtifactKey.fromString("io.quarkus:quarkus-smallrye-reactive-messaging-amqp")) | ||
.languages(JAVA) | ||
.build(); | ||
|
||
@RegisterExtension | ||
public static QuarkusCodestartTest mqttCodestartTest = QuarkusCodestartTest.builder() | ||
.extension(ArtifactKey.fromString("io.quarkus:quarkus-smallrye-reactive-messaging-mqtt")) | ||
.languages(JAVA) | ||
.build(); | ||
|
||
@Test | ||
void testKafkaContent() throws Throwable { | ||
kafkaCodestartTest.checkGeneratedSource("org.acme.MyReactiveMessagingApplication"); | ||
kafkaCodestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/application.properties"); | ||
kafkaCodestartTest.checkGeneratedTestSource("org.acme.MyReactiveMessagingApplicationTest"); | ||
} | ||
|
||
@Test | ||
void testMQTTContent() throws Throwable { | ||
mqttCodestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/application.properties"); | ||
} | ||
|
||
@Test | ||
void testAMQPContent() throws Throwable { | ||
amqpCodestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/application.properties"); | ||
} | ||
|
||
@Test | ||
void buildAll() throws Throwable { | ||
kafkaCodestartTest.buildAllProjects(); | ||
mqttCodestartTest.buildAllProjects(); | ||
amqpCodestartTest.buildAllProjects(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...__/ReactiveMessagingCodestartIT/testAMQPContent/src_main_resources_application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mp.messaging.outgoing.uppercase-out.connector=smallrye-amqp | ||
mp.messaging.outgoing.uppercase-out.address=uppercase-word | ||
mp.messaging.incoming.source-in.connector=smallrye-amqp | ||
mp.messaging.incoming.uppercase-in.address=uppercase-word | ||
mp.messaging.outgoing.source-out.address=word | ||
mp.messaging.incoming.source-in.address=word | ||
mp.messaging.outgoing.source-out.connector=smallrye-amqp | ||
mp.messaging.incoming.uppercase-in.connector=smallrye-amqp |
35 changes: 35 additions & 0 deletions
35
...startIT/testKafkaContent/src_main_java_ilove_quark_us_MyReactiveMessagingApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ilove.quark.us; | ||
|
||
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-out") | ||
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-in") | ||
@Outgoing("uppercase-out") | ||
public Message<String> toUpperCase(Message<String> message) { | ||
return message.withPayload(message.getPayload().toUpperCase()); | ||
} | ||
|
||
/** Consume the uppercase channel and print the message **/ | ||
@Incoming("uppercase-in") | ||
public void sink(String word) { | ||
System.out.println(">> " + word); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
..._/ReactiveMessagingCodestartIT/testKafkaContent/src_main_resources_application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mp.messaging.outgoing.uppercase-out.connector=smallrye-kafka | ||
mp.messaging.incoming.source-in.connector=smallrye-kafka | ||
mp.messaging.outgoing.source-out.topic=word | ||
mp.messaging.incoming.source-in.topic=word | ||
mp.messaging.incoming.uppercase-in.topic=uppercase-word | ||
mp.messaging.outgoing.source-out.connector=smallrye-kafka | ||
mp.messaging.outgoing.uppercase-out.topic=uppercase-word | ||
mp.messaging.incoming.uppercase-in.connector=smallrye-kafka |
Oops, something went wrong.