-
Notifications
You must be signed in to change notification settings - Fork 15
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
62f0993
commit ef76982
Showing
8 changed files
with
124 additions
and
145 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
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
38 changes: 19 additions & 19 deletions
38
src/events/app/src/main/java/events/service/EventProducer.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,19 +1,19 @@ | ||
package events.service; | ||
|
||
import events.model.EventRecord; | ||
import io.micronaut.configuration.kafka.annotation.KafkaClient; | ||
import io.micronaut.configuration.kafka.annotation.Topic; | ||
|
||
/** | ||
* The messaging Kafka {@link EventRecord} producer. | ||
* | ||
* The annotation {@link KafkaClient} is handled by {@link io.micronaut.configuration.kafka.intercept.KafkaClientIntroductionAdvice} | ||
* which introduces new bean that is able to handle publishing of {@link EventRecord}s to the Kafka. | ||
*/ | ||
@KafkaClient(batch = true) | ||
public interface EventProducer { | ||
String EVENT_TOPIC_NAME = "events"; | ||
|
||
@Topic(EVENT_TOPIC_NAME) | ||
void send(EventRecord... eventRecords); | ||
} | ||
package events.service; | ||
|
||
import events.model.EventRecord; | ||
import io.micronaut.configuration.kafka.annotation.KafkaClient; | ||
import io.micronaut.configuration.kafka.annotation.Topic; | ||
|
||
/** | ||
* The messaging Kafka {@link EventRecord} producer. | ||
* | ||
* The annotation {@link KafkaClient} is handled by {@link io.micronaut.configuration.kafka.intercept.KafkaClientIntroductionAdvice} | ||
* which introduces new bean that is able to handle publishing of {@link EventRecord}s to the Kafka. | ||
*/ | ||
@KafkaClient(batch = true) | ||
public interface EventProducer { | ||
String EVENT_TOPIC_NAME = "events"; | ||
|
||
@Topic(EVENT_TOPIC_NAME) | ||
void send(EventRecord...eventRecords); | ||
} |
94 changes: 47 additions & 47 deletions
94
src/events/app/src/main/java/events/service/EventService.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,47 +1,47 @@ | ||
package events.service; | ||
|
||
import events.model.Event; | ||
import events.model.EventRecord; | ||
import events.model.EventsReceived; | ||
import io.micronaut.tracing.annotation.NewSpan; | ||
import io.micronaut.tracing.annotation.SpanTag; | ||
import jakarta.inject.Singleton; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Arrays; | ||
|
||
@Singleton | ||
public class EventService { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(EventService.class); | ||
|
||
private final EventProducer eventProducer; | ||
|
||
public EventService(EventProducer eventProducer) { | ||
this.eventProducer = eventProducer; | ||
} | ||
|
||
@NewSpan("receive events") | ||
public EventsReceived postEvents(@SpanTag String source, | ||
String track, | ||
Event... events) { | ||
final int numEvents = events.length; | ||
try { | ||
LOG.debug("Posting Events (source: {}, track {}, length {})", source, track, numEvents); | ||
if (numEvents == 0) { | ||
return new EventsReceived(false, 0); | ||
} | ||
|
||
final EventRecord[] eventRecords = Arrays.stream(events) | ||
.map(ev -> new EventRecord(source, track, ev)) | ||
.toArray(EventRecord[]::new); | ||
|
||
eventProducer.send(eventRecords); | ||
return new EventsReceived(true, events.length); | ||
} catch (Exception e) { | ||
LOG.error("Unable to process events: {}", e.getMessage(), e); | ||
return new EventsReceived(false, events.length); | ||
} | ||
} | ||
} | ||
package events.service; | ||
|
||
import events.model.Event; | ||
import events.model.EventRecord; | ||
import events.model.EventsReceived; | ||
import io.micronaut.tracing.annotation.NewSpan; | ||
import io.micronaut.tracing.annotation.SpanTag; | ||
import jakarta.inject.Singleton; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Arrays; | ||
|
||
@Singleton | ||
public class EventService { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(EventService.class); | ||
|
||
private final EventProducer eventProducer; | ||
|
||
public EventService(EventProducer eventProducer) { | ||
this.eventProducer = eventProducer; | ||
} | ||
|
||
@NewSpan("receive events") | ||
public EventsReceived postEvents(@SpanTag String source, | ||
String track, | ||
Event... events) { | ||
final int numEvents = events.length; | ||
try { | ||
LOG.debug("Posting Events (source: {}, track {}, length {})", source, track, numEvents); | ||
if (numEvents == 0) { | ||
return new EventsReceived(false, 0); | ||
} | ||
|
||
final EventRecord[] eventRecords = Arrays.stream(events) | ||
.map(ev -> new EventRecord(source, track, ev)) | ||
.toArray(EventRecord[]::new); | ||
|
||
eventProducer.send(eventRecords); | ||
return new EventsReceived(true, events.length); | ||
} catch (Exception e) { | ||
LOG.error("Unable to process events: {}", e.getMessage(), e); | ||
return new EventsReceived(false, events.length); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
plugins { | ||
id 'groovy-gradle-plugin' | ||
} | ||
repositories { | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
dependencies { | ||
implementation("com.bmuschko:gradle-docker-plugin:9.4.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