Run in docker
This commit is contained in:
parent
98e4f36039
commit
3015e9b452
|
@ -0,0 +1,7 @@
|
|||
FROM gcr.io/distroless/java17:latest
|
||||
|
||||
COPY ./build/libs/chargepoint-0.0.1-SNAPSHOT.jar /usr/app/chargepoint.jar
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENTRYPOINT ["java","-jar","/usr/app/chargepoint.jar"]
|
|
@ -1,23 +1,57 @@
|
|||
version: '2'
|
||||
services:
|
||||
api:
|
||||
build: .
|
||||
container_name: chargepoint_transaction_api
|
||||
environment:
|
||||
- SPRING_KAFKA_BOOTSTRAP_SERVERS=kafka:29092
|
||||
- SPRING_PROFILES_ACTIVE=web-api,kafka-auth-client
|
||||
depends_on:
|
||||
- kafka
|
||||
- auth
|
||||
ports:
|
||||
- "8080:8080"
|
||||
networks:
|
||||
- chargepoint
|
||||
|
||||
auth:
|
||||
build: .
|
||||
container_name: chargepoint_transaction_auth
|
||||
environment:
|
||||
- SPRING_KAFKA_BOOTSTRAP_SERVERS=kafka:29092
|
||||
- SPRING_PROFILES_ACTIVE=kafka-auth-consumer
|
||||
depends_on:
|
||||
- kafka
|
||||
networks:
|
||||
- chargepoint
|
||||
|
||||
zookeeper:
|
||||
image: confluentinc/cp-zookeeper:7.4.4
|
||||
hostname: zookeeper
|
||||
environment:
|
||||
ZOOKEEPER_CLIENT_PORT: 2181
|
||||
ZOOKEEPER_TICK_TIME: 2000
|
||||
ports:
|
||||
- 22181:2181
|
||||
networks:
|
||||
- chargepoint
|
||||
|
||||
kafka:
|
||||
image: confluentinc/cp-kafka:7.4.4
|
||||
hostname: kafka
|
||||
depends_on:
|
||||
- zookeeper
|
||||
ports:
|
||||
- 29092:29092
|
||||
networks:
|
||||
- chargepoint
|
||||
environment:
|
||||
KAFKA_BROKER_ID: 1
|
||||
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
|
||||
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
|
||||
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://kafka:29092
|
||||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
|
||||
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
|
||||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
||||
networks:
|
||||
chargepoint:
|
||||
driver: bridge
|
||||
|
|
|
@ -16,10 +16,10 @@ typealias AuthProducerRecord = ProducerRecord<String, KafkaAuthRequest>
|
|||
class KafkaAuthService(
|
||||
val kafka: ReplyingAuthTemplate,
|
||||
) : AuthService {
|
||||
fun validateAsync(req: TransactionAuthRequest): CompletableFuture<ValidationResult> =
|
||||
private fun validateAsync(req: TransactionAuthRequest): CompletableFuture<ValidationResult> =
|
||||
CompletableFuture.supplyAsync { validateRequest(req) }
|
||||
|
||||
fun sendToKafka(req: TransactionAuthRequest): CompletableFuture<TransactionAuthResponse> =
|
||||
private fun sendToKafka(req: TransactionAuthRequest): CompletableFuture<TransactionAuthResponse> =
|
||||
AuthProducerRecord(KAFKA_AUTH_REQUESTS, KafkaAuthRequest(req)).let {
|
||||
kafka.sendAndReceive(it).thenApply { resp ->
|
||||
TransactionAuthResponse(resp.value())
|
||||
|
@ -29,7 +29,10 @@ class KafkaAuthService(
|
|||
override fun authorizeTransaction(req: TransactionAuthRequest): CompletableFuture<TransactionAuthResponse> =
|
||||
validateAsync(req).thenCompose { res ->
|
||||
res.fold(
|
||||
ifRight = { sendToKafka(it) },
|
||||
ifRight = {
|
||||
println("Determined that $it is valid")
|
||||
sendToKafka(it)
|
||||
},
|
||||
ifLeft = { CompletableFuture.supplyAsync { TransactionAuthResponse(AuthStatus.Invalid) } },
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package net.thermetics.chargepoint
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
|
||||
@SpringBootTest
|
||||
class ChargepointAssignmentTests {
|
||||
|
||||
@Test
|
||||
fun contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue