This file contains hidden or 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
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' |
This file contains hidden or 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
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 { |
This file contains hidden or 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
// ...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() |
This file contains hidden or 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 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(), |
This file contains hidden or 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
//...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) | |
} | |
} |
This file contains hidden or 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
//...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}") |