Thursday, October 29, 2015

Exploring CQRS with Axon Framework: Applying Event Sourcing

This post is part of the series of post on exploring CQRS architecture using Axon Framework. It looks into combining event sourcing within CQRS using Axon Framework.

The previous posts in this series has explored the various components of a CQRS application and in Introducing Domain Events and Event Handling, we are able to put everything together. We did all that without bringing in event sourcing, showing that it is possible to have a CQRS architecture easily without introducing event sourcing. But in this post, we do just that: introduce event sourcing.

There is a project on Github (exploringCQRSwithAxon) that accompanies these series of posts. It is a trivial application where we can perform debiting, crediting and transferring of money between two dummy accounts. The code in the project is meant to help illustrate the application of the Axon framework to building CQRS application.


Saturday, October 17, 2015

Exploring CQRS with Axon Framework: Introducing Domain Events and Event Handling

This is a post in a series of posts that explores the CQRS architecture with Axon Framework. It is recommended to read the previous posts in this series before going ahead with this one, as that would help in forming a thread of continuity around the topic being discussed. You can start from Exploring CQRS Architecture with Axon Framework: Introduction

There is a Github project (exploringCQRSwithAxon) that contains a simple application that accompanies the posts in this series. it is an illustrative application that allows debiting, crediting and transferring money between two fictitious accounts. It is obvious a trivial application, which is on purpose. It’s aim is not to capture any complex domain but to help illustrates the various components of a CQRS architecture and how the Axon Framework can be used to build these various components.


Tuesday, October 13, 2015

Exploring CQRS with Axon Framework: Building the Entity, Aggregate, Aggregate Root and Repository Components

The previous post provided a basic explanation of Entity, Aggregate, Aggregate Root, Repository and Domain Events which are some of the building blocks in Domain Driven Design. This post looks at using Axon Framework to create some of these building blocks.

In Exploring the Commands, Command Bus and Command Handler, we looked at the command handling aspect of CQRS using Axon, where we had commands created, that were dispatched into a command bus via a command gateway which were then subsequently handled by their respective command handlers.

But in that post, all what the command handlers did was to print to the console. In real life applications, you would want the commands to lead to some business logic being executed, which might lead to state change in the application.

Achieving that, is what we look into in this post.


Monday, October 12, 2015

Exploring CQRS with Axon Framework: Overview of Some DDD Concepts

In Exploring the Commands, Command Bus and Command Handler, we looked at the command handling aspect of CQRS using Axon. We created commands that were dispatched into a command bus via a command gateway, which were then subsequently handled by their respective command handlers.

But in that post, all the command handlers did was to print to the console. In real life applications, you would want the commands to lead to state change within your application. Achieving this is what we look into next, but for us to do that, we would first need to explore some concepts that stem from the Domain Driven Design world. Namely Entities, Aggregates, Aggregate Roots, Repositories and Domain Events.

At this junction, it is worth mentioning that concepts and ideas from DDD always pop up in a typical CQRS discussion...this post and others in the series are not an exception, therefore, at least a basic understanding of these DDD concepts will be beneficiary.

This post will provide a quick overview of the relevant DDD concepts without touching on Axon Framework, while the next post will look at how Axon is used for their implementation.

That been said, let us quickly have an overview of the relevant DDD concepts that we will be needing in our exploration of CQRS with the Axon Framework.


Saturday, October 03, 2015

Exploring CQRS with Axon Framework: The Command, Command Bus and Command Handling Components

In this post we look at how to use Axon Framework to build out the command handling parts in a CQRS application.

It is part of a series of post that explores CQRS with Axon Framework.

As stated in the introductory post, these series of post is accompanied by the exploringCQRSwithAxon  project on Github. The project is a trivial application that simulates two bank accounts. It will support debiting, crediting and transfer between these two accounts. It is intended to help illustrate the features discussed as we explore how Axon Framework can be used to build application following CQRS stipulations.

The sample application is built with Axon Framework and Spring Boot. It uses the 2.4.1 version of Axon Framework, as you will notice in the Pom.xml

