Interaction execution
This section will give a basic explanation when baker will execute interactions in your Recipe. For a more in depth information please see the execution-semantics page.
When does Baker execute an interaction
Baker will execute an interaction when:
- All incoming ingredients are available
- All event preconditions are met.
After an interaction is executed it will 'consume' the ingredients and events. Interactions get their own copies of events/ingredients to consume. You do not have to worry about one interaction taking the ingredients away from another.
To execute an interaction again all incoming ingredients need to be provided again and the event preconditions need to be met again.
Reprovider interactions
Interactions can be configured to be reprovider interactions. This means that after execution they will provide their own ingredients again. Reprovider interactions will only need to have their ingredients to be provided once. They will execute everytime their event preconditions are met.
Reprovider interactions do not update the ingredient data and will always use the latest ingredient data that is available.
If there are no event preconditions on a reprovider interaction, it will automatically loop its execution. Therefore this is made mandatory in the RecipeCompiler.
package examples.java.recipes;
import com.ing.baker.recipe.javadsl.InteractionDescriptor;
import com.ing.baker.recipe.javadsl.Recipe;
import examples.java.events.OrderPlaced;
import examples.java.interactions.ShipOrder;
public class RecipeWithReproviderInteraction {
public final static Recipe recipe = new Recipe("Reprovider recipe")
.withSensoryEvent(OrderPlaced.class)
.withInteractions(
InteractionDescriptor.of(ShipOrder.class)
.isReprovider(true)
.withRequiredEvent(OrderPlaced.class)
);
}
package examples.kotlin.recipes
import com.ing.baker.recipe.kotlindsl.ExperimentalDsl
import com.ing.baker.recipe.kotlindsl.recipe
import examples.kotlin.events.OrderPlaced
import examples.kotlin.events.PaymentReceived
import examples.kotlin.interactions.ShipOrder
@ExperimentalDsl
object RecipeWithReproviderInteraction {
val recipe = recipe("Reprovider recipe") {
sensoryEvents {
event<OrderPlaced>()
}
interaction<ShipOrder> {
isReprovider = true
requiredEvents { event<OrderPlaced>() }
}
}
}
package examples.scala.recipes
import com.ing.baker.recipe.scaladsl.{Event, Recipe}
import examples.scala.events.OrderPlaced
import examples.scala.interactions.ShipOrder
object RecipeWithReproviderInteraction {
val recipe: Recipe = Recipe("Reprovider recipe")
.withSensoryEvent(Event[OrderPlaced])
.withInteraction(
ShipOrder.interaction
.isReprovider(true)
.withRequiredEvent(Event[OrderPlaced])
)
}