我正在尝试为骆驼路线设置测试。我的测试路线读取一个二进制文件并将其发送到翻译器 bean,返回一个 POJO。现在,我想对 POJO 进行一些断言,以确保其中的值与已知值匹配。我认为标准的东西。在我见过的示例中,主体似乎始终是 String 或原始类型,并且可以对其进行简单的断言。然而,就我而言,它是一个对象,所以我想以某种方式获取该对象。
到目前为止,这是我尝试过的:
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:///path/to/dir/of/test/file/?noop=true")
.bean(TranslatorBean.class)
.to("mock:test").end();
}
};
}
@Test
public void testReadMessage() throws Exception {
MockEndpoint endpoint = getMockEndpoint("mock:test");
endpoint.whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Object body = exchange.getIn().getBody();
assertIsInstanceOf(MyPOJO.class, body);
MyPOJO message = (MyPOJO) body;
assertEquals("Some Field", someValue, message.getSomeField());
// etc., etc.
}
});
//If I don't put some sleep …Run Code Online (Sandbox Code Playgroud) 我想要一个像 my.company.bindy 这样的包,其中有几个类都用 Bindy 注释进行注释。然后我想要 Camel 路线可以将 CSV 解组为这些类型之一。我已经完成了所有工作,但是如果包中有多个带有 Bindy 带注释的类,则解组会失败。这是因为 Bindy 试图将 CSV 行解组到包中的每个类中。并且特定的行不会正确地编组到多个类中。我的数据格式在 Spring 中声明如下:
<bean class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat">
<property name="packages" value="my.company.bindy"/>
</bean>
Run Code Online (Sandbox Code Playgroud) 在 Apache Camel 2.14 的 Metrics 组件中,我尝试使用简单表达式语言设置计数器的名称,但似乎指标组件没有使用它。
我试过了 :
from("direct:foo").routeId("routeFoo")
.to("metrics:counter:${id}")
Run Code Online (Sandbox Code Playgroud)
和
from("direct:foo").routeId("routeFoo")
.to("metrics:counter:"+ simple("${id}"))
Run Code Online (Sandbox Code Playgroud)
但在这两种情况下,计数器的名称都设置为 ${id}。
是否可以在此组件 URI 中使用表达式语言?
谢谢
编辑 :
添加标题即可完成这项工作:
.setHeader(MetricsConstants.HEADER_METRIC_NAME, simple("${id}.${header.operationName}"))
Run Code Online (Sandbox Code Playgroud)
但直接在 URI 中使用 SEL 会更方便。
我正在尝试在我的 Apache Camel 项目中进行日志记录。我已经尝试过以下方法:
VM args 在 Eclipse 中,我添加了以下 VM args: -Dlog4j.configuration=log4j-/resources/log4j.properties -Dlog4j.debug=true
类路径上的属性文件 我已仔细检查 log4j.properties 是否在类路径上
我的java看起来像这样:
Logger LOG = LoggerFactory.getLogger(CamelMain.class);
LOG.info("starting");
Run Code Online (Sandbox Code Playgroud)
我的 pom 包含以下内容:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-beanio</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
任何想法为什么日志记录不起作用?
更新/解决方案
我需要添加以下内容:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我有一个假设的场景:让 \xe2\x80\x99s 假装我有一个 Apache Camel Websocket 服务器,并且 I\xe2\x80\x99m 允许许多 Websocket 连接。每个客户端连接都需要与一个 ClientID 关联。ClientID 是由新连接通过 InitConnection json 消息获取的,其中 ClientID 是消息的成员。问题是:camel 是否可以将 websocket 实例与 ClientID 关联起来以执行基于内容的路由?
\n我正在使用 Apache Camel 2.13.2 并尝试连接到用户名中包含特殊字符的 sftp。用户名类似于“XXX\XX-XXXXXXX”。最后的骆驼 URL 被转换成如下所示,并且身份验证失败。有人可以阐明如何处理用户名中的这些特殊字符吗?
Endpoint[sftp://XXX%5CXX-xxxxxxx@99.999.99.99:22//folder_Test/?binary=true&consumer.bridgeErrorHandler=true&delay=15000&idempotent=true&idempotentKey=%24%7Bfile%3Aname%7D-%24%7Bfile%3Asize%7D-%24%7Bfile%3Amodified%7D&include=.*Test.*&maxMessagesPerPoll=30&password=xxxxxx&pollStrategy=%23FTPPollingConsumerPollStrategy&readLock=changed&sendEmptyMessageWhenIdle=true&stepwise=false&throwExceptionOnConnectFailed=true]
Run Code Online (Sandbox Code Playgroud)
以下是我在日志中看到的异常。
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot connect to sftp://XXX\XX-XXXXX@99.999.99.99:22
at org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:143)
at org.apache.camel.component.file.remote.RemoteFileConsumer.connectIfNecessary(RemoteFileConsumer.java:154)
at org.apache.camel.component.file.remote.RemoteFileConsumer.recoverableConnectIfNecessary(RemoteFileConsumer.java:145)
at org.apache.camel.component.file.remote.RemoteFileConsumer.prePollCheck(RemoteFileConsumer.java:55)
at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:106)
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:512)
at org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:115)
... 15 more
Run Code Online (Sandbox Code Playgroud)
使用 fileZilla 或 Apache FTP 实用程序时,sftp 的凭据相同。
需要使用 SpringBoot 将 Camel 和 MyBatis 与应用程序集成。SpringBoot 为 Camel 和 MyBatis 提供了开箱即用的支持。还提供Camel和MyBatis SpringBoot启动器。
但是,当我尝试将 Spring Boot 应用程序与 Camel 和 MyBatis 集成时,它失败了。
我正在使用基于 Java DSL 的 Camel Route。还使用 Mybatis Spring 启动依赖项。注释映射器,在 application.properties 文件中添加数据库属性。我期望发生的事情:1)SpringBoot 在启动时设置数据源和映射器、sqlsessionfactory。2)接下来调用Camel-MyBatis消费者,(1)中完成的设置将允许Camel成功使用mybatis进行数据库调用。
我创建了 spring 带注释的配置类并用它来创建/获取 DataSource bean。
我怎样才能让Camel使用这个dataSource bean?如何告诉 Camel 使用新构建的 SQL 会话工厂,而不是尝试从配置文件构建?
在 github 中创建了示例应用程序,它使用内存数据库(h2)
示例应用程序
获取 NPE Consumer[mybatis://getClaimInfo?statementType=SelectOne] 失败的轮询端点:Endpoint[mybatis://getClaimInfo?statementType=SelectOne]。将在下次投票时再试一次。引起的:[org.apache.ibatis.exceptions.PersistenceException -
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.4.0.jar:3.4.0]
Run Code Online (Sandbox Code Playgroud)
在 org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:100) ~[mybatis-3.4.0.jar:3.4.0] 在 org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession( DefaultSqlSessionFactory.java:47) ~[mybatis-3.4.0.jar:3.4.0]
我目前正在尝试在 AWS 上将 Apache Camel 与 S3 存储桶结合使用。目前,我们的代码库的每个环境都有 1 个存储桶(例如:开发存储桶、e2e 存储桶、生产存储桶)。
我们希望使用 1 个存储桶,其中包含多个目录,以避免混乱并巩固空间。然后我们可以将 Camel 指向端点内的一个文件夹来监听(似乎可行)。在尝试配置时,这已经变得非常成问题。Camel 似乎期望它可以连接的每个端点都有一个存储桶。
有人可以阐明这是否可行,或者是否有必要每个端点拥有 1 个存储桶?Camel文档没有说明是否可以。
我有一个对 Rest Web 服务的 AJAX 请求,其中包含自定义标头“登录”。
\n\n这是我的其余配置:
\n\nrestConfiguration()\n.component("netty4-http")\n.bindingMode(RestBindingMode.json)\n.dataFormatProperty("prettyPrint", "true")\n.enableCORS(true)\n.corsAllowCredentials(true)\n.corsHeaderProperty("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, login")\n.contextPath(contextPath).host(host).port(port);\nRun Code Online (Sandbox Code Playgroud)\n\n我收到对 OPTIONS 预检请求的 200 响应,但“登录”标头不是 Access-Control-Allow-Headers,并且我的浏览器从不发送实际请求。
\n\n另外,我还没有在我的路径中为 cors 进行任何配置。
\n\n这是我的请求标头
\n\n\n\n\n用户代理:Mozilla/5.0(Windows NT 10.0;Win64;x64;rv:58.0)\n Gecko/20100101 Firefox/58.0
\n\n接受:\n text/html,application/xhtml+xml,application/xml;q=0.9, / ;q=0.8
\n\n接受语言:fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
\n\n接受编码:gzip、deflate
\n\n访问控制请求方法:GET
\n\n访问控制请求标头:登录
\n\n来源: http: //127.0.0.1:8081
\n\n不饱和脂肪酸:1
\n\n连接:保持活动状态
\n
和响应标头:
\n\n\n内容长度:0
\n\n接受:\n text/html,application/xhtml+xml,application/xml;q=0.9, / ;q=0.8
\n\n接受编码:gzip、deflate
\n\n接受语言:fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
\n\n访问控制允许凭据: true
\n\n访问控制允许标头:来源、接受、X-Requested-With、\n 内容类型、访问控制请求方法、\n …
我正在尝试在 Spring Boot 项目中将 Apache Artemis 与 Apache Camel 连接起来。
当我将 Spring Boot 版本从 1.5.9.RELEASE 升级到 2.2.2.RELEASE 时遇到问题。下面是我正在使用的 POM 和 Java 文件:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.learncamel</groupId>
<artifactId>activemq-learncamel-spring-boot</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>learncamel-spring-boot</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<camel-version>2.20.1</camel-version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.20.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--jdbc-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
<version>${camel-version}</version>
</dependency> …Run Code Online (Sandbox Code Playgroud)