<dependency>
   <groupId>org.axonframework</groupId>
   <artifactId>axon-core</artifactId>
   <version>2.4.1</version>
  </dependency>
  <dependency>
   <groupId>org.axonframework</groupId>
   <artifactId>axon-test</artifactId>
   <version>2.4.1</version>
   <scope>test</scope>
  </dependency>

For the purpose of this series we would be using only the axon-core and axon-test modules.


Exploring CQRS Architecture with Axon Framework: Introduction

This is a first post in a series of posts that explores the CQRS architecture with Axon Framework.

The aim is to first understand what CQRS is from a conceptual/architectural standpoint and then explore what building blocks the Axon Framework provides that can help in building applications following the CQRS pattern.

The posts in this series include:
  1. Exploring CQRS with Axon Framework: The Command, Command Bus and Command Handling Components
  2. Exploring CQRS with Axon Framework: Overview of Some DDD concepts: Entity.
  3. Exploring CQRS with Axon Framework: Building the Entity, Aggregate, Aggregate Root and Repository components
  4. Exploring CQRS with Axon Framework: Introducing Domain Events and Event Handling.
  5. Exploring CQRS with Axon Framework: Applying Event Sourcing.
  6. Exploring CQRS with Axon Framework: Overview of the Testing infrastructure.
  7. Exploring CQRS with Axon Framework: Closing thoughts.


Friday, October 02, 2015

Exploring Architectures

I would be spending some time in the next couple of days/weeks/months, exploring software architectures.

Software Architecture is obviously a very broad subject to contemplate. It could also be an ambiguous one. So I am going to exploit this ambiguity and broadness and limit my exploration only to activities which piques my interest (:p) meaning what my exploration will be mostly concerned with the development/deploying side of things (nothing on analysis, requirement engineering etc)

Why do this? Two main personal motivation.

There are a lot of buzz words and terminologies, and acronyms and what have you swirling around the activity of putting software together. From DDD to Layered Architecture, to Microservice architecture, to Command Query Responsibility Segregation, to Message Driven Architecture, to Reactive systems, to...you get the point? And obviously there are overlaps in the concepts these words represents: therein lay the first motivation: To cut through all these ideas and get to the core of the know-how they represents when it comes to putting Software together.

Then there are the slew of libraries and frameworks that are supposed to help build software following these aforementioned ideas: From Akka, to AxonFramework, to RxJava, to Reactor, to Vertx: list is almost endless. (As you might have guessed my exploring of the topic will be heavily influenced by the tools available in the Java/JVM ecosystem)

Second motivation is then a logical follow up off the first one: applicability. Make sense of the plenitude of tools out there. Know when their usage is most appropriate and how they help in applying the various ideas around putting software systems together.

I am definitely curious to see the ideas and tools (libraries/frameworks) these exploration would lead me in contact/familiarity with...posts that falls into this category will be aptly tagged “Software Architecture”.

Saturday, September 19, 2015

Krwkrw 0.1.3 Released

Just pushed the latest release (0.1.3) of Krwkrw to Maven central.

Krwkrw is a web scraper. You can read how it came into being here

A quick run down of the changes in 0.1.3.
  1. Ability to express URL's to be included/excluded using Regex pattern. For example:
    Krwkrw crawler = new Krwkrw(action);
    crawler.match("(\\S+)(/projects/)(\\S+)")
    
    makes sure that only contents in the /projects/ path would be processed while
    Krwkrw crawler = new Krwkrw(action);
    crawler.skip("(\\S+)(/projects/)(\\S+)")
    
    will fetch and process all the contents except, the ones in the /projects/ path
  2. Ability to have random delays in between requests.
    Before now it was only possible to set the seconds to wait between requests. For example:
    Krwkrw crawler = new Krwkrw(action);
    crawler.setDelay(5) // waits 5 seconds between requests
    
    With the 0.1.3 release, it is possible to have random delay; that is, the requests will be delayed by number of seconds picked randomly from a lower and upper bound, for example:
    Krwkrw crawler = new Krwkrw(action);
    // waiting seconds will be any number between 5 and 20
    crawler.setDelay(5, 20) 
    
  3. Change in API. doKrawl method replaced with crawl
  4. Fix issue where it was possible for the crawler to crawl pages outside the origin url
  5. Some minor improvements here and there...
