# Mixing Processor API with Stream DSL

**URL:** <https://forum.confluent.io/t/mixing-processor-api-with-stream-dsl/4671>\
**Category:** Kafka Streams\
**Created:** [1 April 2022 20:48 UTC](https://forum.confluent.io/t/mixing-processor-api-with-stream-dsl/4671 "2022-04-01T20:48:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaeltuelho](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/rafaeltuelho/32/1765_2.png) [@rafaeltuelho](https://forum.confluent.io/u/rafaeltuelho)\
**Post date:** [1 April 2022 20:48 UTC](https://forum.confluent.io/t/mixing-processor-api-with-stream-dsl/4671/1 "2022-04-01T20:48:38Z")

</div>

Hi.  
How can I combine Stream DSL within a Processor based Topology?  
Taking this sample topology from the KStream 101 course:

```java
        final Topology topology = new Topology();
        topology.addSource("source-node", Serdes.String().deserializer(), electronicSerde.deserializer(), inputTopic);
        topology.addProcessor("aggregate-price", new TotalPriceOrderProcessorSupplier(storeName), "source-node");
       // --> DSL OP HERE <--
        topology.addSink(
            "sink-node", 
            outputTopic, 
            stringSerde.serializer(), 
            doubleSerde.serializer(), 
            "aggregate-price");

```

Is it possible to insert a stateless DSL operation like `peek or filter` before sending to the sink topic?

---

<div class="post-metadata">

**Author:** ![bbejeck](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/bbejeck/32/412_2.png) [@bbejeck](https://forum.confluent.io/u/bbejeck)\
**Post date:** [4 April 2022 20:06 UTC](https://forum.confluent.io/t/mixing-processor-api-with-stream-dsl/4671/2 "2022-04-04T20:06:06Z")

</div>

Hi rafaeltuelho,

While you can mix in the Processor API from the DSL with `process` or one of the `transformXXX` variants, you can’t do it the other way. There’s no mechanism to mix the DSL into the Processor API.

To add in `peek` or `filter` functionality, you need to use the `addProcessor` method.  
Here’s an example of adding a simulated `peek` operation printing to the console

```auto
 topology.addProcessor("printing",
                () -> (Processor<String, Double, String, Double>) record -> System.out.printf("key[%s] value[%s] %n", record.key(), record.value()),
                "aggregate-price");

```

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![rafaeltuelho](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/rafaeltuelho/32/1765_2.png) [@rafaeltuelho](https://forum.confluent.io/u/rafaeltuelho)\
**Post date:** [6 April 2022 18:11 UTC](https://forum.confluent.io/t/mixing-processor-api-with-stream-dsl/4671/3 "2022-04-06T18:11:45Z")

</div>

Got it!

Thanks @bbejeck

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/confluentcommunity/original/1X/c49438c90c9df282e9996fdf6971be890c71b65a.svg) [@system](https://forum.confluent.io/u/system)\
**Post date:** [13 April 2022 18:12 UTC](https://forum.confluent.io/t/mixing-processor-api-with-stream-dsl/4671/4 "2022-04-13T18:12:11Z")

</div>

Closed on 13 April 2022 18:12 UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
