Skip to content

Commit

Permalink
Chore/align cloudstream example (#464)
Browse files Browse the repository at this point in the history
* chore(cloud-stream): align example

* chore(cloud-stream): fix cloud-stream message description

the description is part of the schema, therefore removing the duplicate in the message
(aligns with other plugins)
  • Loading branch information
timonback authored Nov 20, 2023
1 parent 707b7ce commit 2b7dafe
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ private Message buildMessage(Method method) {
return Message.builder()
.name(payloadType.getName())
.title(payloadType.getSimpleName())
.description(null)
.payload(PayloadReference.fromModelName(modelName))
.headers(HeaderReference.fromModelName(headerModelName))
.bindings(buildMessageBinding(method))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private ChannelItem buildChannel(
Message message = Message.builder()
.name(payloadType.getName())
.title(payloadType.getSimpleName())
.description(null)
.payload(PayloadReference.fromModelName(modelName))
.headers(HeaderReference.fromModelName(headerModelName))
.bindings(messageBinding)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.example.cloudstream;

import io.github.stavshamir.springwolf.example.cloudstream.payload.ConsumerPayload;
import io.github.stavshamir.springwolf.example.cloudstream.payload.InputPayload;
import io.github.stavshamir.springwolf.example.cloudstream.payload.OutputPayload;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.streams.kstream.KStream;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.function.Consumer;
import java.util.function.Function;

@SpringBootApplication
@Slf4j
public class SpringwolfCloudstreamExampleApplication {

public static void main(String[] args) {
SpringApplication.run(SpringwolfCloudstreamExampleApplication.class, args);
}

@Bean
public Function<KStream<Void, InputPayload>, KStream<Void, OutputPayload>> process() {
return input -> input.peek((k, v) -> log.info("Received payload: {}", v))
.mapValues(
v -> new OutputPayload(v.getFoo().stream().findFirst().orElse("list was empty"), v.getBar()))
.peek((k, v) -> log.info("Publishing output: {}", v));
}

@Bean
public Consumer<ConsumerPayload> consumerMethod() {
return input -> log.info("Consumed: {}", input);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.example.cloudstream.configuration;

import io.github.stavshamir.springwolf.example.cloudstream.dtos.AnotherPayloadDto;
import io.github.stavshamir.springwolf.example.cloudstream.dtos.ExamplePayloadDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.streams.kstream.KStream;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.function.Consumer;
import java.util.function.Function;

@Slf4j
@Configuration
public class CloudstreamConfiguration {
@Bean
public Function<KStream<Void, ExamplePayloadDto>, KStream<Void, AnotherPayloadDto>> process() {
return input -> input.peek((k, v) -> log.info("Received new message in example-topic: {}", input))
.mapValues(v -> new AnotherPayloadDto("foo", v))
.peek((k, v) -> log.info("Publishing output: {}", v));
}

@Bean
public Consumer<AnotherPayloadDto> consumerMethod() {
return input -> log.info("Received new message in another-topic: {}", input.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.example.cloudstream.dtos;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

@Schema(description = "Another payload model")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AnotherPayloadDto {

@Schema(description = "Foo field", example = "bar", requiredMode = NOT_REQUIRED)
private String foo;

@Schema(description = "Example field", requiredMode = REQUIRED)
private ExamplePayloadDto example;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.example.cloudstream.dtos;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

@Schema(description = "Example payload model")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExamplePayloadDto {
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED)
private String someString;

@Schema(description = "Some long field", example = "5")
private long someLong;

@Schema(description = "Some enum field", example = "FOO2", requiredMode = REQUIRED)
private ExampleEnum someEnum;

public enum ExampleEnum {
FOO1,
FOO2,
FOO3
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ spring.application.name=Springwolf example project - Cloud Stream
# Spring cloud configuration
spring.cloud.stream.kafka.streams.binder.applicationId=springwolf-cloud-stream-example
spring.kafka.bootstrap-servers=${BOOTSTRAP_SERVER:localhost:29092}
spring.cloud.stream.bindings.process-in-0.destination=input-topic
spring.cloud.stream.bindings.process-out-0.destination=output-topic
spring.cloud.stream.bindings.consumerMethod-in-0.destination=consumer-method-input-topic
spring.cloud.stream.bindings.process-in-0.destination=example-topic
spring.cloud.stream.bindings.process-out-0.destination=another-topic
spring.cloud.stream.bindings.consumerMethod-in-0.destination=another-topic


#########
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
}
},
"channels": {
"consumer-method-input-topic": {
"publish": {
"operationId": "consumer-method-input-topic_publish_consumerMethod",
"another-topic": {
"subscribe": {
"operationId": "another-topic_subscribe_process",
"description": "Auto-generated description",
"bindings": {
"kafka": { }
},
"message": {
"schemaFormat": "application/vnd.oai.openapi+json;version=3.0.0",
"name": "io.github.stavshamir.springwolf.example.cloudstream.payload.ConsumerPayload",
"title": "ConsumerPayload",
"name": "io.github.stavshamir.springwolf.example.cloudstream.dtos.AnotherPayloadDto",
"title": "AnotherPayloadDto",
"payload": {
"$ref": "#/components/schemas/ConsumerPayload"
"$ref": "#/components/schemas/AnotherPayloadDto"
},
"headers": {
"$ref": "#/components/schemas/HeadersNotDocumented"
Expand All @@ -43,23 +43,18 @@
}
}
},
"bindings": {
"kafka": { }
}
},
"input-topic": {
"publish": {
"operationId": "input-topic_publish_process",
"operationId": "another-topic_publish_consumerMethod",
"description": "Auto-generated description",
"bindings": {
"kafka": { }
},
"message": {
"schemaFormat": "application/vnd.oai.openapi+json;version=3.0.0",
"name": "io.github.stavshamir.springwolf.example.cloudstream.payload.InputPayload",
"title": "InputPayload",
"name": "io.github.stavshamir.springwolf.example.cloudstream.dtos.AnotherPayloadDto",
"title": "AnotherPayloadDto",
"payload": {
"$ref": "#/components/schemas/InputPayload"
"$ref": "#/components/schemas/AnotherPayloadDto"
},
"headers": {
"$ref": "#/components/schemas/HeadersNotDocumented"
Expand All @@ -73,19 +68,19 @@
"kafka": { }
}
},
"output-topic": {
"subscribe": {
"operationId": "output-topic_subscribe_process",
"example-topic": {
"publish": {
"operationId": "example-topic_publish_process",
"description": "Auto-generated description",
"bindings": {
"kafka": { }
},
"message": {
"schemaFormat": "application/vnd.oai.openapi+json;version=3.0.0",
"name": "io.github.stavshamir.springwolf.example.cloudstream.payload.OutputPayload",
"title": "OutputPayload",
"name": "io.github.stavshamir.springwolf.example.cloudstream.dtos.ExamplePayloadDto",
"title": "ExamplePayloadDto",
"payload": {
"$ref": "#/components/schemas/OutputPayload"
"$ref": "#/components/schemas/ExamplePayloadDto"
},
"headers": {
"$ref": "#/components/schemas/HeadersNotDocumented"
Expand All @@ -102,50 +97,48 @@
},
"components": {
"schemas": {
"ConsumerPayload": {
"type": "object",
"properties": {
"payloadString": {
"type": "string"
}
},
"example": {
"payloadString": "string"
}
},
"HeadersNotDocumented": {
"type": "object",
"properties": { },
"example": { }
},
"InputPayload": {
"AnotherPayloadDto": {
"required": [
"example"
],
"type": "object",
"properties": {
"bar": {
"type": "integer",
"format": "int32"
"example": {
"$ref": "#/components/schemas/ExamplePayloadDto"
},
"foo": {
"type": "array",
"items": {
"type": "string"
}
"type": "string",
"description": "Foo field",
"example": "bar"
}
},
"description": "Input payload model",
"description": "Another payload model",
"example": {
"bar": 0,
"foo": [
"string"
]
"example": {
"someEnum": "FOO2",
"someLong": 5,
"someString": "some string value"
},
"foo": "bar"
}
},
"OutputPayload": {
"ExamplePayloadDto": {
"required": [
"someEnum",
"someString"
],
"type": "object",
"properties": {
"someEnum": {
"type": "string",
"description": "Some enum field",
"example": "FOO2",
"enum": [
"FOO1",
"FOO2",
"FOO3"
]
},
"someLong": {
"type": "integer",
"description": "Some long field",
Expand All @@ -158,11 +151,17 @@
"example": "some string value"
}
},
"description": "Output payload model",
"description": "Example payload model",
"example": {
"someEnum": "FOO2",
"someLong": 5,
"someString": "some string value"
}
},
"HeadersNotDocumented": {
"type": "object",
"properties": { },
"example": { }
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
api project(":springwolf-core")

implementation "com.asyncapi:asyncapi-core:${asyncapiCoreVersion}"

implementation "org.slf4j:slf4j-api:${slf4jApiVersion}"

implementation "org.springframework:spring-context"
Expand Down
Loading

0 comments on commit 2b7dafe

Please sign in to comment.