If using Maven as your build tool, you can add it to your project via:
<dependency>
<groupid>com.blogspot.geekabyte.krwkrw</groupid>
<artifactid>krwler</artifactid>
<version>0.1.3</version>
</dependency>

If using Gradle, then:
dependencies {
compile "com.blogspot.geekabyte.krwkrw:krwler:0.1.3}"
}

The Javadoc can be accessible online here.

You can also check out Krwkrw on Github

Sunday, September 06, 2015

What Does Changing Someone Else's Code Have In Common With Defusing A Bomb?


A while back, the above picture bobbled up my twitter stream...it was a morning of a weekday if I remember correctly...and as I was about to bop my head in agreement and push the retweet button: a gesture to show the picture also holds for me...It slowly struck me: that was not the case... this does not hold true for me...maybe it did before, but not anymore.

See, I understood the sentiments expressed in the picture so perfectly well. Either due to building on a codebase written by someone else (aka a former employee), or working on the same codebase with other developers. That apprehension of approaching someone else's code. That feeling of things blowing up, in unpredictable and unexpectable ways was just too familiar.


Monday, August 24, 2015

How Well Do You Know Your Collection API?

I recently spent some time going over the Java collection API and even though, it can be said it is one of the most used API in everyday programming with Java, I still had some "Oh I totally forgot about that" moments to "I did not even know that was so" realizations.

I will note down some of the interesting observations in this post, being as succinct as possible and backing with code examples when needed. It is intended to be a place I can always consult to get an overview of the API.


Sunday, August 16, 2015

Embedding ElasticSearch In a Spring Application

This blog post will show how to have ElasticSearch embedded in a Spring Application.

Motivation


Why Embed ElasticSearch in an application? Simple. To reduce the infrastructure overhead an application needs in other to run, making it more portable.

It is also for the same reason you will want to embed, say a web server, within your application.

It is especially appropriate to have ElasticSearch embedded when the use case does not require the distributed features of ElasticSearch and all that is needed is just a single node.


Tuesday, August 04, 2015

Video Courses? Maybe, Maybe Not.

Sometimes last week I got to learn that one of my blog posts inspired folks at Webucator to make a video tutorial.

The video, which is seen below, is about a feature in Spring MVC. it was inspired by the post Injecting and Binding Objects to Spring MVC Controllers




I recently published a series of post on introducing Servlet based web application development in Java. The original idea was supposed to have the topic covered in a single post, not a series, but as soon as I started writing, it became obvious that the topic at hand is too broad to fit into a single post.

This sort of realization is fast becoming the norm when considering blogging tutorials that relates to Java, as the landscape is quite extensive, having various moving parts that an attempt to write short, relatively beginner level tutorials is almost impossible.

With this video, I might have just been inspired to consider video courses, as those seem to provide the apt medium for covering the vast landscape that is Java software development.

...or maybe not? as making videos definitely requires a whole lot more time... time, the luxury I currently do not have much of. :)

We'll see..

...and oh, by the way the folks at Webucator do offer Java Fundamental courses... You might want to check them out.

Friday, July 31, 2015

Introduction to Spring Boot as a Servlet Based Web Application Framework

This is the fifth and last post in the series on Introduction to servlet based web application in java. The previous posts in this series are:
  1. Introduction to the Servlet API, Web Server and Servlet Container
  2. Introduction to .war Packaging and Maven
  3. Quick Overview of Basic Maven Concepts
  4. How to Create .war Files with Maven Archetypes and Deploy to Tomcat
  5. How to Create .war Files with IntelliJ and Deploy to Tomcat
These posts have touched on web servers and containers, the servlet API, packaging war files and how to achieve this using built in support in IDE or via maven archetype. This post would conclude the series by taking a look at Spring boot.


How to Create .war Files with IntelliJ and Deploy to Tomcat

This post is the fourth post in the series of post on Introduction to Servlet based web application development in Java.

Previous post shows how to create Maven projects, package and deploy to either a standalone server or an embedded server, by directly using the Maven archetype; but since in practice, an IDE would be used for development, this post shows how to do the same using an IDE.

Intellij IDEA is used in this post. If using other IDEA (say Eclipse or NetBeans) you would have to consult the help section or online documentation for the corresponding steps in the IDE you use.

