Archive by Author | martincx

Downtown Quito

If I had to suggest a place to visit while touring in Ecuador I would advise you to go downtown Quito. Although San Francisco de Quito, Ecuador’s capital city has grown as a vibrant metropolis with modern buildings and neighborhoods, what truly pays the visit of this city is its lovely colonial district (Centro Histórico).  Hundreds of well-preserved buildings and churches of the Spanish Empire era can be found in this area. While walking through its narrow cobblestone streets you will feel like traveling back in time. Visiting the Church of «Compañia de Jesús» is a must. This magnificent church is one of the best examples of Baroque of Quito style being its most representative features the church’s volcanic rock facade and the imposing gold leaf details of its interior. It is, without a doubt Quito’s crown jewel, a place where the spirituality of its people meets the splendor of a long bygone era.


Setting up a project for Testing with Selenium WebDriver


  • Java 8+
  • IDE: Eclipse.
  • Apache Maven
  1. Create a Maven project with the option skip archetype selection.
  2. Add dependencies(selenium-java and TestNG* -can be replaced by JUnit-) to pom.xml. (hint can be found at
  3. Create a TestNG class in src/test.
  4. Execute test.

Get TestNG eclipse plugin here:

Do not forget to Download the Driver for your Browser (Chrome, although support for other exist)


Reactive ScalaJdbc with Flyway Play

  1. Postgres Driver /
  2. Flyway to add reactive non-blocking: flyway/flyway-play (play 2.4 +)/
  3. Scalikejdbc-async here
  4. Edit conf/application.conf add
play.modules.enabled += ""
  1. postgresql-async (More and in depth analysis here)

Add in conf/application.conf

play.modules.enabled += ""


# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`


# ScalikeJDBC original configuration

play.modules.enabled += "scalikejdbc.PlayModule"


  1. Implement SuperMail model
  2. Create REST endpoints
  3. Add to routes
GET        /bars:username                   controllers.Application.getSuperMails(username: String)
POST       /bars                   controllers.Application.createSuperMail


  1. Implement Controller
  2. Test

Original reactive post here.

More details to handle request here (Official lightbend)

Play + Scalikejdbc +Postgres

Create a new project from scala seed

sbt new playframework/play-scala-seed.g8


Import in IntelliJ IDEA.

Open build.sbt and add:


Open conf/application.conf

Add as following


In plugin.sbt add the following


And enable the reverse plugin at build.sbt


Create a configuration file in project/


This configuration will allow us to create a model from existing db tables. Next step is to go a terminal (In IntelliJ IDEA there is a Terminal access on the botton, next to sbt terminal) in the root directory of your project and execute:

sbt "scalikejdbcGen messages Messages"

If all configurations are correct you will get a result like this:



After that a models package containing a Messages case class with the implementation of methods for CRUD are created in our project.

However the automation provided is awesome for this type of examples, since our table has a serial id we need to change the signature of our case class to exclude the id and to implement the date automatically (not provided by)

Vagrant Lab for Postgres

Since a few days ago I’ve played (wink, wink) with Play, Lagom and Reactive Systems, I’ve found in the need of trying Some Scala  and implement a REST API to access a Postgres Database, so instead of downloading, installing and configuring a database in my local machine I’ve felt tempted to use Vagrant instead.

Vagrant you say?

Vagrant is a tool for building and managing virtual machine environments in a single workflow. This tools “packages” our special box which is a small VM. A remarkable aspect is Vagrant relies on “providers” for virtualization. In this case, we’ll proceed first to install both Vagrant AND Virtualbox.

The beauty of Vagrant is that several boxes with preconfigured OSs, tools and services are ready to be implemented. Just search here for a Vagrant box of your needs.


  • Vagrant.
  • VirtualBox
sudo apt install virtualbox-qt
sudo apt install vagrant

Let’s get to it!

Get Postgres Vagrant box.

Open a Terminal. Create a directory in which you will download and place your Vagrant Machine.


The previous image comprises the following actions we have performed:

  1. Create a Postgres_Vagrant directory
  2. Download our Vagrant box.
  3. Open Vagranfile for this box.

Uncomment the following line of Vagrantfile "private_network", ip: ""

Add "forwarded_port", guest: 5432, host: 5432, host_ip: ""

Save and close the Vagrantfile. Go back to your terminal and execute

vagrant up

This command will start the vm for this exercise.

Now we open VirtualBox and effectively our vm is ready.


El pase de diapositivas requiere JavaScript.

That’s all! Now we can focus our effort on building our REST API to access a database, but that’s for another day).


Since I’m now in Russia, the Postgresql locale was set to «ru_RU.UTF-8», but it’s necessary to change it to support locale to match my language «en_US.UTF-8».


Change it like this


Thanks faqforge!

Reactive System (and 3)

This tutorial starts here and the second part continues here. Do not forget to start at the beginning.

Part VI: Create a simple frontend App for our System.

  1. Create a new Scala module (microservice) for our project.
  2. Create the package.
  3. Create model WFForm
  4. Implement controllers.
    1. create package controllers
    2. create WFAbstractController
    3. WFConsumerController
    4. WFController

To be continued…

WF Reactive System (2)

In previous post (available here.) we gave a try to Lagom and reactive microservices. We started by creating a sample Weather forecast App with three reactive microservices. Starting by the preparation and setup of tools needed, and the creation of service API and its implementation for the producer service that will deal with request that User will generate from a future UI (We’ll have the chance of play with Play framework).

