Version 0.10.0 is live with Docker Compose and views counter

As some of you may be aware, for the last year I am working on a pet project called JVM Bloggers with a goal to popularize blogging and knowledge sharing in the Polish Java developers community. We send a weekly summary with new blog posts and new videos published in the last 7 days.

During last few weeks two major changes were added to the project:

  • deployment is done using Docker Compose
  • All clicks are going through the application so we can gather some statistics

Docker Compose

Previously application was deployed using two separate Dockers, that was the easier approach to get things going but as we are moving to microservices architecture I knew that Docker Compose will be a good choice allowing us to easily add more and more elements to our system. First, docker-compose.yml needs to be created with two services: jvm_bloggers_db and jvm-bloggers-core:

In jvm_bloggers_db we have some parameters that allows to customize PostgreSQL image, besides most obvious ones like database name, user and password there are also:

  • $JVM_BLOGGERS_DB_PUBLISHED_PORT – port on which our database will be available from external (like developer’s machine)
  • $JVM_BLOGGERS_DB_PATH – path to a directory where database files are located on our server

jvm-bloggers-core is more complicated:

  • environment variables specifies Spring profile and master password used to encrypt properties like API keys, password to admin panel, etc.
  • $JVM_BLOGGERS_CORE_PORT – port on which application is available, on production it is obviously 80, but locally it can be different
  • link jvm_bloggers_db allows us to use this as a url to the database in spring.datasource.url with value jdbc:postgresql://jvm_bloggers_db:5432/jvm_bloggers_prod without worrying where exactly database container is running in our internal network.

Next to docker-compose file we need a bash script to start/stop our system:

Main part of this file consists of multiple exports that enable customization of docker-compose so it can be used without changes locally and on production. Then we have simple commands to launch, shutdown and check status of running services. And that’s all, now we can use following command to launch all services:

Views counter

Next feature released with 0.10.0 version is views counter. I wanted to have some insight into how many people use JVM Bloggers and, most importantly, what are the most popular entries. In next weeks we plan to add section with most popular posts from last month so authors of most valuable content could get extra recognition.

To add this feature following things were required:

  1. Redirect controller
  2. Migration from UUID as a unique blog post identifier to something shorter
  3. Logic to store clicks in the database

Job of Redirect Controller is very simple – get UID from the url parameter (e.g. http://jvm-bloggers.com/r/wx1LivZ) and redirect user to proper blog post. But before 0.10.0 UID was a full

so instead of a nice and short link we had something like http://jvm-bloggers.com/r/b877a837-4f5b-4a0b-90b2-981c83c1366e, not very friendly and concise. Simple data migration was necessary and in a new approach UID is compact 7-chars length String:

The last thing we needed was a logic to save clicks. I didn’t want to make a redirection slower only because we are storing something in the database so I decided to use Akka to handle this work in a separate thread.

In RedirectController we publish SingleClick event:

and actors simply handles this event by persisting Click entity:

 

Credits

These new features wouldn’t be possible without contributors, most notably Mateusz Urbański and Marcin Kłopotek.

Summary

JVM Bloggers is still evolving with both small changes and major new features, so if you want to help please contact me or join our gitterchannel. We have Java8, Spring Boot, Docker, Akka on board and plenty of ideas to implement (even using different languages).

For more details you should visit our GitHub repository.