Microservices with Spring Boot, Netflix Zuul, Kotlin, Docker and MongoDB

Recently I’ve started playing with Kotlin programming language, and wanted to give it a try.

Kotlin gives us possibility to write quite concise code, such as:

@RestController
class UsersController(val userRepo: UserRepository) {

    @ResponseStatus(HttpStatus.OK)
    @GetMapping("/users/{userId}")
    fun getUser(@PathVariable userId: String): UserDTO {
        return userRepo.findOne(userId).toUserDTO()
    }
}

You can find and download source code from GitHub. Readme file there explains how to start & use services. docker-compose comes quite handy to start / shutdown all the services with simple commands and orchestrate them via docker-compose yaml configuration file.

I’ve built sample, small microservice, composed of some kind of simple api-gateway or proxy server, implemented using Spring Boot and Netflix Zuul library for proxying requests to downstream servers.

Continue reading

Using regular expressions for querying MongoDB documents

Ladies and gents, here’s one fairly short hint for anyone wondering how to query documents in mongodb using regular expressions. Let’s get straight to the point:

Let’s start by inserting couple of documents (using mongodb shell) which we’ll use for querying afterwards:

db.developers.insertMany([
    { "name" : "John", "languages" : ["java", "php", "javascript"] },
    { "name" : "Johnny", "languages" : ["java", "c", "c++"] },
    { "name" : "Jim", "languages" : ["node", "java"] }
]);

Continue reading

Querying Mongo documents for array properties

Ladies and gents, I’m just posting one short reminder to myself and anyone keen to find out how do we query array type fields in mongodb.

Let’s start by inserting couple of documents (using mongodb shell) which we’ll use for querying afterwards:

db.developers.insertMany([
    { "name" : "John", "languages" : ["java", "php", "javascript"] },
    { "name" : "Jack", "languages" : ["java", "c", "c++"] },
    { "name" : "Jim", "languages" : ["node", "java"] }
]);

Continue reading