In this  part, we’ll create a consumer API and its implementation.

Part IV: Consumer API

  1. Open the project in the IDE and create a copy of the producer module and rename it as wf-consumer-api.
  2. Add this module to build.sbt.
  3. Go to model and refactor (rename):
    1. WFMessage to WeatherForecasting.
  4. Modify the Service API:
    1. Remove topic
    2. Change descriptor name to «wfconsumer».
    3. Define functions to:
      1. Get Top Ten Weather Forecasts.
      2. Get one (the first) Weather Forecast. (findOneWFData)
      3. Get the latest Weather Forecast. (latestWF)
    4. Define the rest endpoints URI in descriptor to our consumer.
      1. Get for (findTopTenWFData)
      2. Get for (latestWF)
      3. Get for (latestWF)
    5. Remove the withTopics and withAutoAcl options of descriptor.

Part V: Implementing the Consumer Services

  1. Create model package and create the case class WeatherForecasting.
  2. Create companion object for Json serialization format.
  3. Modify the consumer’s WFCommand
    1. Extend ReplyType[T] (previously [Done])
    2. Create SaveNewWF case class and its companion object.
    3. Delete WF case class and its companion object.
    4. Rename WFSerializerRegistry to WFConsumerSerializerRegistry
    5. Add class to WFSerializerRegistry.
    6. EventTag does not require modification.
    7. Modify WFEvent. Refactor WFChanged to WFSaved and change its signature to receive a WeatherForecast object as parameter.
    8. Remove onReadOnlyCommand
    9. In onEvent change case and add message for detail of message.
    10. Modify WFEntity to implement saving messages to handle onCommand and on Event operations for all WFEvents. It is very important to note that this Entity manages components of CQRS/ES architecture.
    11. Modify WFLoader.
      1. Rename it to WFConsumerLoader
      2. Override load and loadDEvMode.
      3. Change abstract class WFConsumerApplication
      4. Add lazy vals for binding WFService client wfService and message repository (WFRepository).
      5. Override jsonSerializerRegistry.
      6. Add persistentEntityRegistry
      7. Add readSide.register(wire[WFEventProcessor])
    12. Implement WFRepository.
      1. Create package repositories.
      2. Create private [impl] class WFRepository its constructor receives CassandraSession.
      3. Implement method for data fetching according to rest endpoints:
        1. fetchWFData: to retrieve 10 elements
        2. fetchOneWFData: to retrieve one (first) register.
    13. Implement Consumer Service
      1. Create class WFConsumerServiceImpl.
      2. Override findTopTenWFData and findOneWFData
    14. change Loader in resources/application.conf
    15. Add binds to build.sbt.

In the next post, we’ll create a simple frontend for our Reactive System.

WF Reactive System (1)


  • Java 8
  • Scala
  • sbt
  • IntelliJ IDEA

Part I: Preparation from Template

Create new lagom project from template.

sbt new lagom/lagom-scala.g8

  1. Import project into IDE.
  2. Refactor project-name-API to create producer API and IMPL.
    1. rename folder wfproducer-API.
    2. Rename module wfproducer-API.
    3. Change new names in build.sbt lazy vals and bindings. Note: at this point you can remove lazy vals of stream services API and its implementation created by lagom template.
  3. Test by runAll. If you’ve done changes correct it’ll run.
    1. Go to: http://localhost:9000/api/hello/Martin

Part II: Define a Producer Service API

  1. Delete stream-api and stream-impl services. Do not forget to remove their references (lazy val) from build.sbt
  2. Since we’re building a reactive Weather forecast system we’ll handle user events on wf-producer service.
  3. Rename wfreactiveService Scala class of wf-producer-API service. Take into consideration that a service API is an interface that in scala is declared with a trait, so make sure to rename using IDE’s refactor capabilities in order to keep consistency and find usages on other scala files.
  4. Extract model from service api implementation.
    1. Create model package inside api.
    2. Move class to the new model package.
    3. Rename class and its companion object to WFMessage.
  5. Open WFService.
    1. Change the topic to wfTemperature.
    2. Change signature of wfTemperature.
    3. Remove other functions definition.
    4. Rename greetingsTopic function to wfTopic and its signature.
    5. Include pathCall to wfTemperature in descriptor.
    6. Remove the addProperty Kafka part.
    7. Delete case class GreetingMessageChanged part.

Part III: Define a Producer Service Implementation (impl)

  1. Producer commands Creation:
    1. Sealed trait WFCommand
    2. UseWFMessage
    3. WF
  2. Create companion objects for commands
  3. Create Serialized registry. Add all command case classes.
  4. Create system events:
    1. (sealed trait) WFEvent
    2. WFChanged
  5. Create Event Tag (WFEventTag) for Service.
  6. Add system events case classes to Serialized registry.
  7. Create WFState
  8. Add WFState to Serialized registry.
  9. Modify WfreactiveEntity.
    1. Rename it to WFEntity.
    2. Change Initial State
  10. Implement WFLoader
    1. Rename it to WFLoader
    2. override lazy val jsonSerializerRegistry = WFSerializerRegistry
  11. Implement WFServiceImpl
  12. Change in application.conf values of Loader

play.application.loader = com.example.wfreactive.impl.WFLoader

(This is a guide, a draft, will be completed with images soon)