Intermediate Events in jBPM – Complete Guide with Examples

 Intermediate Events in jBPM are BPMN elements that occur between the start and end of a workflow.

They allow you to pause, wait, send signals, catch messages, trigger timers, handle errors, and create real-life, production-ready business workflows.

In jBPM, Intermediate Events work through the BPMN2 engine and behave exactly as defined in the BPMN specification — but with jBPM-specific execution semantics such as Event Nodes, Node Instances, Signals, WorkItem interruptions, boundary events, and process instance correlation.


⭐ What Are Intermediate Events?

Intermediate Events in jBPM can:

Catch something (wait)
Throw something (send/trigger)

They appear in the process flow, attached to an activity, or placed in the sequence path.


Types of Intermediate Events in jBPM

Below is the full list — with examples, XML snippets, and usage.


1️⃣ Timer Intermediate Event (Catch)

Used to delay or schedule actions inside a process.

📌 Examples:

  • Wait for 2 days before sending a reminder

  • Check SLA expiration

  • Daily scheduled checks (cron)

XML Example

<intermediateCatchEvent id="Wait2Days"> <timerEventDefinition> <timeDuration>P2D</timeDuration> </timerEventDefinition> </intermediateCatchEvent>

Business Central

You configure delay using:
Duration, Cycle, or Date (ISO-8601).


2️⃣ Message Intermediate Catch Event

Used when jBPM must wait for an external system to send a message.

In jBPM, messages are correlated using:

  • MessageRef

  • CorrelationKey (optional)

📌 Use cases:

  • Wait for payment confirmation

  • Wait for verification from an external microservice

  • Wait for a file to be uploaded

Example

<intermediateCatchEvent id="WaitForMsg"> <messageEventDefinition messageRef="MsgPaymentDone"/> </intermediateCatchEvent>

You then trigger it using:

ksession.signalEvent("MsgPaymentDone", payload, processInstanceId);

3️⃣ Message Intermediate Throw Event

Used to send messages to other processes.

📌 Example

  • Trigger a downstream workflow

  • Notify another jBPM process instance

  • Send asynchronous event to microservices via custom handlers


4️⃣ Signal Intermediate Events (Throw & Catch)

A signal is a broadcast event.
All active processes listening for the signal will respond.

📌 Examples:

  • "PaymentCompleted"

  • "DocumentUploaded"

  • "FraudDetected"

Catching Signal

<intermediateCatchEvent id="SignalWait"> <signalEventDefinition signalRef="PaymentCompleted"/> </intermediateCatchEvent>

Throwing Signal

<intermediateThrowEvent id="SendSignal"> <signalEventDefinition signalRef="PaymentCompleted"/> </intermediateThrowEvent>

Triggering from Java

ksession.signalEvent("PaymentCompleted", data);

5️⃣ Error Intermediate Event (Catch)

Used to capture errors thrown inside a task.

In jBPM, you can attach these to nodes:

  • Service Tasks

  • Script Tasks

  • WorkItemHandlers

📌 Example:
An API call fails → throw error → catch error → move to fallback path.

Process XML

<intermediateCatchEvent id="CatchError"> <errorEventDefinition errorRef="API_ERROR"/> </intermediateCatchEvent>

Throwing from Java

throw new WorkItemHandlerException("API_ERROR", "API failed!");

6️⃣ Escalation Intermediate Events (Throw & Catch)

Escalations are non-fatal alerts.

Use cases:
✔ SLA warning
✔ Supervisor notification
✔ Business exception that should not kill the process

Example Throw

<intermediateThrowEvent id="EscalateSLA"> <escalationEventDefinition escalationRef="SLA_WARNING"/> </intermediateThrowEvent>

7️⃣ Compensation Intermediate Events

Used to roll back previous actions.

📌 Real-world examples:

  • Refund a payment

  • Reverse stock allocation

  • Undo reservation

jBPM compensation works through compensation handlers attached to activities.

XML

<intermediateThrowEvent id="TriggerCompensation"> <compensateEventDefinition activityRef="BookHotel"/> </intermediateThrowEvent>

8️⃣ Conditional Intermediate Event

Triggered when a condition becomes true at runtime.

📌 Example:
If approvalAmount > 50000, trigger a different path.

XML

<intermediateCatchEvent id="CondEvent"> <conditionalEventDefinition> <condition xsi:type="tFormalExpression"> #{approvalAmount > 50000} </condition> </conditionalEventDefinition> </intermediateCatchEvent>

Comparison Table




Event Type



Catch



Throw


Typical Usage
TimerWait for time or schedule
MessageSystem-to-system communication
SignalBroadcast to all processes
ErrorException handling
EscalationBusiness warnings
CompensationUndo/rollback
ConditionalTrigger when condition matches


Real-World Example: Insurance Claim Process


Scenario Flow:

  1. Claim submitted

  2. Timer waits for 24 hours pending documents

  3. External system sends verification message

  4. If mismatch → Error event → move to manual review

  5. If SLA at risk → Escalation event

  6. If fraud detected → Signal event triggers audit process

  7. If claim rejected → Compensation refunds customer

  8. Final settlement task executes

This shows how intermediate events support real-world business logic.


Best Practices for jBPM Intermediate Events

✔ Use message events for microservices communication
✔ Use signal events only when many processes must react
✔ Prefer error events over gateways for exceptions
✔ Use timers for reminders, SLAs, and delay logic
✔ Use conditional events for dynamic state changes
✔ Avoid mixing message, signal, and error handling in a single complex path
✔ Keep compensation actions simple and idempotent


💼 Professional Support Available

If you are facing issues in real projects related to enterprise backend development or workflow automation, I provide paid consulting, production debugging, project support, and focused trainings.

Technologies covered include Java, Spring Boot, PL/SQL, Azure, and workflow automation (jBPM, Camunda BPM, RHPAM).


Comments

Popular posts from this blog

jBPM Installation Guide: Step by Step Setup

Scopes of Signal in jBPM

OOPs Concepts in Java | English | Object Oriented Programming Explained