当前位置: 首页 > 知识库问答 >
问题:

英菲尼斯潘发布将骆驼应用程序从独立移植到骆驼夸克

姚自强
2023-03-14

我正在尝试向camel quarkus移植一个使用Infinispan组件的独立camel应用程序。这是路线

package org.federico.swiftref.portfolio.route;

import org.apache.camel.BindToRegistry;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.infinispan.InfinispanConstants;
import org.apache.camel.component.infinispan.InfinispanOperation;
import org.apache.camel.converter.jaxb.JaxbDataFormat;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.support.builder.Namespaces;
import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
//import org.federico.swiftref.portfolio.model.SepaplusSchemaImpl;

/**
 * A Camel Java DSL Router
 */
public class LoadIbanPlus extends RouteBuilder {

    @BindToRegistry("cacheContainerConfiguration")
    Configuration configuration;

    private static final String JAXB_CONTEXT_PATH = "org.federico.swiftref.sepaplus.ibanplus.jaxb";
    private static final String STAX_TOKENIZER_PATH = "//ibanplus_v3";

    public LoadIbanPlus() {
        configuration = new ConfigurationBuilder()
                .security()
                .authentication()
                .saslMechanism("DIGEST-MD5")
                .username("myuser")
                .password("myuser")
                .addServer()
                .host("localhost")
                .port(11222)
                .version(org.infinispan.client.hotrod.ProtocolVersion.PROTOCOL_VERSION_25)
                .addContextInitializer(new SepaplusSchemaImpl())
                .build();
    }

    /**
     * Let's configure the Camel routing rules using Java code...
     */
    public void configure() {

        DataFormat jaxb = new JaxbDataFormat(JAXB_CONTEXT_PATH);

        from("file:src/data/ibanplus?noop=true")
                .split().xtokenize(STAX_TOKENIZER_PATH, 'w', new Namespaces("", ""))
                .unmarshal(jaxb)
                .log("${body}")
                .to("dozer:mapIban?mappingFile=ibanMapping.xml&targetModel=org.federico.swiftref.portfolio.model.Iban")
                .setHeader(InfinispanConstants.OPERATION, constant(InfinispanOperation.PUT))
                .setHeader(InfinispanConstants.KEY, simple("${body.getRecordKey()}"))
                .setHeader(InfinispanConstants.VALUE, simple("${body}"))
                .log("${body.getInstitutionName()}")
                .to("infinispan:sepaplus-cache?cacheContainerConfiguration=#cacheContainerConfiguration");
    }

}

这是独立的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>org.federico.swiftref</groupId>
  <artifactId>swiftref-files-portfolio</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>

  <name>A Camel Route</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <log4j2-version>2.13.3</log4j2-version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <!-- Camel BOM -->
      <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-bom</artifactId>
        <version>3.8.0</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>

    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-main</artifactId>
    </dependency>

    <!-- logging -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <scope>runtime</scope>
      <version>${log4j2-version}</version>
    </dependency>

    <!-- testing -->
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-infinispan</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-stax</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-jaxb</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-dozer</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-bean</artifactId>
    </dependency>
    <dependency>
      <groupId>org.infinispan.protostream</groupId>
      <artifactId>protostream-processor</artifactId>
      <version>4.3.5.Final</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.federico.swiftref.sepaplus</groupId>
      <artifactId>ibanstructure-jaxb-classes</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.federico.swiftref.sepaplus</groupId>
      <artifactId>exclusionlist-jaxb-classes</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.federico.swiftref.sepaplus</groupId>
      <artifactId>ibanplus-jaxb-classes</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <build>
    <defaultGoal>install</defaultGoal>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>

      <!-- Allows the example to be run via 'mvn camel:run' -->
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <logClasspath>true</logClasspath>
          <mainClass>org.federico.swiftref.portfolio.MainApp</mainClass>
        </configuration>
      </plugin>

    </plugins>
  </build>

</project>

