|
| 1 | +/* |
| 2 | + * Copyright 2021-2022 Creek Contributors (https://github.com/creek-service) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.github.creek.service.basic.kafka.streams.demo.services; |
| 18 | + |
| 19 | +// formatting:off |
| 20 | +// begin-snippet: includes-1 |
| 21 | +import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicConfigBuilder.withPartitions; |
| 22 | +import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.inputTopic; |
| 23 | +import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.outputTopic; |
| 24 | +// end-snippet |
| 25 | +import java.time.Duration; |
| 26 | +import java.util.ArrayList; |
| 27 | +import java.util.Collection; |
| 28 | +import java.util.List; |
| 29 | +// begin-snippet: includes-2 |
| 30 | +import org.creekservice.api.kafka.metadata.OwnedKafkaTopicInput; |
| 31 | +import org.creekservice.api.kafka.metadata.OwnedKafkaTopicOutput; |
| 32 | +// end-snippet |
| 33 | +import org.creekservice.api.platform.metadata.ComponentInput; |
| 34 | +import org.creekservice.api.platform.metadata.ComponentInternal; |
| 35 | +import org.creekservice.api.platform.metadata.ComponentOutput; |
| 36 | +import org.creekservice.api.platform.metadata.ServiceDescriptor; |
| 37 | +// formatting:on |
| 38 | + |
| 39 | +// begin-snippet: class-name |
| 40 | +public final class HandleOccurrenceServiceDescriptor implements ServiceDescriptor { |
| 41 | + // end-snippet |
| 42 | + private static final List<ComponentInput> INPUTS = new ArrayList<>(); |
| 43 | + private static final List<ComponentInternal> INTERNALS = new ArrayList<>(); |
| 44 | + private static final List<ComponentOutput> OUTPUTS = new ArrayList<>(); |
| 45 | + |
| 46 | + // formatting:off |
| 47 | +// begin-snippet: topic-resources |
| 48 | + // Define the tweet-text input topic, conceptually owned by this service: |
| 49 | + public static final OwnedKafkaTopicInput<Long, String> TweetTextStream = |
| 50 | + register( |
| 51 | + inputTopic( |
| 52 | + "twitter.tweet.text", // Topic name |
| 53 | + Long.class, // Topic key: Tweet id |
| 54 | + String.class, // Topic value: Tweet text |
| 55 | + withPartitions(5))); // Topic config |
| 56 | + |
| 57 | + // Define the output topic, again conceptually owned by this service: |
| 58 | + public static final OwnedKafkaTopicOutput<String, Integer> TweetHandleUsageStream = |
| 59 | + register(outputTopic( |
| 60 | + "twitter.handle.usage", |
| 61 | + String.class, // Twitter handle |
| 62 | + Integer.class, // Usage count |
| 63 | + withPartitions(6) |
| 64 | + .withRetentionTime(Duration.ofHours(12)) |
| 65 | + )); |
| 66 | +// end-snippet |
| 67 | +// formatting:on |
| 68 | + |
| 69 | + public HandleOccurrenceServiceDescriptor() {} |
| 70 | + |
| 71 | + @Override |
| 72 | + public String dockerImage() { |
| 73 | + return "ghcr.io/creek-service/basic-kafka-streams-demo-handle-occurrence-service"; |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public Collection<ComponentInput> inputs() { |
| 78 | + return List.copyOf(INPUTS); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public Collection<ComponentInternal> internals() { |
| 83 | + return List.copyOf(INTERNALS); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public Collection<ComponentOutput> outputs() { |
| 88 | + return List.copyOf(OUTPUTS); |
| 89 | + } |
| 90 | + |
| 91 | + private static <T extends ComponentInput> T register(final T input) { |
| 92 | + INPUTS.add(input); |
| 93 | + return input; |
| 94 | + } |
| 95 | + |
| 96 | + // Uncomment if needed: |
| 97 | + // private static <T extends ComponentInternal> T register(final T internal) { |
| 98 | + // INTERNALS.add(internal); |
| 99 | + // return internal; |
| 100 | + // } |
| 101 | + |
| 102 | + private static <T extends ComponentOutput> T register(final T output) { |
| 103 | + OUTPUTS.add(output); |
| 104 | + return output; |
| 105 | + } |
| 106 | +} |
0 commit comments