Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add Spring beans into custom functions like Juel #922

Closed
zxuanhong opened this issue Sep 4, 2024 · 12 comments
Closed

How to add Spring beans into custom functions like Juel #922

zxuanhong opened this issue Sep 4, 2024 · 12 comments

Comments

@zxuanhong
Copy link

zxuanhong commented Sep 4, 2024

Is your feature request related to a problem? Please describe.
How to add Spring beans into custom functions like Juel
Describe the solution you'd like

  1. When using feel, sometimes methods need to call spring beans to obtain some information. For example, using mybatis to read database information, etc
  2. May I ask how to add the spidng bean method to the feel like Camunda C7 Juel did
  3. Directly using Spring beans can be well extended, and it is unlikely to implement the logic of Spring beans in custom methods (which appears very complex, and many are associated with Spring)
@saig0
Copy link
Member

saig0 commented Sep 5, 2024

@zxuanhong thank you for raising this. Please provide more context to your use case. Do you have a concrete example?

@saig0 saig0 removed their assignment Sep 5, 2024
@zxuanhong
Copy link
Author

zxuanhong commented Sep 5, 2024

@saig0

  1. I have defined the following beans in spring
image
  1. Define a similar feel expression: person.leader ('user id ')

  2. I hope the feel engine can automatically adjust the method corresponding to the bean

  3. May I ask how feel can achieve such an effect. Camunda C7 juel expression is achievable. c7 eg.:

image
  1. The Spring ecosystem is very powerful. If feel can call the bean method in Spring, it is very important

@saig0
Copy link
Member

saig0 commented Sep 6, 2024

@zxuanhong thank you for providing more context. I assume that you're using Camunda 7, right?

Invoking a Spring bean in a FEEL expression doesn't work. The Camunda engine doesn't provide the Spring beans in the expression context. So, the FEEL engine can't resolve them.

To support Spring beans, we would need to adjust the integration of the FEEL engine in Camunda 7.

@zxuanhong
Copy link
Author

zxuanhong commented Sep 6, 2024

@saig0 I am wondering if Zeebe can support it so that we can extend it through Spring beans. Because some methods require processing within the Spring context (such as querying databases through dao ).Or can you provide relevant examples of integrating spring beans with feel

@saig0
Copy link
Member

saig0 commented Sep 6, 2024

Camunda 8 (Zeebe) has a different architecture and runtime model than Camunda 7. In Camunda 8, the engine has no direct access to the process application but communicates via job API (i.e. similar to external jobs in Camunda 7). So, neither the FEEL nor the BPMN engine can access Spring beans of the process application.

In Camunda 8, your Spring application would implement a job worker that is invoked in a service task or an execution listener.

@zxuanhong
Copy link
Author

zxuanhong commented Sep 6, 2024

@saig0 I need to use it in zeebe jobwork. I have defined some feed expression content in the header and used myself in the job worker to parse these expressions(It can also be defined as other expressions, but do not want the job worker system to embed too many expression engines)
image

At the same time, in self-management deployment, it is meaningful to extend the feel function through Spring beans

@saig0
Copy link
Member

saig0 commented Sep 6, 2024

@zxuanhong sounds like a valid approach for Camunda 8.

The Spring bean is part of your process application. You define a start execution listener on the user task to invoke the Spring bean and pass the leader as a variable (i.e. person.leader(user_id)). In the assignee expression, you can access the leader variable. Not sure why you need the expression in the custom header.

In general:

  • Use an execution listener to invoke the Spring bean
  • Return the result of the Spring bean as a variable
  • Use the result variable in a FEEL expression

in self-management deployment, it is meaningful to extend the feel function through Spring beans

That was possible with Camunda 7 but for Camunda 8 this is not possible by design. The process application with the Spring bean doesn't run in the same JVM as the Camunda engine.

@zxuanhong
Copy link
Author

zxuanhong commented Sep 6, 2024

@saig0 Because this expression is a method of a Spring bean. Obviously, the zeebe engine cannot have this bean. I just used a header to define a job worker business expression, which facilitates the zeebe job to be passed to the worker server.
This is just an idea (currently, I'm not sure how to call the Spring Bean method with Feel).
And I believe that calling Spring Bean methods as an extension to the feed function is more practical than customizing the feed function (because many Java environments require executing business logic under Spring)

That's why I asked how to integrate the Spring Bean method into the feel
I also know that it's not possible in the zeebe engine, but I need to use it in the job worker business service(or connectors)

@saig0
Copy link
Member

saig0 commented Sep 10, 2024

I also know that it's not possible in the zeebe engine, but I need to use it in the job worker business service(or connectors)

It should be possible to invoke the Spring bean function in the FEEL expression if you pass the bean in the variable context.

@zxuanhong
Copy link
Author

@saig0 I really don't understand how to pass parameters to the Spring Bean method. Can you provide a simple example. Thank you.

@saig0
Copy link
Member

saig0 commented Sep 16, 2024

@zxuanhong sorry. I can't help you here. The integration from Spring and FEEL is not our focus.

However, feel free to come back if you have very concrete questions or an example.

@zxuanhong
Copy link
Author

@saig0 I'm sorry to hear that. It is a bad choice to separate the feel expression from spring in the job work system. I'll stick with juel😔

@zxuanhong zxuanhong closed this as not planned Won't fix, can't repro, duplicate, stale Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants