Skip to content

Instantly share code, notes, and snippets.

View schroedermatt's full-sized avatar

Matt Schroeder schroedermatt

View GitHub Profile
@schroedermatt
schroedermatt / build.gradle
Created August 8, 2018 21:34
snippet of the dependencies needed for integration testing with spring-kafka
repositories {
maven {
url "http://packages.confluent.io/maven/"
}
}
compile 'org.springframework.kafka:spring-kafka’
compile "org.apache.avro:avro”
compile "io.confluent:kafka-avro-serializer
testCompile 'org.springframework.kafka:spring-kafka-test'
@schroedermatt
schroedermatt / MockSerdeConfig.groovy
Last active August 9, 2018 02:37
bean configurations for using MockSchemaRegistryClient with @embeddedkafka
@Configuration
class MockSerdeConfig {
// KafkaProperties groups all properties prefixed with `spring.kafka`
private KafkaProperties props
MockSerdeConfig(KafkaProperties kafkaProperties) {
props = kafkaProperties
}
/**
* Mock schema registry bean used by Kafka Avro Serde since
@schroedermatt
schroedermatt / application.yml
Created August 8, 2018 21:33
integration test configuration
spring:
kafka:
# point the bootstrap servers to the running embedded kafka
bootstrap-servers: ${spring.embedded.kafka.brokers}
consumer:
client-id: test-avro-consumer
group-id: test-avro-group
value-deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
producer:
value-serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
@schroedermatt
schroedermatt / extension.kt
Created August 2, 2018 18:25
toStruct extension example
// extension on model from 3rd party library
fun ArtistModel.toStruct() : Struct = Struct(Artist.SCHEMA)
        .put(BaseSchema.HREF_FIELD, this.href)
        .put(BaseSchema.ID_FIELD, this.id)
        .put(BaseSchema.NAME_FIELD, this.name)
// example when creating list of SourceRecords from result set
val results: List<ArtistModel> = client.getResults()
results.map {
SourceRecord(partition, offset, topic, keySchema, it.id, valueSchema, it.toStruct())
@schroedermatt
schroedermatt / song.java
Last active August 2, 2018 18:42
java pojo vs kotlin data class
// kotlin data class (equals/hashcode/copy available)
data class Song (val name: String, val artist: Artist, var length: Int?)
// pojo with 1 of the Song properties for brevity (and no equals/hashcode)
public class Song {
private String name;
public Song(String name) {
this.name = name;
}
@schroedermatt
schroedermatt / TopicAdministrator.java
Last active July 24, 2018 19:59
Spring Kafka Config blog
@Configuration
public class TopicAdministrator {
private final TopicConfigurations configurations;
private final GenericWebApplicationContext context;
public TopicAdministrator(TopicConfigurations configurations, GenericWebApplicationContext genericContext) {
this.configurations = configurations;
this.context = genericContext;
}
@schroedermatt
schroedermatt / list-topics.sh
Created July 24, 2018 19:17
Spring Kafka Config blog
> bin/kafka-topics.sh --list --zookeeper localhost:2181
test-topic-1
test-topic-2
test-topic-3
@schroedermatt
schroedermatt / TopicConfigurations.java
Last active July 24, 2018 20:22
Spring Kafka Config blog
@Configuration
@ConfigurationProperties(prefix = "kafka")
class TopicConfigurations {
List<TopicConfiguration> topics;
static class TopicConfiguration {
String name;
Integer numPartitions = 3;
Short replicationFactor = 1;
@schroedermatt
schroedermatt / kafka-connect-docker-compose.yml
Last active June 22, 2018 13:01
Docker compose snippet showing the volume mount for local development of a Connector.
connect:
image: confluentinc/cp-kafka-connect:latest
volumes:
- ./build/libs:/usr/share/java/kafka-connect-plugin-name
@schroedermatt
schroedermatt / kafka-connect-build.gradle
Created June 21, 2018 17:16
Gradle build file for Kotlin Kafka Connector
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.jengelman.gradle.plugins:shadow:$shadow_version"
}
}
plugins {
id 'idea'
id 'com.palantir.git-version' version '0.5.2'