Workers

Infinitic is still in active development. Subscribe here to follow its progress.

Infinitic provides a generic worker in charge of task or workflow execution based on its configuration. The roles of workers are:

  • to listen to Pulsar for messages
  • to process task or workflow accordingly and return its result
  • to maintain the state of task or workflow.

When running, a worker catches any exception sent by the class during its execution (see task failure). Use a logger to see the errors.

Do not start multiple workers with same configuration on one machine, instead increase the concurrency settings. To increases throughput and resilience, just start multiple workers on multiple servers

Workers can be scaled horizontally.

We can start a worker with:

import io.infinitic.factory.InfiniticWorkerFactory;
import io.infinitic.worker.InfiniticWorker;

public class App {
    public static void main(String[] args) {
        try(InfiniticWorker worker = InfiniticWorkerFactory.fromConfigFile("infinitic.yml")) {
            worker.start();
        }
    }
}
import io.infinitic.factory.InfiniticWorkerFactory

fun main(args: Array<String>) {
    InfiniticWorkerFactory.fromConfigFile("infinitic.yml").use { worker ->
        worker.start()
    }
}

We can also use .fromConfigResource("/infinitic.yml") if the configuration file is located in the resource folder.

Here is an example of a valid infinitic.yml file:

name: optional_worker_name

redis:
  host: localhost
  port: 6379
  user:
  password:
  database: 0

pulsar:
  brokerServiceUrl: pulsar://localhost:6650
  webServiceUrl: http://localhost:8080
  tenant: infinitic
  namespace: dev

workflows:
  - name: example.booking.workflows.BookingWorkflow
    class: example.booking.workflows.BookingWorkflowImpl
    concurrency: 10

tasks:
  - name: example.booking.tasks.carRental.CarRentalService
    class: example.booking.tasks.carRental.CarRentalServiceFake
    concurrency: 5
  - name: example.booking.tasks.flight.FlightBookingService
    class: example.booking.tasks.flight.FlightBookingServiceFake
    concurrency: 5
  - name: example.booking.tasks.hotel.HotelBookingService
    class: example.booking.tasks.hotel.HotelBookingServiceFake
    concurrency: 5

This configuration contains a worker name (optional), the Redis settings, the Pulsar settings, and for each task or workflow:

NameTypeDescription
namestringname of the task / workflow (its interface)
classstringname of the class to instantiate
concurrencyintegermaximum number of messages processed in parallel

When providing a worker name, this name must be unique among all our workers and clients connected to the same Pulsar namespace.

A worker must contain the code of all class described in its configuration file.

As illustrated above, a worker can handle multiple task or workflow, but we can also specialize a worker per task or per workflow. We just have to update to infinitic.yml file accordingly, for example:

pulsar:
  brokerServiceUrl: pulsar://localhost:6650
  webServiceUrl: http://localhost:8080
  tenant: infinitic
  namespace: dev

tasks:
  - name: example.booking.tasks.carRental.CarRentalService
    class: example.booking.tasks.carRental.CarRentalServiceFake
    concurrency: 5
Edit this page on GitHub Updated at Mon, Oct 25, 2021