[GitHub] [camel-k] doru1004 opened a new issue #1579: Running YAML code

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 opened a new issue #1579: Running YAML code

GitBox

doru1004 opened a new issue #1579:
URL: https://github.com/apache/camel-k/issues/1579


   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:
   
   ```
   - from:
       uri: "timer:tick"
       parameters:
         period: "1000"
       steps:
         - process:
             class: MyProcessor
         - to: "log:info"
   ```
   
   But that is a guess and when I do `kamel run` it doesn't actually work:
   
   ```
   [1] Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> process[Processor@0x0] <<< in route: Route(route1)[From[timer://tick?period=1000] -> [process[Pro... because of ref must be specified on: process[Processor@0x0]
   [1] at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:393)
   [1] at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:117)
   [1] at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:374)
   [1] at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:348)
   [1] at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2617)
   [1] at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
   [1] at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2450)
   [1] at org.apache.camel.support.service.BaseService.start(BaseService.java:111)
   [1] at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2467)
   [1] at org.apache.camel.k.main.ApplicationRuntime$MainAdapter.doStart(ApplicationRuntime.java:206)
   [1] at org.apache.camel.support.service.BaseService.start(BaseService.java:115)
   [1] at org.apache.camel.main.MainSupport.run(MainSupport.java:83)
   [1] at org.apache.camel.k.main.ApplicationRuntime.run(ApplicationRuntime.java:70)
   [1] at org.apache.camel.k.main.Application.main(Application.java:42)
   [1] Caused by: java.lang.IllegalArgumentException: ref must be specified on: process[Processor@0x0]
   [1] at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:171)
   [1] at org.apache.camel.reifier.ProcessReifier.createProcessor(ProcessReifier.java:39)
   [1] at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:766)
   [1] at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:511)
   [1] at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:391)
   ```
   
   Are there any examples out there which invoke a processor as one of the steps?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] lburgazzoli commented on issue #1579: Running YAML code

GitBox

lburgazzoli commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650318327


   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


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650320236


   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:
   
   ```
   - process:
             class: MyProcessor
   ```
   
   I understand the process step is supported and I'm wondering what can I actually pass to it if not a custom class.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650322514


   In other words, what would be the correct syntax for passing a processor class to the process step.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] lburgazzoli commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

lburgazzoli commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650323419


   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)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650323903


   Got it. That's helpful to know!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650324660


   What is the approximate timeline for the next release?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650671589


   Do you have an example of how this can be done using YAML? What's unclear to me is how this method:
   
   ```
   bindBeans(camelContext.getRegistry());
   ```
   
   can be called from yaml (where bindBeans binds MyProcessor to the Camel registry).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] davsclaus commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

davsclaus commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650724285


   You can add @BindToRegisty on the MyProcessor class


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650801582


   I did that and then added this to my route:
   
   ```
   .to("bean:MyProcessor")
   ```
   
   I got an error saying:
   
   ```
   No bean could be found in the registry for: MyProcessor
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650805380


   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 `@BindToRegistry` annotation but by doing this:
   
   ```
   camelContext.getRegistry().bind("MyProcessor", new MyProcessor());
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 edited a comment on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 edited a comment on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650805380


   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 `@BindToRegistry` annotation but by doing this:
   
   ```
   camelContext.getRegistry().bind("MyProcessor", new MyProcessor());
   ```
   
   How do I transition from this way of doing this to using the annotation instead? Or is that possible only with camel k ?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 edited a comment on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 edited a comment on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-650805380


   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 `@BindToRegistry` annotation but by doing this:
   
   ```
   camelContext.getRegistry().bind("MyProcessor", new MyProcessor());
   ```
   
   How do I transition from this to using the annotation instead? Or is that possible only with camel k ?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] davsclaus commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

davsclaus commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-651068216


   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
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-651127032


   So you mean doing something like this:
   
   ```
   kamel run --property camel.beans.myProcessor=#class:com.foo.MyProcessor
   ```
   
   ?
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-651134532


   > 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,
   
   What's the YAML side code for using the reference?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] lburgazzoli commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

lburgazzoli commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-651136182


   I've been recommending to use something like:
   
   ```yaml
   - from:
       uri: "direct:route"
       steps:
         - bean:
             bean-type: org.apache.camel.k.loader.yaml.support.MyUppercaseProcessor
         - to: "mock:route"
   ```
   
   does that work for you ?
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] lburgazzoli commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

lburgazzoli commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-651139598


   > > 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,
   >
   > What's the YAML side code for using the reference?
   
   You need to bind a processor to the context with what @davsclaus described and the using the `ref` property of the `process` step, something like:
   
   ```yaml
   - 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:
   
   ```java
   public class MyConfigurer {
       @BindToRegistry
       public myProcessor() {
           return e -> { ... };
       }
   }
   ```
   
   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
   [2] https://camel.apache.org/community/mailing-list


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] lburgazzoli edited a comment on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

lburgazzoli edited a comment on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-651139598


   > > 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,
   >
   > What's the YAML side code for using the reference?
   
   You need to bind a processor to the context with what @davsclaus described and the using the `ref` property of the `process` step, something like:
   
   ```yaml
   - 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:
   
   ```java
   public class MyConfigurer {
       @BindToRegistry
       public myProcessor() {
           return e -> { ... };
       }
   }
   ```
   
   And the run it like:
   
       kamel run integration.yaml MyConfigurer.java
   
   
   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
   [2] https://camel.apache.org/community/mailing-list


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [camel-k] doru1004 commented on issue #1579: Running YAML code

GitBox
In reply to this post by GitBox

doru1004 commented on issue #1579:
URL: https://github.com/apache/camel-k/issues/1579#issuecomment-651273188


   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:
   
   ```
   kamel run integration.yaml MyConfigurer.java
   ```
   
   I get:
   
   ```
   Error: unable to determine integration name
   ```
   
   It seems to happen when I pass 2 inputs. Passing each one of those files individually does not result in that error.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


12