Search in sources :

Example 16 with KafkaSystemDescriptor

use of org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor in project samza by apache.

the class AsyncApplicationExample method describe.

@Override
public void describe(StreamApplicationDescriptor appDescriptor) {
    KafkaSystemDescriptor trackingSystem = new KafkaSystemDescriptor("tracking");
    KafkaInputDescriptor<AdClickEvent> inputStreamDescriptor = trackingSystem.getInputDescriptor("adClickEvent", new JsonSerdeV2<>(AdClickEvent.class));
    KafkaOutputDescriptor<KV<String, EnrichedAdClickEvent>> outputStreamDescriptor = trackingSystem.getOutputDescriptor("enrichedAdClickEvent", KVSerde.of(new StringSerde(), new JsonSerdeV2<>(EnrichedAdClickEvent.class)));
    MessageStream<AdClickEvent> adClickEventStream = appDescriptor.getInputStream(inputStreamDescriptor);
    OutputStream<KV<String, EnrichedAdClickEvent>> enrichedAdClickStream = appDescriptor.getOutputStream(outputStreamDescriptor);
    adClickEventStream.flatMapAsync(AsyncApplicationExample::enrichAdClickEvent).map(enrichedAdClickEvent -> KV.of(enrichedAdClickEvent.getCountry(), enrichedAdClickEvent)).sendTo(enrichedAdClickStream);
}
Also used : CommandLine(org.apache.samza.util.CommandLine) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) StringSerde(org.apache.samza.serializers.StringSerde) AdClickEvent(org.apache.samza.example.models.AdClickEvent) KafkaOutputDescriptor(org.apache.samza.system.kafka.descriptors.KafkaOutputDescriptor) ImmutableList(com.google.common.collect.ImmutableList) EnrichedAdClickEvent(org.apache.samza.example.models.EnrichedAdClickEvent) ApplicationRunners(org.apache.samza.runtime.ApplicationRunners) KV(org.apache.samza.operators.KV) MessageStream(org.apache.samza.operators.MessageStream) ApplicationRunner(org.apache.samza.runtime.ApplicationRunner) KafkaInputDescriptor(org.apache.samza.system.kafka.descriptors.KafkaInputDescriptor) Collection(java.util.Collection) Member(org.apache.samza.example.models.Member) KafkaSystemDescriptor(org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) StreamApplicationDescriptor(org.apache.samza.application.descriptors.StreamApplicationDescriptor) Config(org.apache.samza.config.Config) JsonSerdeV2(org.apache.samza.serializers.JsonSerdeV2) KVSerde(org.apache.samza.serializers.KVSerde) StreamApplication(org.apache.samza.application.StreamApplication) Collections(java.util.Collections) OutputStream(org.apache.samza.operators.OutputStream) AdClickEvent(org.apache.samza.example.models.AdClickEvent) EnrichedAdClickEvent(org.apache.samza.example.models.EnrichedAdClickEvent) StringSerde(org.apache.samza.serializers.StringSerde) KV(org.apache.samza.operators.KV) KafkaSystemDescriptor(org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor) JsonSerdeV2(org.apache.samza.serializers.JsonSerdeV2)

Example 17 with KafkaSystemDescriptor

use of org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor in project samza by apache.

the class BroadcastAssertApp method describe.

@Override
public void describe(StreamApplicationDescriptor appDescriptor) {
    Config config = appDescriptor.getConfig();
    String inputTopic = config.get(INPUT_TOPIC_NAME_PROP);
    final JsonSerdeV2<PageView> serde = new JsonSerdeV2<>(PageView.class);
    KafkaSystemDescriptor ksd = new KafkaSystemDescriptor(SYSTEM);
    KafkaInputDescriptor<PageView> isd = ksd.getInputDescriptor(inputTopic, serde);
    final MessageStream<PageView> broadcastPageViews = appDescriptor.getInputStream(isd).broadcast(serde, "pv");
    /**
     * Each task will see all the pageview events
     */
    MessageStreamAssert.that("Each task contains all broadcast PageView events", broadcastPageViews, serde).forEachTask().containsInAnyOrder(Arrays.asList(new PageView("v1", "p1", "u1"), new PageView("v2", "p2", "u1"), new PageView("v3", "p1", "u2"), new PageView("v4", "p3", "u2")));
}
Also used : PageView(org.apache.samza.test.operator.data.PageView) Config(org.apache.samza.config.Config) KafkaSystemDescriptor(org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor) JsonSerdeV2(org.apache.samza.serializers.JsonSerdeV2)

