Skip to content

Instantly share code, notes, and snippets.

View ankitthakur's full-sized avatar

Ankit Thakur ankitthakur

View GitHub Profile
@ankitthakur
ankitthakur / Dockerfile
Created August 28, 2018 04:59
Docker file
FROM openjdk:8-jdk-alpine
EXPOSE 8080
ADD /build/libs/dockerdemo-0.0.1-SNAPSHOT.jar dockerdemo.jar
ENTRYPOINT ["java", "-jar", "dockerdemo.jar"]
@ankitthakur
ankitthakur / DockerController.kt
Created August 28, 2018 05:01
Basic Springboot based kotlin RestController
package com.thakur.dockerdemo.controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/docker/api")
class DockerController {
@RequestMapping("/")
@ankitthakur
ankitthakur / application.yaml
Created September 3, 2018 13:09
kafka stream binding as producer
spring:
cloud:
stream:
kafka:
binder:
brokers: localhost:9092 #kafkahost:kafkaport
bindings:
kafkatopic1: # this is particular topic, we will create in spring to create connection
destination: test # name of the topic
contentType: application/json # what sort of data, we want to send in message
@ankitthakur
ankitthakur / application.properties
Created September 3, 2018 13:15
spring kafka properties
# kafkahost:kafkaport
spring.cloud.stream.kafka.binder.brokers="localhost:9092"
# kafkatopic1 is the stream, will create, and the stream will get the destination or topic name from here
# test is the topic name
spring.cloud.stream.bindings.kafkatopic1.destination=test
# kafkatopic1 is the stream, where we will define in what sort, we will send data
spring.cloud.stream.bindings.kafkatopic1.content-type=application/json
@ankitthakur
ankitthakur / KafkaServerStreams.kt
Last active September 3, 2018 13:31
Kafka Producer stream interface, which will be used to write to the topic
package com.thakur.kafkaserver.config
import org.springframework.cloud.stream.annotation.Output
import org.springframework.messaging.MessageChannel
interface KafkaServerStreams {
@Output(PRODUCER_STREAM)
fun producerChannel(): MessageChannel
@ankitthakur
ankitthakur / StreamsConfig.kt
Created September 3, 2018 13:32
Kafka Stream class, which will be used to configure Kafka Streams and bind it to the topic
package com.thakur.kafkaserver.config
import org.springframework.cloud.stream.annotation.EnableBinding
@EnableBinding(KafkaServerStreams::class)
class StreamsConfig
@ankitthakur
ankitthakur / Person.kt
Created September 3, 2018 13:35
Kotlin based model object using lombok
package com.thakur.kafkaserver.model
import lombok.Getter
import lombok.Setter
import lombok.ToString
@Getter
@Setter
@ToString
data class Person(
@ankitthakur
ankitthakur / KafkaService.kt
Created September 3, 2018 13:41
Kafka Service class which will use Kafka Stream to send message as producer
package com.thakur.kafkaserver.service
import com.thakur.kafkaserver.config.KafkaServerStreams
import com.thakur.kafkaserver.model.Person
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.messaging.MessageHeaders
import org.springframework.messaging.support.MessageBuilder
import org.springframework.stereotype.Service
import org.springframework.util.MimeTypeUtils
@ankitthakur
ankitthakur / KafkaRestController.kt
Created September 3, 2018 13:46
Rest Controller
package com.thakur.kafkaserver.restcontroller
import com.thakur.kafkaserver.model.Person
import com.thakur.kafkaserver.service.KafkaService
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import java.util.*
@ankitthakur
ankitthakur / application.yaml
Created September 6, 2018 05:42
kafka consumer yml file
spring:
cloud:
stream:
kafka:
binder:
brokers: localhost:9092
spring.kafka.topic: test
spring.kafka.topic.groupId: testgroup