Using AOP to add some logic

Hi!

I have to add some logging logic which should be executed before starting new process in my spring boot app.
There are 3 ways to start process: using cockpit, using REST API, during delegation code using ProcessEngine and its RuntimeService.

To achieve my goal I use Spring AOP and have already wrote @Aspect class with point cut - @Before(“execution(* org.camunda.bpm.engine.RuntimeService.*(…))”).

When new process start from delegation code the additional logic works fine and I see logging message in stdout.
But when I start process from cockpit or using postman - additional logic is not invoked. And there is no message in stdout.

My dependencies


org.camunda.bpm.springboot
camunda-bpm-spring-boot-starter


org.camunda.bpm.springboot
camunda-bpm-spring-boot-starter-webapp


org.springframework.boot
spring-boot-configuration-processor
true


org.camunda.bpm.springboot
camunda-bpm-spring-boot-starter-rest

What’s my mistake? It looks like rest-starter and web-app-starter do not use the bean of ProcessEngine provided by camunda-bpm-spring-boot-starter

Hello @Vi_Va ,

indeed, the ProcessEngine has its self-contained instance providing mechanism that is independent of any cdi framework.

This allows for flexible architecture.

If you want to log a process instance start, you can use the Spring Event Bridge:

Or, you add a listener to the start event programmatically.

I hope this helps

Jonathan

1 Like

Hello @jonathan.lukas !

Thanks for your valuable answer. Spring Eventing Bridge is pretty good mechanism for logging.
Could you give me another one advice for implementing some logic before starting the process?

For example, it is necessary to verify count of started instances (of same definition).
Every time someone try to start process (through cockpit, REST API or java api):
If count == #some number => the request to start the process must not be executed. return exception message
else => start new instance

it seems that an execution listener will also be suitable for this

Hello,

for this you can use a conditional start event.

Jonathan

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.