Skip to content

Instantly share code, notes, and snippets.

Michael Stöckli mchlstckl

Block or report user

Report or block mchlstckl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mchlstckl
mchlstckl / ProfileController.kt
Last active Jan 7, 2016
Async Reactive operation with fallback observable
View ProfileController.kt
//...elided package, class and imports...//
@RequestMapping("/profiles", method = arrayOf(RequestMethod.GET))
fun getUserByEmail(
@RequestParam(value = "email") email: String,
): DeferredResult<ResponseEntity<Profile>> {
val result = DeferredResult<ResponseEntity<Profile>>()
val uriBuilder = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{uuid}")
@mchlstckl
mchlstckl / UserService.kt
Last active Jan 7, 2016
HystrixCommand returning Observable
View UserService.kt
//...elided code...//
@HystrixCommand(/* ...some very advanced hystrix configurations here... */)
open fun fetchUser(email: String): Observable<User> {
// MUST return ObservableResult when using @HystrixCommand and Observable<T>
// See: https://github.com/Netflix/Hystrix/issues/729
return object : ObservableResult<User>() {
override fun invoke() = client.fetchUser(email)
}
}
@mchlstckl
mchlstckl / Property.kt
Last active Jul 31, 2019
Example entity with composite key Spring Boot and Kotlin
View Property.kt
// This will not serialize!
data class Muppet(val name: String)
// This will serialize!
data class Puppet(val name: String = "")
// Composite key class must implement Serializable
// and have defaults.
class PropertyId(
val uuid: UUID = UUID.randomUUID(),
@mchlstckl
mchlstckl / ProfileController.kt
Last active Jan 7, 2016
Example logging with Kotlin
View ProfileController.kt
// ...elided package and imports... //
import com.example.profileservice.logging.logger
@RestController
class ProfileController @Autowired constructor(
val profileRepository: ProfileRepository
) {
// This is how you create a logger
val log = logger()
@mchlstckl
mchlstckl / Logging.kt
Created Jan 7, 2016
Log helper file for Kotlin
View Logging.kt
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import kotlin.reflect.KClass
// Based on answer by Jayson Minard on Stack Oveflow question
// "Idiomatic logging for Kotlin"
// See: http://stackoverflow.com/questions/34416869
// Return logger for Java class, if companion object fix the name
public fun <T : Any> logger(forClass: Class<T>): Logger {
@mchlstckl
mchlstckl / build.gradle
Created Jan 7, 2016
Example build.gradle file for Spring Boot with Kotlin
View build.gradle
group 'com.example.profile'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.0.0-beta-3595'
ext.spring_boot_version = '1.3.1.RELEASE'
ext.spring_dmp_version = '0.5.2.RELEASE'
ext.spring_cloud_netflix_version = '1.0.4.RELEASE'
ext.rx_kotlin_version = '0.30.1'
You can’t perform that action at this time.