Skip to content

Commit

Permalink
chore: Add Spring Boot example application
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzsimon committed Oct 1, 2023
1 parent 397f77c commit 11220dd
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>kotlin-asyncapi-examples</artifactId>
<groupId>org.openfolder</groupId>
<version>3.0.3-SNAPSHOT</version>
</parent>

<artifactId>kotlin-asyncapi-spring-boot-example</artifactId>
<packaging>jar</packaging>

<name>Kotlin AsyncAPI Spring Boot Example</name>
<description>Example for Kotlin AsyncAPI Spring Boot Application</description>

<properties>
<java.version>17</java.version>
<kotlin.version>1.8.22</kotlin.version>
<spring-boot.version>2.7.6</spring-boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.openfolder</groupId>
<artifactId>kotlin-asyncapi-spring-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<jvmTarget>17</jvmTarget>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.openfolder.kotlinasyncapi.example.spring

import org.openfolder.kotlinasyncapi.springweb.service.AsyncApiExtension
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
internal class AsyncApiConfiguration {

@Bean
fun asyncApiExtension() = AsyncApiExtension.builder {
info {
title("Gitter Streaming API")
version("1.0.0")
}
servers {
server("production") {
url("https://stream.gitter.im/v1")
protocol("https")
protocolVersion("1.1")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.openfolder.kotlinasyncapi.example.spring

import org.openfolder.kotlinasyncapi.annotation.channel.Message

@Message
data class ChatMessage(
val id: String,
val text: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.openfolder.kotlinasyncapi.example.spring

import org.openfolder.kotlinasyncapi.springweb.EnableAsyncApi
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
@EnableAsyncApi
class ExampleApplication

fun main(args: Array<String>) {
runApplication<ExampleApplication>(*args)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.openfolder.kotlinasyncapi.example.spring

import org.openfolder.kotlinasyncapi.annotation.Schema
import org.openfolder.kotlinasyncapi.annotation.channel.Channel
import org.openfolder.kotlinasyncapi.annotation.channel.Message
import org.openfolder.kotlinasyncapi.annotation.channel.Parameter
import org.openfolder.kotlinasyncapi.annotation.channel.Subscribe
import org.springframework.stereotype.Component

@Component
@Channel(
value = "/rooms/{roomId}",
parameters = [
Parameter(
value = "roomId",
schema = Schema(
type = "string",
examples = [""""53307860c3599d1de448e19d""""]
)
)
]
)
class RoomsChannel {

@Subscribe(
messages = [
Message(ChatMessage::class),
Message(
name = "heartbeat",
summary = "Its purpose is to keep the connection alive.",
payload = Schema(
type = "string",
enum = [""""\r\n""""],
),
),
]
)
fun publish(message: String): Nothing = TODO()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
asyncapi:
enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.demo

import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
class ExampleApplicationTests {

@Test
fun contextLoads() {
}

}
21 changes: 21 additions & 0 deletions kotlin-asyncapi-examples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>kotlin-asyncapi-parent</artifactId>
<groupId>org.openfolder</groupId>
<version>3.0.3-SNAPSHOT</version>
</parent>

<artifactId>kotlin-asyncapi-examples</artifactId>
<packaging>pom</packaging>

<name>Kotlin AsyncAPI Examples</name>
<description>Example applications for Kotlin AsyncAPI</description>

<modules>
<module>kotlin-asyncapi-spring-boot-example</module>
</modules>
</project>
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<module>kotlin-asyncapi-script</module>
<module>kotlin-asyncapi-maven-plugin</module>
<module>kotlin-asyncapi-annotation</module>
<module>kotlin-asyncapi-examples</module>
</modules>

<properties>
Expand Down

0 comments on commit 11220dd

Please sign in to comment.