Is there the equivalent of an activity listener for DMN transactions? I’m trying to figure a way to capture the inputs and outputs of decisions without using the native Camunda history mechanism, which is simply too “expensive” for us to use with our volumes.
I suppose I could use listeners in the Business Rule Task to accomplish this, but for decisions rendered outside of a standard process, this wouldn’t work.
I’m trying very hard to not have to use custom code or to modify Camunda in any non-standard way.
Thanks.
1 Like
Hi @mppfor_manu,
you use a DmnDecisionTableEvaluationListener
which is invoked when a decision table is evaluated.
Does this work for you?
Best regards,
Philipp
I think this is the right track. Here’s how I’m trying to implement it (feel free to point and laugh, I’m new to a lot of this).
The process listener class:
…
@ProcessApplication(“Process_Xhist”)
public class Process_xhist_Impl extends ServletProcessApplication{
public ExecutionListener getExecutionListener() {
return new SendProcessVariableHistoryActivityListener();
}
public DmnDecisionTableEvaluationListener getDecisionListener() {
return new SendProcessVariableHistoryDecisionListener();
}
}
I’m not sure about the “getDecisionListener” above. The previous block for the activity listener works fine, I’m not sure what the equivalent would be for DMN evaluation, so I guessed.
The listener class:
import org.camunda.bpm.dmn.engine.delegate.DmnDecisionTableEvaluationEvent;
import org.camunda.bpm.dmn.engine.delegate.DmnDecisionTableEvaluationListener;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.VariableScope;
import com.att.gcs.bizops.cop.SendProcessVariableHistory;
public class SendProcessVariableHistoryDecisionListener implements DmnDecisionTableEvaluationListener {
@SuppressWarnings("static-access")
public void notify(DmnDecisionTableEvaluationEvent evaluationEvent) {
// Instantiate an object to hold the history record call
SendProcessVariableHistory newHistoryRecord = new SendProcessVariableHistory();
// Call the send process history variable class using the current activity and event "names"
newHistoryRecord.recordProcessVariableHistory((DelegateExecution) evaluationEvent, ((DelegateExecution) evaluationEvent).getCurrentActivityId() + ":" + "decision");
}
}
Again, I’m not sure about the above as it’s based upon my activity listener, which works. I’m ignorant, so I’m just following the activity listener code that works.
Now if only there was an equivalent for incidents…
Thanks.
Hi @mppfor_manu,
the process application doesn’t provide a decision listener. You must register the listener in the process engine configuration. See the user guide for details.
A simple test implementation:
DefaultDmnEngineConfiguration dmnEngineConfiguration = (DefaultDmnEngineConfiguration)
DmnEngineConfiguration.createDefaultDmnEngineConfiguration();
dmnEngineConfiguration.customPostDecisionTableEvaluationListeners(Collections.singletonList(new DmnDecisionTableEvaluationListener()
{
@Override
public void notify(DmnDecisionTableEvaluationEvent event)
{
Map<String, TypedValue> inputVars = event.getInputs().stream().collect(Collectors.toMap(DmnEvaluatedInput::getName, DmnEvaluatedInput::getValue));
// do something
}
}));
config.setDmnEngineConfiguration(dmnEngineConfiguration);
Does this help you?
Best regards,
Philipp
Phillip,
I’ll check this out and let you know.
As always, thanks for taking the time to answer.
Michael