Example 18 with KafkaSystemDescriptor

use of org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor in project samza by apache.

the class TestStreamApplication method describe.

@Override
public void describe(StreamApplicationDescriptor appDescriptor) {
    KafkaSystemDescriptor ksd = new KafkaSystemDescriptor(systemName);
    KafkaOutputDescriptor<String> osd = ksd.getOutputDescriptor(outputTopic, new StringSerde());
    OutputStream<String> outputStream = appDescriptor.getOutputStream(osd);
    for (String inputTopic : inputTopics) {
        KafkaInputDescriptor<String> isd = ksd.getInputDescriptor(inputTopic, new NoOpSerde<>());
        MessageStream<String> inputStream = appDescriptor.getInputStream(isd);
        inputStream.map(new TestMapFunction(appName, processorName)).sendTo(outputStream);
    }
}
Also used : StringSerde(org.apache.samza.serializers.StringSerde) KafkaSystemDescriptor(org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor)

Example 19 with KafkaSystemDescriptor

use of org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor in project samza by apache.

the class TestTaskApplication method describe.

@Override
public void describe(TaskApplicationDescriptor appDescriptor) {
    KafkaSystemDescriptor ksd = new KafkaSystemDescriptor(systemName);
    KafkaInputDescriptor<TestTableData.Profile> inputDescriptor = ksd.getInputDescriptor(inputTopic, new NoOpSerde<>());
    KafkaOutputDescriptor<TestTableData.EnrichedPageView> outputDescriptor = ksd.getOutputDescriptor(outputTopic, new NoOpSerde<>());
    appDescriptor.withInputStream(inputDescriptor).withOutputStream(outputDescriptor).withTaskFactory((AsyncStreamTaskFactory) () -> new TestTaskImpl());
}
Also used : KafkaSystemDescriptor(org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor)

Aggregations

KafkaSystemDescriptor (org.apache.samza.system.kafka.descriptors.KafkaSystemDescriptor)19 StringSerde (org.apache.samza.serializers.StringSerde)14 KV (org.apache.samza.operators.KV)13 JsonSerdeV2 (org.apache.samza.serializers.JsonSerdeV2)13 Config (org.apache.samza.config.Config)12 StreamApplication (org.apache.samza.application.StreamApplication)11 StreamApplicationDescriptor (org.apache.samza.application.descriptors.StreamApplicationDescriptor)11 KVSerde (org.apache.samza.serializers.KVSerde)11 KafkaInputDescriptor (org.apache.samza.system.kafka.descriptors.KafkaInputDescriptor)11 ApplicationRunner (org.apache.samza.runtime.ApplicationRunner)10 ApplicationRunners (org.apache.samza.runtime.ApplicationRunners)10 KafkaOutputDescriptor (org.apache.samza.system.kafka.descriptors.KafkaOutputDescriptor)10 CommandLine (org.apache.samza.util.CommandLine)10 MessageStream (org.apache.samza.operators.MessageStream)9 Duration (java.time.Duration)8 PageViewEvent (org.apache.samza.example.models.PageViewEvent)7 OutputStream (org.apache.samza.operators.OutputStream)7 Windows (org.apache.samza.operators.windows.Windows)7 PageView (org.apache.samza.test.operator.data.PageView)5 WindowPane (org.apache.samza.operators.windows.WindowPane)4