Back to Conductor

Event Handlers API

docs/documentation/api/eventhandlers.md

2019-04-12-13005.0 KB
Original Source

Event Handlers API

The Event Handlers API manages event handler definitions — rules that start workflows or complete tasks in response to events from message brokers (Kafka, NATS, SQS, AMQP). All endpoints use the base path /api/event.

For details on configuring event handlers, see Event Handler Configuration. For configuring message broker connections, see the Event Bus Orchestration guide.

Endpoints

EndpointMethodDescription
/eventPOSTCreate a new event handler
/eventPUTUpdate an existing event handler
/eventGETGet all event handlers
/event/{name}DELETEDelete an event handler
/event/{event}GETGet event handlers for a specific event

Create an Event Handler

POST /api/event
shell
curl -X POST 'http://localhost:8080/api/event' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "order_event_handler",
    "event": "kafka:orders_topic:new_order",
    "active": true,
    "actions": [
      {
        "action": "start_workflow",
        "start_workflow": {
          "name": "order_processing",
          "version": 1,
          "input": {
            "orderId": "${eventPayload.orderId}",
            "customerId": "${eventPayload.customerId}",
            "payload": "${eventPayload}"
          }
        }
      }
    ]
  }'

Response 200 OK — no response body.

Event Handler Fields

FieldDescriptionRequired
nameUnique name for the event handlerYes
eventEvent identifier in format type:queue:subject (e.g., kafka:my_topic:my_event)Yes
activeWhether the handler is activeYes
actionsList of actions to execute when the event is receivedYes
conditionOptional JavaScript expression to filter eventsNo
evaluatorTypeExpression evaluator type (javascript or graaljs)No

Action Types

ActionDescription
start_workflowStart a new workflow execution
complete_taskComplete a pending task (e.g., a WAIT task)
fail_taskFail a pending task

Complete Task Action Example

json
{
  "name": "approval_handler",
  "event": "kafka:approvals_topic:approved",
  "active": true,
  "actions": [
    {
      "action": "complete_task",
      "complete_task": {
        "workflowId": "${eventPayload.workflowId}",
        "taskRefName": "wait_for_approval",
        "output": {
          "approved": true,
          "approvedBy": "${eventPayload.approver}"
        }
      }
    }
  ]
}

Update an Event Handler

PUT /api/event

Updates an existing event handler. The request body is the full event handler definition (same format as create).

shell
curl -X PUT 'http://localhost:8080/api/event' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "order_event_handler",
    "event": "kafka:orders_topic:new_order",
    "active": false,
    "actions": [
      {
        "action": "start_workflow",
        "start_workflow": {
          "name": "order_processing",
          "version": 2,
          "input": {
            "payload": "${eventPayload}"
          }
        }
      }
    ]
  }'

Response 200 OK — no response body.

Get All Event Handlers

GET /api/event

Returns a list of all registered event handlers.

shell
curl 'http://localhost:8080/api/event'

Response 200 OK

json
[
  {
    "name": "order_event_handler",
    "event": "kafka:orders_topic:new_order",
    "active": true,
    "actions": [
      {
        "action": "start_workflow",
        "start_workflow": {
          "name": "order_processing",
          "version": 1,
          "input": {
            "payload": "${eventPayload}"
          }
        }
      }
    ]
  }
]

Delete an Event Handler

DELETE /api/event/{name}

Removes an event handler by name.

shell
curl -X DELETE 'http://localhost:8080/api/event/order_event_handler'

Response 200 OK — no response body.

Get Event Handlers for an Event

GET /api/event/{event}?activeOnly=true

Returns event handlers configured for a specific event.

ParameterDescriptionDefault
eventEvent identifier (e.g., kafka:orders_topic:new_order)
activeOnlyOnly return active handlerstrue
shell
curl 'http://localhost:8080/api/event/kafka:orders_topic:new_order?activeOnly=true'

Response 200 OK — returns a list of matching event handler definitions.


Event Identifier Format

Event identifiers follow the pattern:

{type}:{queue/topic}:{subject}
TypeExampleDescription
kafkakafka:my_topic:my_eventApache Kafka topic
natsnats:my_subject:my_eventNATS subject
sqssqs:my_queue:my_eventAmazon SQS queue
amqp_exchangeamqp_exchange:my_exchange:my_eventRabbitMQ exchange
conductorconductor:my_event:my_eventConductor internal event queue