This post is adapted from Developing a Java EE application. A post which shows how to create and run a JEE web application, but it does not accomplish this with Maven and uses Glassfish as the application server instead of Tomcat which we are interested in.

What this post does is to modify the steps to include usage of Maven and then show steps on how to deploy to Tomcat


How to Create .war Files with Maven Archetypes and Deploy to Tomcat

 Maven Archetypes are project templating mechanism, implemented as a Maven plugin.Archetypes make it possible to define the barebone of a project’s structure and then use that to create other projects.

This post, which is the fourth in a series of posts on Servlet based web application development in Java, shows how Maven archetypes can be used to generate a Web application Maven project; how to edit it to print “hello world”; and also, how you can use Maven to package it up so it can be deployed to a Servlet container.

We would make use of two Maven archetypes to achieve this:
1. The maven-archetype-webapp  and
2. The Servlet3-maven-archetype

Let's get down to business


Quick Overview of Basic Maven Concepts

This post is the third in the series of posts that Introduces Servlet based web application development in Java. It would be an overview of Maven and it serves to provide the necessary basic information about Maven before we proceed to other post in the series that touches on how to use Maven to package .war files and to use archetypes to create and deploy a .war to Tomcat.

An in depth coverage of these Maven concepts or Maven capabilities in general is not something that can be covered in a single blogpost; what this post does then is to only touch on some of the concepts, especially the ones that would help in making sense of the topics that will be addressed further on in this series of post.


Introduction to .war Packaging and Maven

The .war (Web application ARchive) is a packaging mechanism for putting together the application code of a web application to be deployed to a Servlet container. It is nothing complex and can be considered similar to ZIP files, the only difference being that it contains java related meta files that distinguishes it from regular ZIP files.

And just like ZIP files package up directory structures and their contents, .war files also do the same, the only difference being that the directory structures has to be laid out in a particular format.

This post is the second in a series of posts on Servlet based web application development in Java. It will thus introduce .war files, their structure and how to create one using Maven.


Introduction to the Servlet API, Web Server and Servlet Container

This post is the first in a series of posts on Servlet based web application development in Java. It will introduce the Servlet API and Servlet Containers.

Let's get to it...

Okay so you want to build a web application using Java? But as everyone knows, a web application needs to be hosted by a web server right? Right!

So maybe you can use the Apache HTTP Server or Microsoft Internet Information Services (IIS)...?

No.

No? But they are both web servers, aren't they?

True they are web servers, but remember we are going to be building Servlet based web applications? That means we need a web server that can, not only functions as an HTTP web server, but one that also serve as a Servlet container and can execute code written against the Servlet API...

"Servlet API? One that can serve as a Servlet container"? What does these mean?

Let us attempt an explanation…


Introduction to Servlet Based Web Application Development In Java

This post is the first in a series of post that introduces Servlet based web application development in Java.

The Goal

The aim is to help the reader, quickly create a mental model for Servlet based web application development in Java: build an appreciation for the essential moving parts and a basic understanding of how they all fit together.

It does not seek to be an exhaustive guide to a topic that is obviously broad and encompassing. That being said, the reader who is just approaching Servlet based web development for the first time should find the series of posts helpful.

Also, at appropriate junctions, I will provide links to resources where more in depth information can be found.

It is also worth pointing out that the reason we have the title as "Servlet based web application in Java", instead of just "web application in Java" is to stress the fact that using Servlet is just one option (albeit currently the most ubiquitous option) to building web applications with Java. It is possible to build web applications without using the Servlet API. Play Framework is an example of a framework that allows exactly that; Vertx is another example.

The posts contained in the series includes:

Introduction to the Servlet API, Web Server and Servlet Container
Introduction to .war Packaging and Maven
Quick Overview of Basic Maven Concepts
How to Create .war Files with Maven Archetypes and Deploy to Tomcat
How to Create .war Files with IntelliJ and Deploy to Tomcat
Introduction to Spring Boot as a Servlet Based Web Application Framework

Hopefully these series of posts help build the basic foundational knowledge of how servlet based web application works.


Monday, May 18, 2015

How To Publish Software Artifacts To Central Repository

