如何在quarkus骆驼中使用Apache Camel“ direct”

时间:2019-07-20 18:38:31

标签: apache-camel quarkus

我已经在我的应用程序中添加了io.quarkus:quarkus-camel-core,但是直接启动在本机映像中不起作用。如果我在JVM中运行quarkus,那么它将起作用。

在Github(https://github.com/apache/camel-quarkus/tree/master/extensions/direct)中有一些项目以某种方式表明将来有扩展计划,但是并没有得到官方的支持。

如何让它以最小的努力运行,例如创建自己的扩展项目仅用于直接。如果将现有项目添加到我的Maven pom中,我会遇到不同的Maven坐标问题,最后,本机版本会告诉我重复项。

使Camel中的“直接”语句在quarkus中运行的好方法是什么?

顺便说一句,本机构建有效,即我得到了一个可执行文件,但是直接语句的注入不起作用:

  

“ org.apache.camel.ResolveEndpointFailedException:无法解析   端点:direct:// init归因于:在方案中找不到组件:   直接”

来源: REST端点:

@Path("/hello")
public class GreetingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        ExchangeBuilder exchangeBuilder = new ExchangeBuilder(context);
        Exchange out = template.send("direct:init", exchangeBuilder.build());

        return out.getOut().toString();
    }

CamelRouteBuilder:

public class CamelSyncRouteBuilder extends RouteBuilder {

    static final String HTTP_ROUTE_ID = "http:camel";
    static long[] times = new long[1];

    @Override
    public void configure() throws Exception {
        from("direct:init").routeId(HTTP_ROUTE_ID)
                .setHeader(MyOrderService.class.getName(), MyOrderService::new)
                .setHeader(Filler.class.getName(), Filler::new).process(fill(Filler.class.getName(), "fill"))
                .split(body().tokenize("@"), CamelSyncRouteBuilder.this::aggregate)
                .process(stateless(MyOrderService.class.getName(), "handleOrder")).end().to("log:foo?level=OFF");
    }

pom.xml:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.sap.it.graal</groupId>
  <artifactId>getting-started</artifactId>
  <version>1.0-SNAPSHOT</version>
  <properties>
    <surefire-plugin.version>2.22.0</surefire-plugin.version>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    <quarkus.version>0.19.1</quarkus.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-bom</artifactId>
        <version>${quarkus.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-camel-core</artifactId>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <version>${quarkus.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <systemProperties>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
          </systemProperties>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>     
          <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>${quarkus.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>native-image</goal>
                </goals>
                <configuration>
                  <enableHttpUrlHandler>true</enableHttpUrlHandler>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${surefire-plugin.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
                <configuration>
                  <systemProperties>
                    <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                  </systemProperties>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

2 个答案:

答案 0 :(得分:1)

direct组件即使没有专用扩展名也应立即可用,例如,它用于为jdbc组件(https://github.com/apache/camel-quarkus/tree/master/integration-tests/jdbc)创建集成测试。

您可以分享有关您的项目和设置的更多信息吗?

答案 1 :(得分:0)

我遇到了同样的问题,因为我没有了解骆驼到底是如何工作的。就像在日志中说的那样-您没有提供“直接” URI的组件。因此,您必须添加该组件。 Camel Quarkus extensions中有一个:

<dependency>
  <groupId>org.apache.camel.quarkus</groupId>
  <artifactId>camel-quarkus-direct</artifactId>
</dependency>