1.3.4. 簡単な Camel ルートの追加
手順
-
src/main/java/org/acme/
サブフォルダーにRoutes.java
という名前のファイルを作成します。 以下のコードスニペットのように Camel Rest ルートを追加します。
Routes.java
package org.acme; import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.concurrent.CopyOnWriteArrayList; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.rest.RestBindingMode; import io.quarkus.runtime.annotations.RegisterForReflection; public class Routes extends RouteBuilder { private final List<Fruit> fruits = new CopyOnWriteArrayList<>(Arrays.asList(new Fruit("Apple"))); @Override public void configure() throws Exception { restConfiguration().bindingMode(RestBindingMode.json); rest("/fruits") .get() .route() .setBody(e -> fruits) .endRest() .post() .type(Fruit.class) .route() .process().body(Fruit.class, (Fruit f) -> fruits.add(f)) .endRest(); } @RegisterForReflection // Let Quarkus register this class for reflection during the native build public static class Fruit { private String name; public Fruit() { } public Fruit(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public int hashCode() { return Objects.hash(name); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Fruit other = (Fruit) obj; return Objects.equals(name, other.name); } } }