Queues vs. Topics vs. Virtual Topics (in ActiveMQ) ActiveMQ provides a variety of different messaging patterns. While queues and topics are the most famous ones, virtual topics can combine the best of both worlds: multiple consumers with their own dedicated queue. Queues Queues are the most obvious messaging pattern implemented by ActiveMQ. They provide a direct channel between a producer and a consumer. […]
Using @ConfigurationProperties to separate service and configuration Roughly about two years ago, I wrote an article called “Why using Spring’s @Value annotation is bad“. I described why you should avoid @Value annotations all throughout your code. By using @Value annotations in services, controllers and other Spring components, you will scatter your configuration through the complete application. In the worst case, you will […]
AngularJS provider and app configuration AngularJS provides 3 different ways to create a service: Factory A factory is a well known pattern in software development. It aims to create a certain object, in this case a service. In AngularJS this is simply a function which returns an object with methods. In my opinion, this is the cleanest way to create […]
Programming to an interface Program to an interface, not an implementation. This short sentence, introduced in 1994 by the GoF, is one of the most important design principles in software development. However, I have seen several projects where this principle has gone wrong. Here’s why: Interface vs. Interface If you come from a Java background like myself and you […]
Anti Pattern: Don’t use Optionals for data repositories Java 8 Optionals Java 8 introduced a new feature call Optionals. Optionals are an easy way to force the caller of a method to deal with a possible null return value: 123456 public Optional<String> getName() { ...} Optional<String> name = getName();System.out.println(name.orElse("I forgot my name"); If you use an Optional as the return type of your method, whoever calls the method will be reminded that it might return […]
Everytime a mock returns a mock a fairy dies As I was reading about some Mockito features last week, I stumbled over the following tweet, which really made me laugh: Everytime a mock returns a mock a fairy dies — Damian Guy (@damianguy) 18. Oktober 2009 I actually found the reference to the tweet in the Mockito source code about “deep mocking” and it’s […]
Why using Spring’s @Value annotation is bad @Value Configuration is an important topic of every application which has more than a couple of hundred lines of code. In case you are using Spring, you would typically use Spring’s @Value annotation to load values from a Java properties file. This could look like this: 12345678 @Servicepublic class MyService { @Value("${my.config.property.key}") private String someConfigValue; //...} If you do so, Spring would inject the […]
Thread pools with Java’s ExecutorService Some days ago I had to do a migration of legacy data to a new system. The task was mainly about copying stuff from the old system to the new system. This was done via a REST interface of the new service. So the task was completely IO bound and most of the time the […]
Anti Patterns A couple of days ago I have been to a tech talk from eBay in Berlin. The talk was hold by a developer of the eBay Kleinanzeigen team (a subsection of eBay in Germany) who talked about development patterns his team learned during the years. He mentioned behavioral patterns, design patterns and coding pattern his […]
Making a Spring bean session scoped Spring can not only inject beans (components, services, entities, however you want to call them), it can also inject them according to a certain scope. This is great if you have state-full objects which belongs (for example) to a dedicated user and not to the whole application. To do that, Spring introduced the @Scope annotation. […]