这是夸克斯应用程序的pom

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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>org.federico.swiftref</groupId>
  <artifactId>swiftref-files-portfolio-quarkus</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <properties>
    <compiler-plugin.version>3.8.1</compiler-plugin.version>
    <maven.compiler.parameters>true</maven.compiler.parameters>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <quarkus-plugin.version>1.12.0.Final</quarkus-plugin.version>
    <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
    <quarkus.platform.version>1.12.0.Final</quarkus.platform.version>
    <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>${quarkus.platform.artifact-id}</artifactId>
        <version>${quarkus.platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-main</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-file</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-jaxb</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-stax</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-dozer</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-bean</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-infinispan</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-arc</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>org.federico.swiftref.sepaplus</groupId>
      <artifactId>ibanstructure-jaxb-classes</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.federico.swiftref.sepaplus</groupId>
      <artifactId>exclusionlist-jaxb-classes</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.federico.swiftref.sepaplus</groupId>
      <artifactId>ibanplus-jaxb-classes</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <version>${quarkus-plugin.version}</version>
        <extensions>true</extensions>
        <executions>
          <execution>
            <goals>
              <goal>build</goal>
              <goal>generate-code</goal>
              <goal>generate-code-tests</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${compiler-plugin.version}</version>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <systemPropertyVariables>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            <maven.home>${maven.home}</maven.home>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${surefire-plugin.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
                <configuration>
                  <systemPropertyVariables>
                    <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                    <maven.home>${maven.home}</maven.home>
                  </systemPropertyVariables>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <properties>
        <quarkus.package.type>native</quarkus.package.type>
      </properties>
    </profile>
  </profiles>
</project>

独立运行时,应用程序工作正常;在quarkus内部运行时,应用程序不连接到服务器,并获得此异常。

2021-02-27 10:48:57,472 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile dev): org.infinispan.client.hotrod.exceptions.HotRodClientException:Request for messageId=5 returned server error (status=0x85): java.lang.SecurityException: ISPN006017: Unauthorized 'PUT' operation
        at org.infinispan.client.hotrod.impl.protocol.Codec20.checkForErrorsInResponseStatus(Codec20.java:333)
        at org.infinispan.client.hotrod.impl.protocol.Codec20.readHeader(Codec20.java:172)
        at org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder.decode(HeaderDecoder.java:139)
        at org.infinispan.client.hotrod.impl.transport.netty.HintedReplayingDecoder.callDecode(HintedReplayingDecoder.java:94)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
        at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:792)
        at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:475)
        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)

2021-02-27 10:48:57,533 INFO  [io.quarkus] (Quarkus Main Thread) swiftref-files-portfolio-quarkus stopped in 0.060s

我意识到这应该是不同的配置,因为例外保持相同,即使服务器关闭。当服务器关闭或我故意设置了错误的凭据时,独立应用程序根本不会执行路由。它在执行构造函数时停止。

任何想法?可能cacheContainerConfiguration必须以不同的方式构建,当在QUARKUS生态系统中运行时?或者其他图书馆不见了?

例如,我注意到在夸克斯中,原型流处理器依赖不能包含在pom中,也许它已经包含在骆驼-夸克斯-无限泛的东西中,如果包含,它会产生冲突。干杯

共有1个答案

干高歌
2023-03-14

更新最终我想出了如何!我已经从路由中删除了ConfigurationBuilder,因为Quarkus需要设置以下属性的application.properties文件中的所有这些详细信息

quarkus.infinispan-client.server-list=localhost:11222
quarkus.infinispan-client.auth-username=myuser
quarkus.infinispan-client.auth-password=myuser
quarkus.infinispan-client.sasl-mechanism=DIGEST-MD5
quarkus.infinispan-client.use-auth=true

我还更改了现在更简单的InfinispanendpointURL。它只包含缓存的名称。

...
.to("infinispan:sepaplus-cache");

多亏了Quarkus,所有的代码现在绝对更整洁了

 类似资料:
  • 我设置了一个endpoint,如下所示: 我用骆驼石英2.22.2和石英1.8.6 下面是从关闭到启动上下文的日志。

  • 问题内容: 我尝试对Apache骆驼路线进行junit测试。像这样的东西: 构建器类的定义如下 “ myExportRouteProcessor”类仅从JPA存储库中获取一些数据,并将结果放入路由。我想要的是在测试类中触发此路由,以检查整个过程是否正确完成。当前,处理器未启动。我该怎么办? 问题答案: 您可以使用AdviceWithRouteBuilder#replaceFromWith直接替换测

  • 我试着为阿帕奇骆驼路线做一个jUnit测试。类似于这样: builder类的定义如下 myExportRouteProcencer类只是从JPA存储库中获取一些数据,并将结果放入路由。我想要的是在测试类中触发此路由,以检查整个过程是否正确完成。目前,处理器没有被触发。我应该做些什么?

  • 我正在使用带有Apache骆驼的Spring Boot。我正在从控制器调用路由。一旦路由完成,控制就会返回控制器。我正在VerifyLimitProcess和批准限制处理器中生成响应。如果我没有在路由中提供窃听配置,控制器会按预期检索标头和正文。但如果我在路由中引入窃听,控制器会将标头和正文接收为null。如果有人指出我需要做什么,以便我可以在选择语句中引入两个处理器的窃听配置,即VerifyLi

  • 我有一条小路线,我想使用自定义的重新传递策略来重复向endpoint发送消息,但这种行为非常奇怪。看起来,重新交付政策只是在重复一个错误。我试图将所有交换发送到路由的开头,但策略不起作用,因为每次都在创建: 我做错了什么?当错误发生时,我想以间隔重复我的请求。我的骆驼版本是2.6 日志:

  • 我正在遵循位于Camel MyBatis Integration guide的安装指南。我使用的是Service Mix 5.0.1。我使用了安装spring mybatis的功能,它支持3.2.4。释放我的SqlMapConfig文件只包含有关TypeHandler和TypeAlias的信息。 当我开启服务混合,然后启动我的应用程序,我收到以下堆栈跟踪: ...还有50个 我的Bean定义如下: