org.apache.camel.Consume Java Examples
The following examples show how to use
org.apache.camel.Consume.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Application.java From camel-k-runtime with Apache License 2.0 | 6 votes |
@POST @Path("/load-routes/{name}") @Consume(MediaType.TEXT_PLAIN) @Produces(MediaType.APPLICATION_JSON) public JsonObject loadRoutes(@PathParam("name") String name, String code) throws Exception { final Runtime runtime = Runtime.on(context); final Source source = Sources.fromBytes(name, "js", null, code.getBytes(StandardCharsets.UTF_8)); final SourceLoader loader = new JavaScriptSourceLoader(); final SourceLoader.Result result = loader.load(Runtime.on(context), source); result.builder().ifPresent(runtime::addRoutes); result.configuration().ifPresent(runtime::addConfiguration); loader.load(Runtime.on(context), source); return Json.createObjectBuilder() .add("components", extractComponents()) .add("routes", extractRoutes()) .add("endpoints", extractEndpoints()) .build(); }
Example #2
Source File: Application.java From camel-k-runtime with Apache License 2.0 | 6 votes |
@POST @Path("/load-routes/{name}") @Consume(MediaType.TEXT_PLAIN) @Produces(MediaType.APPLICATION_JSON) public JsonObject loadRoutes(@PathParam("name") String name, String code) throws Exception { final Runtime runtime = Runtime.on(context); final Source source = Sources.fromBytes(name, "yaml", null, code.getBytes(StandardCharsets.UTF_8)); final SourceLoader loader = new YamlSourceLoader(); final SourceLoader.Result result = loader.load(Runtime.on(context), source); result.builder().ifPresent(runtime::addRoutes); result.configuration().ifPresent(runtime::addConfiguration); return Json.createObjectBuilder() .add("components", extractComponents()) .add("routes", extractRoutes()) .add("endpoints", extractEndpoints()) .build(); }
Example #3
Source File: Application.java From camel-k-runtime with Apache License 2.0 | 6 votes |
@POST @Path("/load-routes/{loaderName}/{name}") @Consume(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) public JsonObject loadRoutes(@PathParam("loaderName") String loaderName, @PathParam("name") String name, byte[] code) throws Exception { final SourceLoader loader = context.getRegistry().lookupByNameAndType(loaderName, SourceLoader.class); final Runtime runtime = Runtime.on(context); final Source source = Sources.fromBytes(name, loaderName, null, code); final SourceLoader.Result result = loader.load(Runtime.on(context), source); result.builder().ifPresent(runtime::addRoutes); result.configuration().ifPresent(runtime::addConfiguration); return Json.createObjectBuilder() .add("components", extractComponents()) .add("routes", extractRoutes()) .add("endpoints", extractEndpoints()) .build(); }
Example #4
Source File: Application.java From camel-k-runtime with Apache License 2.0 | 6 votes |
@POST @Path("/load-routes/{name}") @Consume(MediaType.TEXT_PLAIN) @Produces(MediaType.APPLICATION_JSON) public JsonObject loadRoutes(@PathParam("name") String name, String code) throws Exception { final Runtime runtime = Runtime.on(context); final Source source = Sources.fromBytes(name, "xml", null, code.getBytes(StandardCharsets.UTF_8)); final SourceLoader loader = new XmlSourceLoader(); final SourceLoader.Result result = loader.load(Runtime.on(context), source); result.builder().ifPresent(runtime::addRoutes); result.configuration().ifPresent(runtime::addConfiguration); return Json.createObjectBuilder() .add("components", extractComponents()) .add("routes", extractRoutes()) .add("endpoints", extractEndpoints()) .build(); }
Example #5
Source File: CamelBinder.java From statefulj with Apache License 2.0 | 5 votes |
private void addConsumeAnnotation(CtMethod ctMethod, String uri) { MethodInfo methodInfo = ctMethod.getMethodInfo(); ConstPool constPool = methodInfo.getConstPool(); Annotation consume = new Annotation(Consume.class.getName(), constPool); StringMemberValue valueVal = new StringMemberValue(constPool); valueVal.setValue(uri); consume.addMemberValue("uri", valueVal); AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag); attr.addAnnotation(consume); methodInfo.addAttribute(attr); }
Example #6
Source File: RoutingSlipAnnotated.java From camel-cookbook-examples with Apache License 2.0 | 5 votes |
@Consume(uri = "direct:start") @RoutingSlip(delimiter = ",") public List<String> routeMe(String body, @Headers Map<String, Object> headers) { ArrayList<String> results = new ArrayList<String>(); Object slip = headers.get("myRoutingSlipHeader"); if (slip != null) { String[] uris = slip.toString().split(","); Collections.addAll(results, uris); } results.add("mock:oneMore"); return results; }
Example #7
Source File: DynamicRouterAnnotated.java From camel-cookbook-examples with Apache License 2.0 | 5 votes |
/** * Returns the next endpoint to route a message to or null to finish routing. * This implementation leverages Camel's * <a href="http://camel.apache.org/bean-integration.html">Bean injection</a> * to pass parts of the Camel Exchange to the method for processing. This can * help the code be easier to maintain as it does not need the extra boilerplate * code for extracting the relative data from the Exchange. * <p></p> * This implementation stores an int property with the message exchange that is * used to drive the routing behavior. This method will be called from multiple * threads, one per message, so storing message specific state as a property is * a good strategy. * * @param body the IN message converted to a String using Camel Bean injection * @param properties the properties map associated with the Camel Exchange * @return next endpoint uri(s) to route to or <tt>null</tt> to finish routing */ @Consume(uri = "direct:start") @DynamicRouter(delimiter = ",") public String routeMe(String body, @ExchangeProperties Map<String, Object> properties) { LOG.info("Exchange.SLIP_ENDPOINT = {}, invoked = {}", properties.get(Exchange.SLIP_ENDPOINT), properties.get(PROPERTY_NAME_INVOKED)); // Store a property with the message exchange that will drive the routing // decisions of this Dynamic Router implementation. int invoked = 0; Object current = properties.get(PROPERTY_NAME_INVOKED); // property will be null on first call if (current != null) { invoked = Integer.valueOf(current.toString()); } invoked++; properties.put(PROPERTY_NAME_INVOKED, invoked); if (invoked == 1) { return "mock:a"; } else if (invoked == 2) { return "mock:b,mock:c"; } else if (invoked == 3) { return "direct:other"; } else if (invoked == 4) { return "mock:result"; } // no more, so return null return null; }
Example #8
Source File: InventoryUpdater.java From camelinaction with Apache License 2.0 | 4 votes |
@Consume(uri = "jms:partnerInventoryUpdate") public void updateInventory(Inventory inventory) { jdbc.execute(toSql(inventory)); }
Example #9
Source File: InventoryUpdaterAnnotatedWithProduce.java From camelinaction with Apache License 2.0 | 4 votes |
@Consume(uri = "jms:partnerInventoryUpdate") public void updateInventory(Inventory inventory) { jdbc.execute(toSql(inventory)); partnerAudit.sendBody(inventory); }
Example #10
Source File: InventoryUpdaterAnnotatedWithProduceInterface.java From camelinaction with Apache License 2.0 | 4 votes |
@Consume(uri = "jms:partnerInventoryUpdate") public void updateInventory(Inventory inventory) { jdbc.execute(toSql(inventory)); partnerAudit.audit(inventory); }
Example #11
Source File: ConsumeMdb.java From camel-cookbook-examples with Apache License 2.0 | 4 votes |
@Consume(uri = "activemq:queue:sayhello") public String onMyMessage(String message) { LOG.info("Message = {}", message); return "Hello " + message; }