-
Notifications
You must be signed in to change notification settings - Fork 15
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
Events to micronaut version 4.3.4 #81
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,73 +1,94 @@ | ||
plugins { | ||
id("com.github.johnrengelman.shadow") version "7.1.2" | ||
id("io.micronaut.application") version "3.6.2" | ||
} | ||
|
||
group = "micronaut.mushop" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
micronaut { | ||
runtime("netty") | ||
testRuntime("junit5") | ||
processing { | ||
incremental(true) | ||
annotations("events.*") | ||
} | ||
} | ||
|
||
dependencies { | ||
annotationProcessor("io.micronaut.openapi:micronaut-openapi") | ||
|
||
implementation("io.micronaut:micronaut-http-client") | ||
implementation("io.micronaut:micronaut-runtime") | ||
implementation("io.micronaut:micronaut-validation") | ||
|
||
// Metrics | ||
implementation("io.micronaut:micronaut-management") | ||
implementation("io.micronaut.micrometer:micronaut-micrometer-core") | ||
implementation("io.micronaut.micrometer:micronaut-micrometer-registry-prometheus") | ||
|
||
// Tracing | ||
implementation("io.micronaut.tracing:micronaut-tracing-core") | ||
implementation("io.micronaut.tracing:micronaut-tracing-zipkin") | ||
|
||
// Streaming | ||
implementation("io.micronaut.kafka:micronaut-kafka") | ||
|
||
implementation("io.swagger.core.v3:swagger-annotations") | ||
|
||
runtimeOnly("ch.qos.logback:logback-classic") | ||
|
||
testImplementation(project(":tck")) | ||
testImplementation("org.testcontainers:junit-jupiter") | ||
} | ||
|
||
application { | ||
mainClass.set("events.Application") | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
if (javaBaseImage == "graalvm") { | ||
dockerfile { | ||
baseImage = "phx.ocir.io/oraclelabs/micronaut-showcase/mushop/base/graalvm-ce:java11-21.1.0" | ||
} | ||
} | ||
|
||
dockerBuild { | ||
images = ["phx.ocir.io/oraclelabs/micronaut-showcase/mushop/$project.parent.name-$project.name-${javaBaseImage}:$project.version"] | ||
} | ||
|
||
dockerBuildNative { | ||
images = ["phx.ocir.io/oraclelabs/micronaut-showcase/mushop/${project.parent.name}-${project.name}-native:$project.version"] | ||
} | ||
|
||
dockerfileNative { | ||
instruction "RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.11/main' >> /etc/apk/repositories && apk update && apk add 'zlib<1.2.12'" | ||
} | ||
plugins { | ||
id("com.github.johnrengelman.shadow") version "8.1.1" | ||
id("io.micronaut.application") version "4.3.4" | ||
id("io.micronaut.aot") version "4.3.4" | ||
id("io.micronaut.test-resources") version "4.3.4" | ||
} | ||
|
||
group = "micronaut.mushop" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
micronaut { | ||
runtime("netty") | ||
testRuntime("junit5") | ||
processing { | ||
incremental(true) | ||
annotations("events.*") | ||
} | ||
aot { | ||
optimizeServiceLoading = false | ||
convertYamlToJava = false | ||
precomputeOperations = true | ||
cacheEnvironment = true | ||
optimizeClassLoading = true | ||
deduceEnvironment = true | ||
optimizeNetty = true | ||
} | ||
} | ||
|
||
dependencies { | ||
annotationProcessor("io.micronaut.openapi:micronaut-openapi") | ||
annotationProcessor("io.micronaut:micronaut-http-validation") | ||
annotationProcessor("io.micronaut.tracing:micronaut-tracing-opentelemetry-annotation") | ||
annotationProcessor("io.micronaut.serde:micronaut-serde-processor") | ||
annotationProcessor("io.micronaut.validation:micronaut-validation-processor") | ||
annotationProcessor("io.micronaut.micrometer:micronaut-micrometer-annotation") | ||
|
||
implementation("io.micronaut:micronaut-http-client") | ||
implementation("io.micronaut.serde:micronaut-serde-jackson") | ||
implementation("io.micronaut.validation:micronaut-validation") | ||
implementation("io.micronaut:micronaut-retry") | ||
implementation("jakarta.validation:jakarta.validation-api") | ||
// Metrics | ||
implementation("io.micronaut:micronaut-management") | ||
implementation("io.micronaut.micrometer:micronaut-micrometer-core") | ||
implementation("io.micronaut.micrometer:micronaut-micrometer-registry-prometheus") | ||
|
||
// Tracing | ||
implementation("io.micronaut.tracing:micronaut-tracing-core") | ||
implementation("io.micronaut.tracing:micronaut-tracing-opentelemetry-http") | ||
implementation("io.opentelemetry:opentelemetry-exporter-zipkin") | ||
|
||
// Streaming | ||
implementation("io.micronaut.kafka:micronaut-kafka") | ||
|
||
implementation("io.swagger.core.v3:swagger-annotations") | ||
|
||
runtimeOnly("ch.qos.logback:logback-classic") | ||
|
||
compileOnly("io.micronaut.openapi:micronaut-openapi-annotations") | ||
|
||
runtimeOnly("org.yaml:snakeyaml") | ||
testImplementation(project(":tck")) | ||
testImplementation("io.micronaut:micronaut-http-client") | ||
} | ||
|
||
application { | ||
mainClass.set("events.Application") | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.toVersion("21") | ||
targetCompatibility = JavaVersion.toVersion("21") | ||
} | ||
|
||
if (javaBaseImage == "graalvm") { | ||
dockerfile { | ||
baseImage = "ghcr.io/graalvm/native-image-community:21" | ||
} | ||
} | ||
|
||
dockerBuild { | ||
images = ["phx.ocir.io/oraclelabs/micronaut-showcase/mushop/$project.parent.name-$project.name-${javaBaseImage}:$project.version"] | ||
} | ||
|
||
dockerBuildNative { | ||
images = ["phx.ocir.io/oraclelabs/micronaut-showcase/mushop/${project.parent.name}-${project.name}-native:$project.version"] | ||
} | ||
|
||
dockerfileNative { | ||
instruction "RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.11/main' >> /etc/apk/repositories && apk update && apk add 'zlib<1.2.12'" | ||
} |
72 changes: 35 additions & 37 deletions
72
src/events/app/src/main/java/events/controllers/EventController.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 |
---|---|---|
@@ -1,37 +1,35 @@ | ||
package events.controllers; | ||
|
||
import events.model.Event; | ||
import events.model.EventsReceived; | ||
import events.service.EventService; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Post; | ||
|
||
import javax.validation.constraints.Min; | ||
import javax.validation.constraints.NotBlank; | ||
|
||
@Controller("/events") | ||
class EventController { | ||
|
||
private final EventService eventService; | ||
|
||
EventController(EventService eventService) { | ||
this.eventService = eventService; | ||
} | ||
|
||
/** | ||
* Submit events endpoint. | ||
* | ||
* @param source The source of the event | ||
* @param track The event to track | ||
* @param events The events to post | ||
* @return Whether the events were received or not | ||
*/ | ||
@Post(processes = MediaType.APPLICATION_JSON) | ||
EventsReceived postEvents( | ||
@NotBlank String source, | ||
@NotBlank String track, | ||
@Min(1) Event...events) { | ||
return eventService.postEvents(source, track, events); | ||
} | ||
} | ||
package events.controllers; | ||
|
||
import events.model.Event; | ||
import events.model.EventsReceived; | ||
import events.service.EventService; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Post; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
@Controller("/events") | ||
class EventController { | ||
|
||
private final EventService eventService; | ||
|
||
EventController(EventService eventService) { | ||
this.eventService = eventService; | ||
} | ||
|
||
/** | ||
* Submit events endpoint. | ||
* | ||
* @param source The source of the event | ||
* @param track The event to track | ||
* @param events The events to post | ||
* @return Whether the events were received or not | ||
*/ | ||
@Post(processes = MediaType.APPLICATION_JSON) | ||
EventsReceived postEvents( | ||
@NotBlank String source, | ||
@NotBlank String track, | ||
Event...events) { | ||
return eventService.postEvents(source, track, events); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,30 +1,30 @@ | ||
package events.model; | ||
|
||
import io.micronaut.core.annotation.Introspected; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* The event to track. | ||
*/ | ||
@Introspected | ||
public class Event { | ||
|
||
private final String type; | ||
private final Map<String, String> detail; | ||
|
||
public Event(String type, Map<String, String> detail) { | ||
this.type = Objects.requireNonNull(type, "Type cannot be null"); | ||
this.detail = detail != null ? detail : Collections.emptyMap(); | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public Map<String, String> getDetail() { | ||
return detail; | ||
} | ||
} | ||
package events.model; | ||
import io.micronaut.serde.annotation.Serdeable; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
/** | ||
* The event to track. | ||
*/ | ||
@Serdeable | ||
public class Event { | ||
private final String type; | ||
private final Map<String, String> detail; | ||
public Event(String type, Map<String, String> detail) { | ||
this.type = Objects.requireNonNull(type, "Type cannot be null"); | ||
this.detail = detail != null ? detail : Collections.emptyMap(); | ||
} | ||
public String getType() { | ||
return type; | ||
} | ||
public Map<String, String> getDetail() { | ||
return detail; | ||
} | ||
} |
96 changes: 48 additions & 48 deletions
96
src/events/app/src/main/java/events/model/EventRecord.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 |
---|---|---|
@@ -1,48 +1,48 @@ | ||
package events.model; | ||
|
||
import io.micronaut.core.annotation.Creator; | ||
import io.micronaut.core.annotation.Introspected; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Event record. | ||
*/ | ||
@Introspected | ||
public class EventRecord extends Event { | ||
|
||
private final String source; | ||
private final String track; | ||
private final Instant time; | ||
|
||
public EventRecord(String source, | ||
String track, | ||
Event event) { | ||
this(source, track, Objects.requireNonNull(event, "Event cannot be null").getType(), event.getDetail()); | ||
} | ||
|
||
@Creator | ||
public EventRecord(String source, | ||
String track, | ||
String type, | ||
Map<String, String> detail) { | ||
super(type, detail); | ||
this.source = source; | ||
this.track = track; | ||
time = Instant.now(); | ||
} | ||
|
||
public String getSource() { | ||
return source; | ||
} | ||
|
||
public String getTrack() { | ||
return track; | ||
} | ||
|
||
public Instant getTime() { | ||
return time; | ||
} | ||
} | ||
package events.model; | ||
import io.micronaut.core.annotation.Creator; | ||
import io.micronaut.serde.annotation.Serdeable; | ||
import java.time.Instant; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
/** | ||
* Event record. | ||
*/ | ||
@Serdeable | ||
public class EventRecord extends Event { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Record please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
private final String source; | ||
private final String track; | ||
private final Instant time; | ||
public EventRecord(String source, | ||
String track, | ||
Event event) { | ||
this(source, track, Objects.requireNonNull(event, "Event cannot be null").getType(), event.getDetail()); | ||
} | ||
@Creator | ||
public EventRecord(String source, | ||
String track, | ||
String type, | ||
Map<String, String> detail) { | ||
super(type, detail); | ||
this.source = source; | ||
this.track = track; | ||
time = Instant.now(); | ||
} | ||
public String getSource() { | ||
return source; | ||
} | ||
public String getTrack() { | ||
return track; | ||
} | ||
public Instant getTime() { | ||
return time; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Record please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done