Configuration

The API is likely to change as Doddle stabilises

Configuring

To create a new client configuration, we need use the builder

import dev.doddle.core.DoddleConfigurationBuilder;
final DoddleConfigurationBuilder builder = new DoddleConfigurationBuilder();

Storage

Configure Doddle to use your chosen storage provider. See the previous chapter about storage providers.

builder.storage(storageProvider);

Packages

This is where Doddle will look for class methods annotated with the @Task annotation.

For example, if you have a task defined in com.example.tasks.OrderTasks then set this value to com.example.tasks.

builder.packages("com.examples.tasks");

Resolver

Doddle needs to know how to get an instance or create an instance of a class that has a method annotated with the @Task annotation.

For example, let's say we have the following service with a task

public class OrderService {
    private final CustomerService customerService;
    
    OrderManager(CustomerService customerService) {
        this.customerService = customerService;
    }
    
    @Task
    public void process() {
    
    }
}

Doddle does not know how to instantiate this class - it has no idea how to get an instance of the CustomerService class. Let's solve that by creating a simple resolver:

builder.resolver(new TaskDependencyResolver() {
    @Override
    public <T> T resolve(Class<T> clazz) {
        if (clazz == OrderService.class) {
            return clazz.cast(new OrderService(new CustomerService()));
        }
        return null;
    }
});

This is just a simple example. You would normally use a dependency injection container such as a Guice or Spring IoC to get instances of your classes!

Great, Doddle now knows how to create the objects containing the task methods!

Scheduling

The scheduler is used to find jobs that are ready to be processed.

builder.scheduling(options -> {
    options.interval("1s")
           .delay("5000ms")
    return options;
});

Creating the client

Build the configuration

DoddleConfiguration configuration = builder.build();

Create the client

DoddleClientFactory factory = new DoddleClientFactory();
DoddleClient client = factory.createClient(configuration);

Great, we now have a client!

Last updated