Welcome to docs|Reactions|Creating reaction definitions

Creating reaction definitions

This page describes how you create Reaction Definitions in Serialized.

To create a Reaction Definition you need to set the event type it should react on and which action the reaction should perform. You can also optionally configure an offset to postpone the reaction execution into the future. The following are the attributes that can be configured for a reaction definition:

  • Reaction name - A unique name for the reaction definition. This name is used to identify the reaction definition. Every reaction that is triggered will be associated with this name.
  • Feed name - The name of the feed that the reaction processor should subscribe to.
  • Event type - The event type the reaction should react on.
  • Event types to cancel on - The event types that should cancel the reaction. If a reaction is scheduled and this event is processed before the reaction has been triggered, it will be canceled.
  • Action - The action that the reaction should perform. There are different kinds of event types.

You can create as many reaction definitions as you want.

Creating a reaction definition

You can use our SDKs to create a reaction definition. Just like projection definitions, reaction definitions support strict creation, to the operation will fail if there already is a reaction definition with the given name.

You can replace an existing reaction definition by using the method to update a reaction definition.

The following example shows how to create a reaction definition that is configured to send notifications every time an OrderPlaced event is processed from the feed order.

ReactionDefinition request = newReactionDefinition("notify-on-order-placed")    .feed("order")    .reactOnEventType("OrderPlaced")    .action(httpAction(URI.create("")).build())    .build();reactionClient.createDefinition(request);
const request = {  reactionName: 'notify-on-order-placed',  reactOnEventType: 'OrderPlaced',  feedName: 'order',  action: {    actionType: "HTTP_POST",    targetUri: ''  }}await reactionsClient.createDefinition(request);

When an OrderPlaced event is processed, the reaction processor will send a POST request to the configured URL. To see how the request to that URL will look like, see Implementing HTTP actions.