I have had to release software artifacts to the Central Repository, which used to be mainly referred to as Maven Central a couple of times now, and each time I have found myself fumbling at one step or another in the process, and had to resort to Googling to sort things out. This post is basically a compilation of all my “groping in the dark”, because unfortunately the process of moving the piece of software you have written to having it available for the whole world to download from the Central Repository is not yet a matter of just pushing a button; or running a simple command.

So I write this post to serve as a reference for myself and for anyone else out there that might find it useful: a place to document the necessary steps needed to publish Software artifacts to Central Repository; while iterating the recurrent hurdles that I kept on encountering in the process of getting the publishing to Central Repository successful. I have also included a couple of useful links at the end of the post.

A rundown of the steps involved can be roughly summarized to be:
  1. Create an account on oss.sonatype.org
  2. Create and share a PGP signature.
  3. Update settings.xml and pom.xml appropriately.
  4. Upload your artifact to oss.sonatype.org.
  5. Promote the release.


Saturday, May 16, 2015

Krwkrw 0.1.2 Released.

Just pushed the latest release (0.1.2) of Krwkrw to Maven central.

Krwkrw is a web crawler/scrapper...scrapper is more apt actually.

If using Maven as your build tool, you can add it to your project via:

<dependency>
<groupid>com.blogspot.geekabyte.krwkrw</groupid>
<artifactid>krwler</artifactid>
<version>0.1.2</version>
</dependency>

If using Gradle, then:

dependencies {
    compile "com.blogspot.geekabyte.krwkrw:krwler:0.1.2}"
}

A quick run down of stuffs worth mentioning that comes with this release:
  • Addition of 3 utility classes that makes it easy to store the crawled webpages to a relational database, ElasticSearch or saved into a CSV file.
  • It is now possible to register a callback that would be fired when the crawling operation terminates. Should be most useful when the crawling operation is done with the Async mode. 
  • A bug where broken links are crawled multiple times.
  • General improvements to API, tests, etc...
You can see the Readme for more information. And yeah, the 'a' was dropped from the name, from Krawkraw to Krwkrw, because, all consonants name sounds cooler.

For a background story on how Krwkrw came to be, please read A web scraper/crawler in Java: Krawkraw



Saturday, March 21, 2015

Digging Deeper Into Java's HashMap

This post is about Java's HashMap. Even though it is filled under Beginning Java tag, it won't be an introductory post on how to begin using HashMap: its API or the common tasks you can accomplish with it. It would be a peep into how HashMap works, how it is implemented, with the hope that knowing this would provide more insight into what goes on whenever HashMap is being used.

I would wager that HashMap is probably one of the most readily used data structures when programming in Java. The functionality it provides: which is the ability to store stuff in pairs, is a particularly universal data structure need, not unique to Java. This facility goes by other names elsewhere: associative array, symbol table, dictionary or map: which HashMap is: a map implementation that is based on the concept of hashing; and by hashing, what do we mean?

Hashing is basically a transformation process; that takes a value and transform it into another form which is more desirable (due to shorter length, easy to remember etc) but still can be used to represents the original value.


Saturday, January 03, 2015

Using Optional Effectively in Java 8

Optional<T> was added in Java 8, and according to its documentation it is defined as "a container object which may or may not contain a non-null value..."

I have recently been spending some time getting familiar with the Stream API, also introduced in Java 8, and a lot of the terminating methods of the Stream API returns an Optional<T>...

At first encounter with Optional<T>, my first thought was asking what real advantage does this offer? How is it different from checking if an object is null before calling its methods?

The Optional<T> has the isPresent() and get() methods which can be used to check if the enclosing object is null or not, and then retrieve it. Like so:

Optional<SomeType> someValue = someMethod();
if (someValue.isPresent()) { // check
    someValue.get().someOtherMethod(); // retrieve and call
}

But exactly the same thing can be done with plain null checks with the code looking almost the same:

SomeType someValue = someMethod();
if (someValue != null) {
    someValue.someOtherMethod();
}

What then is Optional<T> good for?


Thursday, January 01, 2015

First Blogpost of 2015!

...and the first post of 2015 would be...all first posts of all previous new years since I started blogging!

How meta can that get ;)

So here we go, from 2006 till now!