-
Notifications
You must be signed in to change notification settings - Fork 352
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
Example Request: CamelJmsToFileExample.java #1079
Comments
Hi @RnD-John I've tried to create an example myself (hopefully one that will also help you), since I have been trying to understand how to handle dependencies on packages such as org.apache.camel.component.jms. Typically these would be declared in pom.xml for automatic download by maven The sample I've tried is just to take the camel-k Sample.java and to begin to import packages that relate to your JMS interest. Using the following code, I see the sample pod fail to run properly `import org.apache.camel.builder.RouteBuilder; public class Sample extends RouteBuilder { The error I see in the POD log follows So clearly camel-k is complaining about the following dependency:
Camel-K team, what am I missing here? How do I make use of a component such as camel-jms? @nicolaferraro do you have some guidance for us? |
@davesargrad - When attempting to run a similar test to what you describe, I received the same dependency errors. I also tried to run the camel based example without explicitly requesting the packages (assuming that camel-k may automatically include them for me). That results in unknown symbol errors. I thought my approach might be fundamentally flawed so I just posted it as a feature request. Thank you for the help. -John |
Camel K only detects components in the route DSL, eg like to("jms:xxx") etc. Java import statements are "just noise", and if you add a import for a component that are unused like you do, then you get this error, unless you tell Camel K to add camel-jms as dependecy from the command line arguments. |
Thanks @davsclaus Assume for example, that I need the following:
How would I invoke kamel to build an integrationplatform that contains the proper dependency? A more complete example includes the use of something such as the ActiveMQConnectionFactory
|
The following code works when running only inside camel... I'm trying to reduce this to a camel-k footprint
Note: also replace |
This is what I have tried:
The error that shows up in the camel-k-kit builder is: |
Looks liek the GAV is not in the right format, try with:
note the : between groupId and artifactId |
Wow!! That worked! |
The only problem with the running route is access to the camel context. The code I am trying to use:
|
I think it is getContext() |
@lburgazzoli Incrementally closer. |
looks like it lacks one of the spring classes, thus I do not know which artifact provides it, likely to be spring-core |
Yeah you need all of the JARs for the activemq-client, as its using the JMS client, so you should have that as dependency, and also maybe one of the connection pools. You can use the activemq component instead of jms as its for ActiveMQ 5.x. Where you can say -d camel-activemq to tell it to add this component which should come with the JMS Client and connection pool et all. |
Thanks guys. Great to have your feedback. |
@lburgazzoli my PR #1067 with AMQP examples cover the usage of JMS client with Qpid, but the manage of ConnectionFactory apply to any other component using that type of configuration. |
You guys gave me what I needed to get this working. The following command line successfully runs the JMS integration
Sample.java
I was able to receive data from a real ActiveMQ service. |
Yeah and we are also working on fixing so camel-activemq works nicer OOTB So all you need is to just set Then it comes with all dependencies included as well |
@davesargrad et all, |
Question: Background: using the command: on the file: import javax.jms.ConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory; public class BasicAMQ extends RouteBuilder {
} I get the error: How do I pass my connection factory URI as an argument? |
Hi @RnD-John @nicolaferraro perhaps you have some insights on how a parameter can be passed into the "route code". The "my.uri" above is a perfect example of something that should not be hard-coded. I'd think its easy to pass this in on the "kamel" command line. |
@davesargrad I was out of the office for a few days; however, I still don't have a great solution for this. The best solution I have come up with is to utilize file io to read the desired values from a from a file on the disk. In general, I'd still like to see what @nicolaferraro or others recommend in terms of potential 'native' support. |
Native support will come with properties when we switch to Camel 3.0.1 (next version is expected to support Camel 3.0.0). For the time being a possible solution is to use env variables:
And:
It's more a workaround waiting for property-based configuration, but it should work. |
You can also use public class BasicAMQ extends RouteBuilder {
@PropertyInject("my.uri")
String uri;
....
} Then you should be able to provide |
Hi @lburgazzoli Its not in the newest javadoc. |
camel-core as been modularized in camel 3, the javadoc for the annotation is here: https://www.javadoc.io/doc/org.apache.camel/camel-api/latest/index.html |
Thanks @lburgazzoli !! Good to know |
@lburgazzoli, using the @PropertyInject Method is throwing the following error:
I updated my script as follows: import javax.jms.ConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory; public class BasicAMQ extends RouteBuilder
} I run with the command: |
property inject do not require {{}} |
using the values as keys directly also throws the error... |
@lburgazzoli, The PropertyInject method is desirable because everything can come from command line properties or from a config map. I'd still like to get this method to work if possible. @nicolaferraro, In the mean time, I tested the environment variable method and that worked as expected.
|
So I have a route like: import org.apache.camel.PropertyInject;
import org.apache.camel.builder.RouteBuilder;
public class Sample extends RouteBuilder {
@PropertyInject("my.url")
String url;
@Override
public void configure() throws Exception {
from("timer:tick")
.setBody().constant(url)
.log("${body}");
}
} The I do run it with:
And what I see in my toute is:
So the properties binding works. I think your issue is that the connection factory is instantiated at class constructions, you should move it to the |
Good clean example... Ty |
per @lburgazzoli
This fixes the issue. Thank you for the assistance. For those interested, the new code is as follows:
Run via:
|
Please provide a JMS to File example that runs on camel-K.
The regular camel example is here: https://github.com/apache/camel/tree/master/examples/camel-example-jms-file
Thank you,
-John
The text was updated successfully, but these errors were encountered: