Skip to content

Monitoring

Baker allows you to register a couple of different event listeners. These are especially useful for monitoring and logging purposes.

Warning

Each event is guaranteed to be delivered AT MOST ONCE. You should not use an event listener for critical functionality.

Note

The delivery is local (JVM) only. You will not receive events from other nodes when running in cluster mode.

Recipe instance events

The registerEventListener method allows you to declare an event listener which listens to all events of a specific recipe instance.

package examples.java.application;

import com.ing.baker.runtime.javadsl.Baker;
import com.ing.baker.runtime.javadsl.EventInstance;

public class RegisterEventListener {

    private final Baker baker;

    public RegisterEventListener(Baker baker) {
        this.baker = baker;
    }

    public void example() {
        baker.registerEventListener((String recipeInstanceId, EventInstance event) ->
            System.out.println("Recipe Instance " + recipeInstanceId + " processed event " + event.name())
        );
    }
}
package examples.kotlin.application

import com.ing.baker.runtime.kotlindsl.Baker

class RegisterEventListener(private val baker: Baker) {

    suspend fun example() {
        baker.registerEventListener { recipeInstanceId, eventInstance ->
            println("Recipe Instance: $recipeInstanceId, processed event: ${eventInstance.name} ")
        }
    }
}
package examples.scala.application

import com.ing.baker.runtime.scaladsl.Baker

class RegisterEventListener(val baker: Baker) {

  def example(): Unit = {
    baker.registerEventListener((recipeInstanceId, event) =>
      println(s"Recipe instance: $recipeInstanceId, processed event: ${event.name}")
    )
  }
}

All Baker events

The registerBakerEventListener method allows you to declare an event listener which listens to all Baker events. These are events that notify what Baker is doing.

package examples.java.application;

import com.ing.baker.runtime.javadsl.Baker;
import com.ing.baker.runtime.javadsl.BakerEvent;

public class RegisterBakerEventListener {

    private final Baker baker;

    public RegisterBakerEventListener(Baker baker) {
        this.baker = baker;
    }

    public void example() {
        baker.registerBakerEventListener((BakerEvent event) ->
            System.out.println("Received event: " + event)
        );
    }
}
package examples.kotlin.application

import com.ing.baker.runtime.kotlindsl.Baker

class RegisterBakerEventListener(private val baker: Baker) {

    suspend fun example() {
        baker.registerBakerEventListener { bakerEvent ->
            println("Received event: $bakerEvent")
        }
    }
}
package examples.scala.application

import com.ing.baker.runtime.scaladsl.Baker

class RegisterBakerEventListener(val baker: Baker) {

  def example(): Unit = {
    baker.registerBakerEventListener((bakerEvent) =>
      println(s"Received event: $bakerEvent")
    )
  }
}