Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Grape Component
Available as of Camel 2.16 Grape component allows you to fetch, load and manage additional jars when Setting up class loaderGrape requires using Groovy class loader with the
import static org.apache.camel.component.grape.GrapeComponent.grapeCamelContext; ... CamelContext camelContext = grapeCamelContext(new DefaultCamelContext()); You can also set up the Groovy class loader used be Camel context by yourself: camelContext.setApplicationContextClassLoader(new GroovyClassLoader(myClassLoader)); URI formatGrape component supports only producer endpoints. grape:defaultMavenCoordinates For example the following snippet loads Camel FTP component: from("direct:loadCamelFTP"). to("grape:org.apache.camel/camel-ftp/2.15.2"); You can also specify the Maven coordinates by sending them to the endpoint as the exchange body: from("direct:loadCamelFTP"). setBody().constant("org.apache.camel/camel-ftp/2.15.2"). to("grape:defaultMavenCoordinates"); Adding the Grape component to the projectMaven users will need to add the following dependency to their <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-grape</artifactId> <version>x.y.z</version> <!-- use the same version as your Camel core version --> </dependency> Default payload typeBy default Camel Grape component operates on the String payloads: producerTemplate.sendBody("grape:defaultMavenCoordinates", "org.apache.camel/camel-ftp/2.15.2"); But of course Camel build-in type conversion API can perform the automatic data type transformations for you. In the example below Camel automatically converts binary payload into the String:
producerTemplate.sendBody("grape:defaultMavenCoordinates", "org.apache.camel/camel-ftp/2.15.2".getBytes()); HeadersThe following headers are recognized by the Grape component:
Loading components at runtimeIn order to load the new component at the router runtime, just grab the jar containing the given component: ProducerTemplate template = camelContext.createProducerTemplate(); template.sendBody("grape:grape", "org.apache.camel/camel-stream/2.15.2"); template.sendBody("stream:out", "msg"); Loading processors bean at runtimeIn order to load the new processor bean with your custom business login at the router runtime, just grab the jar containing the required bean: ProducerTemplate template = camelContext.createProducerTemplate(); template.sendBody("grape:grape", "com.example/my-business-processors/1.0"); int productId = 1; int price = template.requestBody("bean:com.example.PricingBean?method=currentProductPrice", productId, int.class)
Loading deployed jars after Camel context restartAfter you download new jar, you usually would like to have it loaded by the Camel again after the restart of the
import static org.apache.camel.component.grape.GrapeEndpoint.loadPatches; ... camelContext.addRoutes( new RouteBuilder() { @Override public void configure() throws Exception { loadPatches(camelContext); from("direct:loadCamelFTP"). to("grape:org.apache.camel/camel-ftp/2.15.2"); } });
Managing the installed jarsIf you would like to check what jars have been installed into the given from("netty-http4:http://0.0.0.0:80/patches"). setHeader(GrapeConstats.GRAPE_COMMAND, constant(CamelGrapeCommand.listPatches)). to("grape:list"); Connecting the to the route defined above using the HTTP client returns the list of the jars installed by Grape component: $ curl http://my-router.com/patches grape:org.apache.camel/camel-ftp/2.15.2 grape:org.apache.camel/camel-jms/2.15.2 If you would like to remove the installed jars, so these won't be loaded again after the context restart, use the from("netty-http4:http://0.0.0.0:80/patches"). setHeader(GrapeConstats.GRAPE_COMMAND, constant(CamelGrapeCommand.clearPatches)). setBody().constant("Installed patches have been deleted."); |