-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa6dcd4
commit ff903a2
Showing
12 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
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,4 @@ | ||
LOG_DIR="/tmp/logs" | ||
KAFKA_ADVERTISED_LISTENERS="PLAINTEXT://localhost:9092" | ||
KAFKA_LISTENERS="PLAINTEXT://0.0.0.0:9092" | ||
KAFKA_ZOOKEEPER_CONNECT="zookeeper:2181" |
3 changes: 3 additions & 0 deletions
3
micro-services/microprofile-rabbitmq-demo/.vscode/settings.json
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,3 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "interactive" | ||
} |
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,3 @@ | ||
== MicroProfile reactive Messaging with RabbitMQ | ||
|
||
Read more: |
17 changes: 17 additions & 0 deletions
17
micro-services/microprofile-rabbitmq-demo/docker-compose.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,17 @@ | ||
version: '3.8' | ||
|
||
services: | ||
rabbit: | ||
image: rabbitmq:3.12-management-alpine | ||
labels: | ||
- quarkus-dev-service-amqp=amqp | ||
ports: | ||
# AMQP protocol port | ||
- '5672:5672' | ||
# HTTP management UI | ||
- '15672:15672' | ||
environment: | ||
- RABBITMQ_DEFAULT_USER=guest | ||
- RABBITMQ_DEFAULT_PASS=guest | ||
volumes: | ||
- './enabled_plugins:/etc/rabbitmq/enabled_plugins:ro' |
8 changes: 8 additions & 0 deletions
8
micro-services/microprofile-rabbitmq-demo/enable-reactive-messaging.cli
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 @@ | ||
batch | ||
/extension=org.wildfly.extension.microprofile.reactive-messaging-smallrye:add | ||
/extension=org.wildfly.extension.microprofile.reactive-streams-operators-smallrye:add | ||
/subsystem=microprofile-reactive-streams-operators-smallrye:add | ||
/subsystem=microprofile-reactive-messaging-smallrye:add | ||
run-batch | ||
|
||
reload |
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 @@ | ||
[rabbitmq_management,rabbitmq_amqp1_0]. |
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,88 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
|
||
<project | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>microprofile-reactive-messaging-kafka</artifactId> | ||
<groupId>com.mastertherboss</groupId> | ||
<version>1.0.0.Final</version> | ||
<packaging>war</packaging> | ||
<name>Quickstart: microprofile-reactive-messaging-kafka</name> | ||
<properties> | ||
<!-- the version for the Server --> | ||
<version.server>31.0.0.Final</version.server> | ||
<!-- The versions for BOMs, Packs and Plugins --> | ||
<version.bom.microprofile>${version.server}</version.bom.microprofile> | ||
</properties> | ||
<dependencyManagement> | ||
<dependencies> | ||
<!-- importing the microprofile BOM adds MicroProfile specs --> | ||
<dependency> | ||
<groupId>org.wildfly.bom</groupId> | ||
<artifactId>wildfly-microprofile</artifactId> | ||
<version>${version.bom.microprofile}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>jakarta.platform</groupId> | ||
<artifactId>jakarta.jakartaee-api</artifactId> | ||
<version>10.0.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- Import the Reactive Messaging API, we use provided scope as the API is included in WildFly --> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.reactive.messaging</groupId> | ||
<artifactId>microprofile-reactive-messaging-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!----> | ||
<dependency> | ||
<groupId>io.smallrye.reactive</groupId> | ||
<artifactId>smallrye-reactive-messaging-amqp</artifactId> | ||
<version>4.17.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- Import the Reactive Streams Operators API, we use provided scope as the API is included in WildFly --> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.reactive-streams-operators</groupId> | ||
<artifactId>microprofile-reactive-streams-operators-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.reactivestreams</groupId> | ||
<artifactId>reactive-streams</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>3.4.0</version> | ||
<configuration> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.wildfly.plugins</groupId> | ||
<artifactId>wildfly-maven-plugin</artifactId> | ||
<version>4.0.0.Final</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>17</source> | ||
<target>17</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
62 changes: 62 additions & 0 deletions
62
...le-rabbitmq-demo/src/main/java/com/mastertheboss/mp/reactive/messaging/InVMMessaging.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,62 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2021, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mastertheboss.mp.reactive.messaging; | ||
|
||
import com.mastertheboss.mp.reactive.messaging.model.WeatherData; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import org.eclipse.microprofile.reactive.messaging.Outgoing; | ||
import org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
|
||
|
||
@ApplicationScoped | ||
public class InVMMessaging { | ||
|
||
@Inject | ||
TemperatureGenerator producer; | ||
|
||
|
||
|
||
@Outgoing("source") | ||
public CompletionStage<WeatherData> sendInVm() { | ||
return producer.getWeatherData(); | ||
|
||
} | ||
|
||
|
||
@Incoming("source") | ||
@Outgoing("filter") | ||
public WeatherData logAllMessages(WeatherData message) { | ||
System.out.println("Got Weather : " + message); | ||
return message; | ||
} | ||
|
||
@Incoming("filter") | ||
@Outgoing("sender") | ||
public PublisherBuilder<WeatherData> filterMessages(PublisherBuilder<WeatherData> messages) { | ||
return messages | ||
.filter(data -> !data.city().equals("Sydney")); | ||
} | ||
|
||
|
||
|
||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...-rabbitmq-demo/src/main/java/com/mastertheboss/mp/reactive/messaging/RemoteMessaging.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,36 @@ | ||
|
||
package com.mastertheboss.mp.reactive.messaging; | ||
|
||
import com.mastertheboss.mp.reactive.messaging.model.WeatherData; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import org.eclipse.microprofile.reactive.messaging.Message; | ||
import org.eclipse.microprofile.reactive.messaging.Outgoing; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
|
||
|
||
@ApplicationScoped | ||
public class RemoteMessaging { | ||
|
||
|
||
|
||
|
||
@Incoming("sender") | ||
@Outgoing("to-amq") | ||
public WeatherData producWeatherData(WeatherData message) { | ||
System.out.println("Sent WeatherData to Remote System : " + message); | ||
return message; | ||
} | ||
|
||
@Incoming("from-amq") | ||
public CompletionStage<Void> consumeWeatherData(Message<WeatherData> message) { | ||
System.out.println("Consumed WeatherData from Remote System: " + message.getPayload()); | ||
return message.ack(); | ||
|
||
} | ||
|
||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...itmq-demo/src/main/java/com/mastertheboss/mp/reactive/messaging/TemperatureGenerator.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 com.mastertheboss.mp.reactive.messaging; | ||
|
||
import com.mastertheboss.mp.reactive.messaging.model.WeatherData; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.concurrent.*; | ||
|
||
|
||
@ApplicationScoped | ||
public class TemperatureGenerator { | ||
|
||
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); | ||
private final List<String> cities = List.of("Paris", "New York", "London", "Tokyo", "Sydney"); | ||
private final Random random = new Random(); | ||
|
||
public CompletionStage<WeatherData> getWeatherData() { | ||
CompletableFuture<WeatherData> future = new CompletableFuture<>(); | ||
ScheduledFuture<?> scheduledFuture = executor.schedule(() -> { | ||
int temperature = random.nextInt(10) + 10; | ||
WeatherData weatherData = new WeatherData(getRandomCity(), temperature); | ||
future.complete(weatherData); | ||
}, 2, TimeUnit.SECONDS); // Schedule the task to run after 2 seconds | ||
|
||
return future; | ||
} | ||
|
||
private String getRandomCity() { | ||
return cities.get(random.nextInt(cities.size())); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...abbitmq-demo/src/main/java/com/mastertheboss/mp/reactive/messaging/model/WeatherData.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,8 @@ | ||
package com.mastertheboss.mp.reactive.messaging.model; | ||
|
||
|
||
|
||
public record WeatherData(String city, Integer temperature) { | ||
|
||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...ces/microprofile-rabbitmq-demo/src/main/resources/META-INF/microprofile-config.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,16 @@ | ||
amqp-host=localhost | ||
amqp-port=5672 | ||
amqp-username=guest | ||
amqp-password=guest | ||
|
||
mp.messaging.outgoing.to-amq.connector=smallrye-amqp | ||
mp.messaging.outgoing.to-amq.address=queueDemo | ||
mp.messaging.outgoing.to-amq.durable=false | ||
|
||
mp.messaging.incoming.from-amq.connector=smallrye-amqp | ||
mp.messaging.incoming.from-amq.address=queueDemo | ||
mp.messaging.incoming.from-amq.durable=false | ||
|
||
mp.messaging.outgoing.to-amq.use-anonymous-sender=false | ||
|
||
|