-
Notifications
You must be signed in to change notification settings - Fork 344
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
Running YAML code #1579
Comments
A fix for this will be available in the next release of the camel-k-runtime, however storing arbitrary code in a CR is not the recommended approach and best is to leverage jitpack or publish your artifact to a maven repo |
Just to make sure I understand, is there no yaml way in which I could specify a custom processor? The yaml code I wrote there my be wrong, in particular this part:
I understand the process step is supported and I'm wondering what can I actually pass to it if not a custom class. |
In other words, what would be the correct syntax for passing a processor class to the process step. |
The current implementation only accept a reference to a Processor stored in the registry so to reference a class you should use the bean dsl, however in the next release there should be support for that syntax too (the property it’s probably not be named class) |
Got it. That's helpful to know! |
What is the approximate timeline for the next release? |
Do you have an example of how this can be done using YAML? What's unclear to me is how this method:
can be called from yaml (where bindBeans binds MyProcessor to the Camel registry). |
You can add @BindToRegisty on the MyProcessor class |
I did that and then added this to my route:
I got an error saying:
|
Note to the above comment: I am doing this in an all Camel example and I was able to get it to work by not using the
How do I transition from this to using the annotation instead? Or is that possible only with camel k ? |
Yeah that would work as you use the Java API. But ideally we should make it possible to auto register beans via that annotation (or if you use cdi annotation with quarkus enabled). Also for what's it work, you can also register via properties camel.beans.myProcessor=#class:com.foo.MyProcessor |
So you mean doing something like this:
? |
What's the YAML side code for using the reference? |
I've been recommending to use something like: - from:
uri: "direct:route"
steps:
- bean:
bean-type: org.apache.camel.k.loader.yaml.support.MyUppercaseProcessor
- to: "mock:route" does that work for you ? |
You need to bind a processor to the context with what @davsclaus described and the using the - from:
uri: "direct:route"
steps:
- process:
ref: "myProcessor"
- to: "mock:route" The processor need to be bound to the context, i.e. by using an additional class, like: public class MyConfigurer {
@BindToRegistry
public myProcessor() {
return e -> { ... };
}
} And the run it like:
btw, we have also a gitter room and a mailing list for general discussions, whereas here is to report issues. [1] https://gitter.im/apache/camel-k |
Thank you for the detailed explanation. I'm working on getting it work right now. A small issue occurs when I try to run this command:
I get:
It seems to happen when I pass 2 inputs. Passing each one of those files individually does not result in that error. |
Ah you can specify the name via |
I guess maybe Kamel CLI should just compute the name from the 1st file |
The |
I am extremely close to getting this to work. A quick question: MyProcessor class uses other classes, defined in separate files. How do I tell kamel about those dependencies? I tried passing the JAVA files to the to "kamel run" but that didn't work. |
I’d suggest to use jitpack or similar solution for that |
I see, for now I just put all the classes into the file containing MyConfigurer and that seems to have been fine although not an ideal solution. |
Does MyProcessor require any annotation as Now that I have no more compilation errors I get:
which looks like a Camel specific problem. I suspect my reference to MyProcessor isn't quite correct.
And my configuration class looks like this:
Am I missing some annotation on the MyProcessor class? ( |
It looks like at the time of binding the bean to the registry MyProcessor class is not found.
|
|
@doru1004 I'm honestly lost about what you are doing. So it seems you have both a As already stated there is an issue in referencing a class by name if the class is provided as a CR (i.e. using camel-k is not a generic build system so adding arbitrary classes to the |
What I am trying to do is have a working application using Camel K. I have managed to do a Java only application. What I would now want to do is rewrite the Camel integration in Yaml. Some initial features that I want to exercise are:
I would like to do this from YAML to see how that can be done using YAML instead of Camel Java code. In this particular issue I am trying to handle point 2. It seems that the problematic part is being able to include processor part. This is my call right now after you telling me that the --property is not required:
routes contains this:
Registry configurer file contains this:
After eliminating the
|
That error is probably about a wrong YAML indentation, as per the YAML guide, each step is represented by YAML map that has a single entry where the field name is the EIP name. |
Here an example of a working code: - from:
uri: "timer:clock"
parameters:
period: "1000"
steps:
- set-body:
constant: "foo"
- process:
ref: "toUpper"
- to: log:info import org.apache.camel.Processor;
import org.apache.camel.BindToRegistry;
public class MyConfigurer {
@BindToRegistry
public Processor toUpper() {
return e -> e.getMessage().setBody(
e.getMessage().getBody(String.class).toUpperCase()
);
}
} tested on OpenShift with the following command:
|
Thank you so much!! Thanks a lot for the patience. I managed to get it to work!! :) After taking out the |
Hey @lburgazzoli, thank you for your example. I'm trying out the same code and commands with my camel-k installation, and I get this error:
Just have the 2 files as it is and running the same command:
|
@sidharthramesh I think this is no longer a valid way because some classloading changes introduced in the latest Camel versions. |
I am trying to transform a Camel route with a simple processor into a yaml version of itself.
I have my processor in a different file MyProcessor.java.
I have tried writing something like this:
But that is a guess and when I do
kamel run
it doesn't actually work:Are there any examples out there which invoke a processor as one of the steps?
The text was updated successfully, but these errors were encountered: