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

Using static methods to create beans in yaml dsl #1643

Closed
2tsheep opened this issue Sep 18, 2023 · 6 comments
Closed

Using static methods to create beans in yaml dsl #1643

2tsheep opened this issue Sep 18, 2023 · 6 comments

Comments

@2tsheep
Copy link

2tsheep commented Sep 18, 2023

Hello everyone,
I hope that this is the right place for this question.

I want to create a connection bean to an influxdb in yaml dsl. However, I was not able to find anything in the documentation or in the examples which specifies how a static or even a specific method can be addressed. Here is an example Code Snippet:
`- beans:

  • name: "influxdb"
    type: "org.influxdb.InfluxDBFactory"
    properties:
    url: "http://localhost:8086"`
    This does not work since this class does not have a constructor which returns an instance of InfluxdDB and I cannot figure out how to specify that I want to address the "connect" method provided in that class. I know that this class references uses the constructors of org.influxdb.impl.InfluxDBImpl to create the desired instances but I don't know either how I could create and pass an Object of type OkHttpClient to that constructor,

Is there a way to address static methods when creating beans ?
What would be the recommended way to achieve the desired behaviour?

Thank you in advance for your help!

@oscerd
Copy link
Contributor

oscerd commented Sep 18, 2023

You can try to create a custom bean like in this example and pass to your route with #bean syntax: apache/camel-kamelets-examples#21 (comment)

@oscerd
Copy link
Contributor

oscerd commented Sep 18, 2023

What runtime are you using?

@2tsheep
Copy link
Author

2tsheep commented Sep 18, 2023

I am using camel-k 1.12.1 and Im running the integrations on a local kubernetes cluster using Docker Desktop 4.22.1 with knative.

I am not sure if I completely understand what the linked example does. It registers a custom class to the bean registry which then allows us to address the defined methods in the class, is that right? Would this also create a connection bean which I need to send data to an influxdb using the influxdb endpoint?

If it is possible I would like to avoid creating custom beans in java and solely rely on yaml dsl.

I'll add this here for maybe a little more clarification:
`
#camel-k: language=yaml dependency=camel-quarkus:influxdb

  • beans:

    • name: "influxdb"
      type: "#ognl:@org.influxdb.InfluxDBFactory@connect"
      properties:
      url: "http://localhost:8086"
  • from:
    uri: "{{source}}"
    ...
    to: "influxdb:influxdb"
    `

@oscerd
Copy link
Contributor

oscerd commented Sep 18, 2023

I think this is not really easy to accomplish, not only in YAML DSL, but also through camel bean support. @davsclaus any idea?

@davsclaus
Copy link
Contributor

@2tsheep
Copy link
Author

2tsheep commented Sep 25, 2023

I apologise for the late reply and thank you very much for the help.

A colleague of mine managed to find a way to solve this solely through YAML DSL. It is possible to address a static method by using the following syntax:

  • beans:
    • name: "influxdbConnectionBean"
      type: org.influxdb.InfluxDBFactory#connect("url", "username","password")

@2tsheep 2tsheep closed this as completed Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants