-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split code into different microservices based on features: webmvc, jp…
…a, kafka.
- Loading branch information
Showing
29 changed files
with
267 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
rootProject.name = "spring-apps" | ||
|
||
include("spring-webmvc") | ||
include("spring-jpa") | ||
include("spring-cloud-stream-kafka") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
### new transaction | ||
POST http://127.0.0.1:8080/transactions HTTP/1.1 | ||
Content-Type: application/json | ||
|
||
{ | ||
"priority": 3, | ||
"accountNumber": "ACC-123456", | ||
"amount": 100, | ||
"description": "Test transaction" | ||
} |
11 changes: 11 additions & 0 deletions
11
...-stream-kafka/src/main/kotlin/com/vacuumlabs/example/SpringCloudStreamKafkaApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.vacuumlabs.example | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.runApplication | ||
|
||
@SpringBootApplication | ||
class SpringCloudStreamKafkaApplication | ||
|
||
fun main(args: Array<String>) { | ||
runApplication<SpringCloudStreamKafkaApplication>(*args) | ||
} |
16 changes: 9 additions & 7 deletions
16
...ing-cloud-stream-kafka/src/main/kotlin/com/vacuumlabs/example/kafka/KafkaConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
package com.vacuumlabs.example.kafka | ||
|
||
import com.vacuumlabs.example.db.MessageEntity | ||
import com.vacuumlabs.example.db.MessageRepository | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import java.util.function.Consumer | ||
|
||
@Configuration | ||
class KafkaConfiguration { | ||
val logger: Logger = LoggerFactory.getLogger(javaClass) | ||
|
||
@Bean("message-saver") | ||
fun messageSaver(messageRepository: MessageRepository) = | ||
Consumer<TransactionDto> { message -> | ||
if (message.accountNumber != "ACC-123456") { | ||
throw java.lang.IllegalArgumentException("Account doesn't exist: ${message.accountNumber}") | ||
fun messageSaver(transactionRepository: TransactionRepository) = | ||
Consumer<TransactionDto> { transaction -> | ||
if (transaction.accountNumber != "ACC-123456") { | ||
throw java.lang.IllegalArgumentException("Account doesn't exist: ${transaction.accountNumber}") | ||
} | ||
messageRepository.save(MessageEntity(id = null, message = message.description ?: "")) | ||
transactionRepository.save(transaction) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...-cloud-stream-kafka/src/main/kotlin/com/vacuumlabs/example/kafka/TransactionRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.vacuumlabs.example.kafka | ||
|
||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class TransactionRepository() { | ||
private val transactions = mutableListOf<TransactionDto>() | ||
|
||
fun save(transaction: TransactionDto) { | ||
transactions.add(transaction) | ||
} | ||
|
||
fun findAll(): List<TransactionDto> { | ||
return transactions | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
alias(libs.plugins.kotlin.jvm) | ||
alias(libs.plugins.kotlin.spring) | ||
alias(libs.plugins.kotlin.jpa) | ||
alias(libs.plugins.spring.boot) | ||
alias(libs.plugins.spring.dependency.management) | ||
alias(libs.plugins.ktlint) | ||
alias(libs.plugins.benmanes.versions) | ||
} | ||
|
||
group = "com.vacuumlabs.example" | ||
version = "0.0.1-SNAPSHOT" | ||
java.sourceCompatibility = JavaVersion.VERSION_17 | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(platform(libs.spring.cloud.dependencies)) | ||
|
||
implementation("org.springframework.boot:spring-boot-starter-actuator") | ||
implementation("org.springframework.boot:spring-boot-starter-data-jpa") | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") | ||
implementation("org.jetbrains.kotlin:kotlin-reflect") | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | ||
implementation(libs.logstash.logback.encoder) | ||
runtimeOnly("io.micrometer:micrometer-registry-prometheus") | ||
runtimeOnly("org.postgresql:postgresql") | ||
developmentOnly("org.springframework.boot:spring-boot-devtools") | ||
|
||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
testImplementation("org.springframework.boot:spring-boot-testcontainers") | ||
testImplementation("org.testcontainers:junit-jupiter") | ||
testImplementation("org.testcontainers:postgresql") | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
freeCompilerArgs = listOf("-Xjsr305=strict") | ||
jvmTarget = "17" | ||
} | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
postgres: | ||
image: postgres:14-alpine | ||
ports: | ||
- '5432:5432' | ||
environment: | ||
POSTGRES_DB: spring-example | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_HOST_AUTH_METHOD: trust |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
### get messages | ||
GET http://127.0.0.1:8080/messages HTTP/1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
spring-apps/spring-jpa/src/main/resources/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
management: | ||
endpoints: | ||
web: | ||
exposure: | ||
include: "*" | ||
endpoint: | ||
health: | ||
show-details: always | ||
probes: | ||
enabled: true | ||
|
||
spring: | ||
profiles: | ||
active: # json-logging | ||
application: | ||
name: spring-example | ||
datasource: | ||
url: jdbc:postgresql://localhost:5432/spring-example | ||
username: postgres | ||
password: postgres | ||
|
||
spring.jpa.hibernate.ddl-auto: create |
14 changes: 14 additions & 0 deletions
14
spring-apps/spring-jpa/src/main/resources/logback-spring.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<configuration> | ||
<springProfile name="default"> | ||
<include resource="org/springframework/boot/logging/logback/base.xml"/> | ||
</springProfile> | ||
|
||
<springProfile name="json-logging"> | ||
<appender name="jsonConsoleAppender" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/> | ||
</appender> | ||
<root level="INFO"> | ||
<appender-ref ref="jsonConsoleAppender"/> | ||
</root> | ||
</springProfile> | ||
</configuration> |
22 changes: 22 additions & 0 deletions
22
spring-apps/spring-jpa/src/test/kotlin/com/vacuumlabs/example/ContainerConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.vacuumlabs.example | ||
|
||
import org.springframework.boot.fromApplication | ||
import org.springframework.boot.test.context.TestConfiguration | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection | ||
import org.springframework.boot.with | ||
import org.springframework.context.annotation.Bean | ||
import org.testcontainers.containers.PostgreSQLContainer | ||
import org.testcontainers.utility.DockerImageName | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
class ContainerConfiguration { | ||
@Bean | ||
@ServiceConnection | ||
fun postgresContainer(): PostgreSQLContainer<*> { | ||
return PostgreSQLContainer(DockerImageName.parse("postgres:14-alpine")) | ||
} | ||
} | ||
|
||
fun main(args: Array<String>) { | ||
fromApplication<SpringJpaApplication>().with(ContainerConfiguration::class).run(*args) | ||
} |
File renamed without changes.
Oops, something went wrong.