generated from creek-service/basic-kafka-streams-demo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding service 'handle-scoreboard-service'
- Loading branch information
Showing
15 changed files
with
430 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM amazoncorretto:19@sha256:a197d796640268bd6fcb74507f92efe69274b2c13de63ee36a07c25058d4bd3f | ||
ARG APP_NAME | ||
ARG APP_VERSION | ||
ENV VERSION=$APP_VERSION | ||
|
||
LABEL org.opencontainers.image.source=https://github.com/creek-service/connected-services-demo/tree/main/handle-scoreboard-service | ||
|
||
RUN yum update -y | ||
RUN yum install -y tar lsof | ||
|
||
RUN mkdir -p /opt/creek | ||
|
||
COPY bin /bin | ||
COPY log4j /log | ||
|
||
COPY ${APP_NAME}-${APP_VERSION}.tar /opt/creek | ||
WORKDIR /opt/creek | ||
RUN tar xf ${APP_NAME}-${APP_VERSION}.tar | ||
RUN ln -s ${APP_NAME}-${APP_VERSION} service | ||
|
||
ENTRYPOINT ["/bin/run.sh"] |
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,72 @@ | ||
/* | ||
* Copyright 2023 Creek Contributors (https://github.com/creek-service) | ||
* | ||
* 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. | ||
*/ | ||
|
||
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage | ||
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage | ||
|
||
plugins { | ||
application | ||
id("com.bmuschko.docker-remote-api") | ||
} | ||
|
||
val creekVersion : String by extra | ||
val kafkaVersion : String by extra | ||
val log4jVersion : String by extra | ||
|
||
dependencies { | ||
implementation(project(":services")) | ||
implementation("org.creekservice:creek-service-context:$creekVersion") | ||
implementation("org.creekservice:creek-kafka-streams-extension:$creekVersion") | ||
implementation("org.apache.logging.log4j:log4j-core:$log4jVersion") | ||
runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl:$log4jVersion") | ||
|
||
testImplementation("org.creekservice:creek-kafka-streams-test:$creekVersion") | ||
} | ||
|
||
// Patch Kafka Streams test jar into main Kafka Streams module to avoid split packages: | ||
modularity.patchModule("kafka.streams", "kafka-streams-test-utils-$kafkaVersion.jar") | ||
|
||
application { | ||
mainModule.set("connected.services.demo.handle.scoreboard.service") | ||
mainClass.set("io.github.creek.service.connected.services.demo.handle.scoreboard.service.ServiceMain") | ||
} | ||
|
||
val buildAppImage = tasks.register<DockerBuildImage>("buildAppImage") { | ||
dependsOn("prepareDocker") | ||
buildArgs.put("APP_NAME", project.name) | ||
buildArgs.put("APP_VERSION", "${project.version}") | ||
images.add("ghcr.io/creek-service/${rootProject.name}-${project.name}:latest") | ||
images.add("ghcr.io/creek-service/${rootProject.name}-${project.name}:${project.version}") | ||
} | ||
|
||
tasks.register<Copy>("prepareDocker") { | ||
dependsOn("distTar") | ||
|
||
from( | ||
layout.projectDirectory.file("Dockerfile"), | ||
layout.buildDirectory.file("distributions/${project.name}-${project.version}.tar"), | ||
layout.projectDirectory.dir("include"), | ||
) | ||
|
||
into(buildAppImage.get().inputDir) | ||
} | ||
|
||
tasks.register<DockerPushImage>("pushAppImage") { | ||
dependsOn("buildAppImage") | ||
images.add("ghcr.io/creek-service/${rootProject.name}-${project.name}:latest") | ||
images.add("ghcr.io/creek-service/${rootProject.name}-${project.name}:${project.version}") | ||
} | ||
|
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,23 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright 2022-2023 Creek Contributors (https://github.com/creek-service) | ||
# | ||
# 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. | ||
# | ||
|
||
exec java \ | ||
-Xms64m -Xmx256m \ | ||
-Dlog4j.configurationFile=/log/log4j2.xml \ | ||
--module-path "/opt/creek/service/lib" \ | ||
--module connected.services.demo.handle.scoreboard.service/io.github.creek.service.connected.services.demo.handle.scoreboard.service.ServiceMain |
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,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2022-2023 Creek Contributors (https://github.com/creek-service) | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<Configuration status="WARN"> | ||
<Appenders> | ||
<Console name="console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Logger name="org.creekservice" level="DEBUG" additivity="false"> | ||
<AppenderRef ref="console"/> | ||
</Logger> | ||
<Logger name="kafka" level="info" additivity="false"> | ||
<AppenderRef ref="console"/> | ||
</Logger> | ||
<Logger name="org.apache.kafka" level="info" additivity="false"> | ||
<AppenderRef ref="console"/> | ||
</Logger> | ||
<Root level="INFO"> | ||
<AppenderRef ref="console"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
45 changes: 45 additions & 0 deletions
45
...o/github/creek/service/connected/services/demo/handle/scoreboard/service/ServiceMain.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,45 @@ | ||
/* | ||
* Copyright 2021-2023 Creek Contributors (https://github.com/creek-service) | ||
* | ||
* 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 io.github.creek.service.connected.services.demo.handle.scoreboard.service; | ||
|
||
import io.github.creek.service.connected.services.demo.handle.scoreboard.service.kafka.streams.TopologyBuilder; | ||
import io.github.creek.service.connected.services.demo.services.HandleScoreboardServiceDescriptor; | ||
import org.apache.kafka.streams.Topology; | ||
import org.creekservice.api.kafka.streams.extension.KafkaStreamsExtension; | ||
import org.creekservice.api.kafka.streams.extension.KafkaStreamsExtensionOptions; | ||
import org.creekservice.api.service.context.CreekContext; | ||
import org.creekservice.api.service.context.CreekServices; | ||
|
||
/** Entry point of the service */ | ||
public final class ServiceMain { | ||
|
||
private ServiceMain() {} | ||
|
||
public static void main(final String... args) { | ||
final CreekContext ctx = | ||
CreekServices.builder(new HandleScoreboardServiceDescriptor()) | ||
.with( | ||
KafkaStreamsExtensionOptions.builder() | ||
// Customize the Kafka streams extension here... | ||
.build()) | ||
.build(); | ||
|
||
final KafkaStreamsExtension ext = ctx.extension(KafkaStreamsExtension.class); | ||
final Topology topology = new TopologyBuilder(ext).build(); | ||
ext.execute(topology); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...vice/connected/services/demo/handle/scoreboard/service/kafka/streams/TopologyBuilder.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,41 @@ | ||
/* | ||
* Copyright 2022-2023 Creek Contributors (https://github.com/creek-service) | ||
* | ||
* 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 io.github.creek.service.connected.services.demo.handle.scoreboard.service.kafka.streams; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.creekservice.api.kafka.metadata.KafkaTopicDescriptor.DEFAULT_CLUSTER_NAME; | ||
|
||
import org.apache.kafka.streams.StreamsBuilder; | ||
import org.apache.kafka.streams.Topology; | ||
import org.creekservice.api.kafka.streams.extension.KafkaStreamsExtension; | ||
import org.creekservice.api.kafka.streams.extension.util.Name; | ||
|
||
public final class TopologyBuilder { | ||
|
||
private final KafkaStreamsExtension ext; | ||
private final Name name = Name.root(); | ||
|
||
public TopologyBuilder(final KafkaStreamsExtension ext) { | ||
this.ext = requireNonNull(ext, "ext"); | ||
} | ||
|
||
public Topology build() { | ||
final StreamsBuilder builder = new StreamsBuilder(); | ||
|
||
return builder.build(ext.properties(DEFAULT_CLUSTER_NAME)); | ||
} | ||
} |
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,6 @@ | ||
module connected.services.demo.handle.scoreboard.service { | ||
requires connected.services.demo.services; | ||
requires creek.service.context; | ||
requires creek.kafka.streams.extension; | ||
requires org.apache.logging.log4j; | ||
} |
95 changes: 95 additions & 0 deletions
95
.../io/github/creek/service/connected/services/demo/example/streams/TopologyBuilderTest.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,95 @@ | ||
/* | ||
* Copyright 2022-2023 Creek Contributors (https://github.com/creek-service) | ||
* | ||
* 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 io.github.creek.service.connected.services.demo.example.streams; | ||
|
||
import static org.creekservice.api.kafka.metadata.KafkaTopicDescriptor.DEFAULT_CLUSTER_NAME; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import io.github.creek.service.connected.services.demo.handle.scoreboard.service.kafka.streams.TopologyBuilder; | ||
import io.github.creek.service.connected.services.demo.services.HandleScoreboardServiceDescriptor; | ||
import org.apache.kafka.streams.Topology; | ||
import org.apache.kafka.streams.TopologyTestDriver; | ||
import org.creekservice.api.kafka.streams.extension.KafkaStreamsExtension; | ||
import org.creekservice.api.kafka.streams.test.TestKafkaStreamsExtensionOptions; | ||
import org.creekservice.api.service.context.CreekContext; | ||
import org.creekservice.api.service.context.CreekServices; | ||
import org.creekservice.api.test.util.TestPaths; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class TopologyBuilderTest { | ||
|
||
private static CreekContext ctx; | ||
|
||
private TopologyTestDriver testDriver; | ||
private Topology topology; | ||
|
||
@BeforeAll | ||
public static void classSetup() { | ||
ctx = | ||
CreekServices.builder(new HandleScoreboardServiceDescriptor()) | ||
.with(TestKafkaStreamsExtensionOptions.defaults()) | ||
.build(); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
final KafkaStreamsExtension ext = ctx.extension(KafkaStreamsExtension.class); | ||
|
||
topology = new TopologyBuilder(ext).build(); | ||
testDriver = new TopologyTestDriver(topology, ext.properties(DEFAULT_CLUSTER_NAME)); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
testDriver.close(); | ||
} | ||
|
||
/** | ||
* A test that intentionally fails when ever the topology changes. | ||
* | ||
* <p>This is to make it less likely that unintentional changes to the topology are committed | ||
* and that thought is given to any intentional changes to ensure they won't break any deployed | ||
* instances. | ||
* | ||
* <p>Care must be taken when changing a deployed topology to ensure either: | ||
* | ||
* <ol> | ||
* <li>Changes are backwards compatible and won't leave data stranded in unused topics, or | ||
* <li>The existing topology is drained before the new topology is deployed | ||
* </ol> | ||
* | ||
* <p>Option #1 allows for the simplest deployment, but is not always possible or desirable. | ||
*/ | ||
@Test | ||
void shouldNotChangeTheTopologyUnintentionally() { | ||
// Given: | ||
final String expectedTopology = | ||
TestPaths.readString( | ||
TestPaths.moduleRoot("handle-scoreboard-service") | ||
.resolve("src/test/resources/kafka/streams/expected_topology.txt")); | ||
|
||
// When: | ||
final String currentTopology = topology.describe().toString(); | ||
|
||
// Then: | ||
assertThat(currentTopology.trim(), is(expectedTopology.trim())); | ||
} | ||
} |
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 @@ | ||
--add-modules | ||
org.junitpioneer,org.hamcrest,guava.testlib,creek.test.util,creek.test.hamcrest,creek.kafka.streams.test | ||
|
||
--add-reads | ||
connected.services.demo.handle.scoreboard.service=org.junitpioneer,org.hamcrest,guava.testlib,creek.test.util,creek.test.hamcrest,creek.kafka.streams.test | ||
|
||
--add-opens | ||
org.junitpioneer/org.junitpioneer.jupiter=org.junit.platform.commons |
1 change: 1 addition & 0 deletions
1
handle-scoreboard-service/src/test/resources/kafka/streams/expected_topology.txt
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 @@ | ||
Topologies: |
Oops, something went wrong.