Vertx, Guice and Config Retriever: Dependency Injection in Vertx 4.x

In computer science, dependency injection is defined as a pattern, whereby one component gets other components (dependencies) from outside. Numerous posts were written about various implementations of dependency injection in Vertx using the Google Guice library. All of them are good and I do not want to reinvent a bicycle here and repeat the same things again. However, in my opinion, it is a good idea to give a bit more systematic approach to this topic. In my experience, in most cases, for developers is not a big deal to implement a basic DI with Vertx, rather it seems hard to incorporate Vertx components into the DI pipeline. In this post, we will review how to do dependency injection in Vertx with Google Guice and how to build a basic injection that has the ConfigRetriever component (Vertx’s way to obtain an application configuration). Please note, that in this article we use Futures API, so it is focused on Vertx 4.x developers.

Basic DI with Google Guice

Google Guice is an established solution to implement a dependency injection technique in Java applications. Like most established libraries, it is quite simple to use, yet it does not mean that it is limited in any way. This is a very flexible and powerful solution. The main building blocks of the framework are modules and injectors. The module is used to define how to get dependencies. The injector serves as a main entry point of an application and is used for an actual component initialization. Let have a quick example, that uses a constructor injection technique. Imagine, that you develop a verticle, that has two external dependencies — a client class (that performed HTTP calls) and a repository class (that does database operations). For sure, we will not do here their precise implementations, because it is out of the scope of the post. In order to specify these dependencies classes inside the verticle, we need to use an @Inject annotation. If you are familiar with the Spring framework, you would find a process familiar. Basically, we need to create fields to keep references for components, define a constructor and annotate it with the @Inject, so Guice will know that we use constructor injection.

Spring Cloud Stream Channel Interceptor

Introduction

A Channel Interceptor is a means to capture a message before being sent or received in order to view it or modify it. The channel interceptor allows having a structured code when we want to add extra message processing or embed additional data that are basically related to a technical aspect without affecting the business code.

The Message Interceptor is used in frameworks like Spring Cloud Sleuth and Spring Security to propagate tracing and security context through message queue by adding headers to message in the producer part, then reading them and restoring the context in the consumer part.

Micronaut Mastery: Change the Default Package for Generated Classes

When we use the Micronaut command line commands to generate controllers, beans, and more, the classes will have a default package name. We can use a fully qualified package name for the class we want to generate, but when we only define a class name, Micronaut will use a default package name automatically. We can set the default package for an application when we first create an application with the create-app command. But we can also alter the default package name for an existing Micronaut application.

To set the default package name when we create a new application we must include the package name in our application name. For example when we want to use the default package name mrhaki.micronaut for an application that is called book-service we must use the following create-app command:

Consistency Through Compensation in Microservices

This article addresses the eventual consistency aspect of transactions in a microservices environment where a transaction spans more than one microservice and where transaction failure midway through is imminent.

Existing Business Use Case

Suppose that we currently have a monolithic order management system that is backed by an RDBMS.

Contract Testing in HL Tech With Judge Dredd, Part 2

Welcome back! If you missed Part 1, you can check it out here

Consumer Expectations

Consumer expectations are expressed in Pact format. Pact format specifies sample interactions between a consumer and its provider. All interactions between them must be described separately with sample values, which can be later validated against a Swagger file. In Picture 6, a sample Pact file is presented which was generated based on Judge Dredd Agent.

TechDays 2019: Microservices for Building an IDE and the Innards of JetBrains Rider

The nice folks of TechDays Finland provided me with the opportunity to speak about Microservices for building an IDE - The innards of JetBrains Rider. It was nice to be able to talk about some of the internals, architecture and design decisions that were made while building a .NET IDE - Rider.

If you’re interested in the slides, find them below. This story is also available as an article on CODE Magazine: Building a .NET IDE with JetBrains Rider.

Improve Microservice Testing With Contract Testing

Today, it is strange to find a system built in a "monolithic" way. It is becoming more common, because of the advantages that this involves, to divide it into smaller components that communicate with each other to meet the expected needs.

This means that the functionality is not concentrated in a single point, but it is the collaboration of all the parties that gives meaning to the system.

Easily Build and Run Unikernels With OPS

Unikernels have long been touted as the next generation of cloud infrastructure for their size, security, and performance — aspects that lend themselves to megatrends like microservices and serverless while combating the non-stop onslaught of data breaches, cryptojacking, and other problems.

There's a big problem though. There has been very little developer pickup. Some of those outside the ecosystem have pointed their fingers at fake problems like a lack of debugging but that simply isn't the reason. For instance, everyone I know that uses unikernels heavily utilizes gdb.

An Introduction to Microservices With Undertow

Introducing Undertow

This is a series of articles trying to cover a powerful and yet an uncommon Java-based NIO server called Undertow. Over the sequence of these articles, I’ll try to cover what Undertow is and how you can leverage it to build a full-featured Java-based production quality network service that provides a REST-based interface and supports modern messaging systems such as Kafka. These articles will purposefully avoid topics on using Servlet APIs, as Undertow follows a simple programming model based around a single abstract interface (SAM) called HttpHandler.

Litany of Distributed Computing Concepts in Java

If you’ve been building Java-based distributed systems, then you’d agree that no other platform has seen so many techniques of building distributed systems as Java has. In fact, most Java developers have used more than a couple of the following programming models for building such systems:

React, Redux and Saga: Connecting the Dots

"Viewer discretion advised." This article is written by a person who is very new to front-end programming with React and worked on backend development for a number of years. I’m quite fascinated, however, by UI recently, since UI libraries are adopting some of the distributed computing theories/features used in middleware applications.

If you have worked with Angular, passing state within components is not as clean as you would have liked. In my personal opinion, React handled the situation quite delicately using React-Redux, a centralized big static state object, which was shared within the whole application, and react-saga, a library which handles the application side effects, e.g. asynchronous actions. In this tutorial, we will build a React application which uses the Redux and the saga pattern. 

HTTP Forwarded and X-Forwarded-* Header Support: Dev Build Update

HTTP Forwarded and X-Forwarded-* header support means that programmers and applications can obtain the original client endpoint information presented by a proxy or a load balancer using the Forwarded or X-Forwarded-* headers instead of the current TCP connected endpoint. This information can be retrieved using certain Servlet API calls or the NCSA Access Log.

You can use the Forwarded and X-Forwarded-* headers by configuring a new element in the server.xml. Optionally, you can provide a regular expression that declares the internal/trusted proxy servers. In addition, you can optionally configure a Boolean type attribute that, if the HTTP Channel has verified the specific remote client information, the NCSA Access Log reflects the Forwarded and X-Forwarded-* headers when recording the remote IP, host, and/or the request protocol.

Lagom Scheduler Service Using SBT

We know how to write a Scheduler and how to take work from it, already. We also have an idea how to start it, just give it in the starting point of the program and it will start. You may also know how to do it when we are using Lagom to create microservices, but I didn't. I struggled to start this scheduler using AbstractModule and asEagerSingleton but it didn't work. Then I researched a lot on the internet, and yet still had no success.

Then I discussed it with a friend and he came up with this beautiful keyword — wire. And that's it — it's done. Let me give you some insights of what I was trying and what solved my problem, so that if someone in your life gets stuck on a similar problem, you can be that friend to them.