将Kafka Streams代码迁移到Spring Cloud Stream吗?

时间:2019-12-03 10:57:39

标签: apache-kafka apache-kafka-streams spring-kafka spring-cloud-stream

Spring云流将支持下面的Kafka Streams应用程序。 以下是Kafka示例应用程序摘录中的代码。感谢您的任何反馈或支持。

        ...
        StreamsBuilder streamsBuilder = new StreamsBuilder();

        KStream<String, Purchase> purchaseKStream = streamsBuilder.stream.....
        KStream<String, PurchasePattern> patternKStream = purchaseKStream.mapValues...
        patternKStream.print(Printed.<String, PurchasePattern>toSysOut().withLabel("patterns"));
        patternKStream.to("patterns", Produced.with(stringSerde, purchasePatternSerde));
        purchaseKStream.print(Printed.<String, Purchase>toSysOut().withLabel("purchases"));
        purchaseKStream.to("purchases", Produced.with(stringSerde, purchaseSerde));

        // adding State to processor
        String rewardsStateStoreName = "rewardsPointsStore";
        RewardsStreamPartitioner streamPartitioner = new RewardsStreamPartitioner();
        KeyValueBytesStoreSupplier storeSupplier = Stores.inMemoryKeyValueStore(rewardsStateStoreName);
        StoreBuilder<KeyValueStore<String, Integer>> storeBuilder = Stores.keyValueStoreBuilder(storeSupplier.....
        streamsBuilder.addStateStore(storeBuilder);
        KStream<String, Purchase> transByCustomerStream = purchaseKStream.through("customer_transactions",....
        KStream<String, RewardAccumulator> statefulRewardAccumulator = transByCustomerStream
                .transformValues(() -> new PurchaseRewardTransformer(rewardsStateStoreName), rewardsStateStoreName);
        statefulRewardAccumulator.print(Printed.<String, RewardAccumulator>toSysOut().withLabel("stateful-rewards"));
        statefulRewardAccumulator.to("rewards", Produced.with(stringSerde, rewardAccumulatorSerde));

        KafkaStreams kafkaStreams = new KafkaStreams(streamsBuilder.build(), getProperties());

1 个答案:

答案 0 :(得分:0)

假设您正在使用Spring Cloud Stream lazy var theCustomWishlistView: CustomWishlistView = { let v = CustomWishlistView() v.translatesAutoresizingMaskIntoConstraints = false v.backgroundColor = .darkGray v.layer.cornerRadius = 30 return v }() 版本,则以下伪代码应该可以使用。我没有测试此代码,但是它应该与目标等的正确配置一起使用。请查看docs

Horsham (3.0.0)