Consumer
📌 Purpose
The CampaignExecutionConsumer
component is responsible for detecting and launching the execution of CampaignExecution
entities that are in the NEW
status.
It is typically used together with the CampaignExecutionProducer
, which creates new executions on a schedule.
🔧 Class: CampaignExecutionConsumer
CampaignExecutionConsumer
🔁 Execution Frequency and Safety
Triggered periodically via
@Scheduled
; interval configured inapplication.properties
:Uses Shedlock via
@SchedulerLock
to ensure only one service instance executes in clustered environments.
⚙️ Core Logic
Find a
CampaignExecution
with statusNEW
:Retrieves the latest
NEW
execution (ordered byid desc
)
Load the execution using
getSync(id)
:Ensures consistent access via
SynchronousAccessRepository
Execution will only proceed after any ongoing transaction completes
Verify execution status:
Prevents race conditions and duplicate execution
Launch the execution:
Execute in an isolated transaction:
Ensures full isolation from external transaction context, improving consistency and preventing side effects
💥 Error Handling
Errors within runExecution(...)
are not swallowed.
Instead, they are logged to an ExceptionEntity
within CampaignExecutionService
.
As a result, the user can view the error message and stack trace in the UI.
🧪 Example Behavior
Campaign A
executionType = AUTOMATIC
Producer:
Creates
CampaignExecution(id=100)
with statusNEW
Consumer:
Finds
id = 100
Loads it via
getSync(100)
Verifies status is
NEW
Executes the campaign
Updates the status to
FINISHED
orEXCEPTION_OCCURRED
📌 Summary
CampaignExecutionConsumer
automatically executes campaignsDetection: Searches for the first
CampaignExecution
inNEW
statusIsolation: Execution runs in a new transaction using
TransactionTemplate
Safety:
@SchedulerLock
prevents duplicate executions in clustered setupsConsistency:
getSync()
ensures serialized access in concurrent environmentsError Logging: Exceptions are saved to
ExceptionEntity
and shown in the UI
Last updated
Was this helpful?