Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move initial local code #1

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.chappie</groupId>
<artifactId>quarkus-chappie</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.quarkiverse.chappie.deployment;

import io.quarkiverse.chappie.runtime.LogMessageReceiver;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;

Expand All @@ -11,4 +15,9 @@ class ChappieProcessor {
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep(onlyIf = IsDevelopment.class)
void registerBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(LogMessageReceiver.class));
}
}
5 changes: 5 additions & 0 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<!-- TODO: Consider moving the mutiny logger to core ? -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.quarkiverse.chappie.runtime;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;

import org.jboss.logging.Logger;

import io.quarkus.devui.runtime.logstream.LogStreamBroadcaster;
import io.quarkus.runtime.StartupEvent;
import io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

/**
* Receive Log messages, and check if there is an exception
*/
@ApplicationScoped
public class LogMessageReceiver {
private static final Logger LOGGER = Logger.getLogger(LogMessageReceiver.class);

@Inject
LogStreamBroadcaster logStreamBroadcaster;

void onStart(@Observes StartupEvent ev) {
LOGGER.info("Chappie is listening for exceptions....");

BroadcastProcessor<JsonObject> logStream = logStreamBroadcaster.getLogStream();

logStream.subscribe().with((JsonObject item) -> {
if (item.containsKey(STACKTRACE)) {
JsonArray stacktrace = item.getJsonArray(STACKTRACE);
if (!stacktrace.isEmpty()) {
System.out.println(">>>>>>> CHAPPIE FOUND AN EXCEPTION !");
String fileName = getFileName(item);
int lineNumber = item.getInteger(SOURCE_LINE_NUMBER);

System.out.println("\t\t " + fileName + " | line " + lineNumber);
}
}
});

}

private String getFileName(JsonObject item) {
String classNameFull = item.getString(SOURCE_CLASS_NAME_FULL);
String fileName = item.getString(SOURCE_FILE_NAME);
int lastDotIndex = classNameFull.lastIndexOf('.');

if (lastDotIndex == -1) {
return fileName; // No package
}
return classNameFull.substring(0, lastDotIndex + 1) + fileName;
}

private static final String STACKTRACE = "stacktrace";
private static final String SOURCE_CLASS_NAME_FULL = "sourceClassNameFull";
private static final String SOURCE_FILE_NAME = "sourceFileName";
private static final String SOURCE_LINE_NUMBER = "sourceLineNumber";

}