我会澄清我的问题。
我有一个任务来集成两个系统:一个为 html 提供服务的前端和一个为前端提供数据的后端。后端有一个非常大的 REST api,所以我必须使用多个路由。我计划使用单个骆驼上下文并将所有路线包装到其中。
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<from uri="direct:data"/>
<to uri="ahc:http://localhost/data"/>
<!--And so on. More than 70 routes-->
</camelContext>
Run Code Online (Sandbox Code Playgroud)
然后,我计划按照隐藏中间件文章中的建议,在服务方法上使用 @Produce 注释来调用路由
public interface Service {
String data();
}
public class MyBean {
@Produce(uri = "direct:data")
protected Service producer;
public void doSomething() {
// lets send a message
String response = producer.data();
}
}
Run Code Online (Sandbox Code Playgroud)
据我了解从这里和这里获取的信息,我最终会在我的应用程序中增加 70 个线程(每条路线一个)。我担心它会导致严重的性能下降,而后端 api 会增长,线程数也会随之增长。这是正确的吗?如果这是真的,我如何避免这种情况?据我了解,在这种情况下我不能使用 ExecutorService 线程池。
提前感谢您的任何回答。
我正在尝试设置从文件系统到在 ActiveMQ 上运行的 JMS 目标的基本路由。我的 ActiveMQ 服务器使用默认设置在本地主机上运行,并且在“ activemq/queue/TestQueue ”中有一个可用的队列。所以我编写了以下 Java 路由:
public static void main(String args[]) throws Exception {
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"vm://localhost");
context.addComponent("jms",
JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
public void configure() {
from("file:D:\\camel\\in").to(
"activemq:queue:TestQueue");
}
});
context.start();
Thread.sleep(10000);
context.stop();
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,引发了以下异常:
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[activemq:queue:TestQueue] <<< in route: Route(route1)[[From[file:D:\camel\in]] -> [To[activemq:queue... because of Failed to resolve endpoint: activemq://queue:TestQueue due to: …Run Code Online (Sandbox Code Playgroud) 在Bluemix中使用Apache Camel Framework有什么限制吗?代码将使用Spring Framework和Apache Camel API的混合?
from("seda:myqueue?size=2&blockWhenFull=true").process(sleep());
private Processor sleep() {
return new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
System.out.println(curTime() + " Going for sleep sleepid=" + body );
Thread.sleep(5000l);
System.out.println(curTime() + " Done sleep sleepid=" + body );
}
};
for (Integer i = 0; i <5; i++) {
Exchange exchange = new DefaultExchange(context);
exchange.setPattern(ExchangePattern.InOnly);
exchange.getIn().setHeader("header", i);
exchange.getIn().setBody(i.toString());
System.out.println("sending msg to seda");
Exchange send = template.send("seda:myqueue",exchange);
System.out.println("done:"+i);
}
Run Code Online (Sandbox Code Playgroud)
“ BlockWhenFull”未确认,即如果大小设置为 2 并且我在循环中发送 3 条消息,正文为“1”、“2”和“3”,那么我只收到“1”和“2”的睡眠消息,我猜即使我将“ BlockWhenFull”设置为 …
我想将一个 zip 文件解压缩到一个名为 zip 文件的文件夹中。例如 original/abc.zip 应该解压到 import/abc/
我现在所拥有的确实解压缩了指定文件夹中的文件。
from("file:" + "</path/to/original>" + "?noop=true").noAutoStartup().routeId("xxx").split(new ZipSplitter()).streaming()
.convertBodyTo(String.class).to("file:" + "</path/to/import>");
Run Code Online (Sandbox Code Playgroud)
如何从“from”文件中获取文件名并将其放入“to”部分?
我是骆驼的新手,所以任何帮助都会受到欢迎。谢谢!
我正在使用 Apache Camel (2.15.x) HTTP4 组件并访问外部 Web 服务。有时回应是200,有时是422,有时是500。对于200s,我很好。我的问题是我想在获得时重试,500但在获得422. 在这两种情况下,它都是一个HttpOperationFailedException. 我查看了 Camel 文档并在 Google 上搜索过,但没有找到任何有关如何执行此操作的示例。任何建议或 URL,将不胜感激。
谢谢。
我正在使用 Jboss-fuse-6.3 和外部 Apache-activemq-5.15.2。我在一个队列上绑定了 50 个消费者,在 Active MQ 门户的“活动消费者”页面上,我注意到所有 50 个消费者都已绑定,但队列上的消息分布并不相同。
附上屏幕截图。在会话 ID“1”上,排队消息计数约为 1010 条,但在其他消费者会话上,排队消息仅为 10 条。
我正在对来自 Apache Camel Route 的消息进行排队。下面是我的蓝图 xml(我做错了什么吗)
<bean class="org.apache.activemq.spring.ActiveMQConnectionFactory" id="connectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
<property name="userName" value="admin"/>
<property name="password" value="admin"/>
<property name="trustAllPackages" value="true"/>
</bean>
<bean class="org.apache.camel.component.jms.JmsConfiguration" id="jmsConfig">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<bean class="org.apache.activemq.camel.component.ActiveMQComponent" id="activemq">
<property name="configuration" ref="jmsConfig"/>
</bean>
<bean class="org.apache.activemq.spring.ActiveMQConnectionFactory" id="connectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
<property name="userName" value="admin"/>
<property name="password" value="admin"/>
<property name="trustAllPackages" value="true"/>
</bean>
<bean class="org.apache.camel.component.jms.JmsConfiguration" id="jmsConfig">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<bean class="org.apache.activemq.camel.component.ActiveMQComponent" id="activemq">
<property …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Camel Spring(Camel 2.20.2;Spring 4.3.14)配置外部化到application.properties属性文件中。该属性文件包含以下内容:
net.sender1.port = 47000
net.sender1.address = 127.255.255.255
Run Code Online (Sandbox Code Playgroud)
该application.properties文件驻留在src/main/resources目标 jar 中并由 maven-shade-plugin 复制到目标 jar。
我的骆驼上下文如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="..." xmlns:xsi="..." xmlns:camel="..." xsi:schemaLocation="...">
<bean id="udpSender1" class="com.foo.MyUDPSender">
<constructor-arg type="java.lang.String" value="${net.sender1.address}" />
<constructor-arg type="java.lang.Integer" value="${net.sender1.port}" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
...
</camelContext>
</beans>
Run Code Online (Sandbox Code Playgroud)
当我启动应用程序时,出现以下错误:
WARN | 2018-02-23 09:50:25,324 | [main] ClassPathXmlApplicationContext.refresh - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'udpSender1' defined in class path resource [META-INF/spring/camel-context.xml]: …
apache Camel 中的过滤器和选择有什么区别?
from("direct:a")
.choice()
.when(header("foo").isEqualTo("bar"))
.to("direct:b")
.when(header("foo").isEqualTo("cheese"))
.to("direct:c")
.otherwise()
.to("direct:d");
Run Code Online (Sandbox Code Playgroud) 可能看起来像一个微不足道的问题,但不幸的是无法让它工作
这是代码
from("direct:START")
.process( (ex) -> {
List<Integer> pages = IntStream.range(1,5).boxed().collect(Collectors.toList());
ex.getOut().setBody( pages );
})
.split(body())
.parallelProcessing()
.to("http://someurl?page=${body}");
--> Get the collective body here
Run Code Online (Sandbox Code Playgroud)
如何获得这份工作!
我已经实现了一个 apache 骆驼调度程序,它以固定的时间间隔执行任务。现在要执行的任务数量已经增加,我很困惑是否继续使用相同的方法或创建多个路线构建器。
现在的方法是,调用数据库获取所有配置的其余详细信息,并在 routerbuilder 的 confuguire 方法中迭代并构建路由。
代码示例:
public void configure() {
for(int i=0; i< list.length;i++){
from("quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1")
.setBody().simple("Current time is ${header.firedTime}")
.to("stream:out");
}
}
Run Code Online (Sandbox Code Playgroud)
这里我只有一个路由构建器类,配置方法具有创建多个路由的 for 循环。
我想在骆驼路线下面进行测试。我在网上找到的所有示例都有以文件开头的路由,在我的情况下,我有一个 spring bean 方法,它每隔几分钟就会被调用一次,最后消息被转换并移动到 jms 和审计目录。
我对这条路线的写测试知之甚少。我目前在我的测试用例中的所有内容是
Mockito.when(tradeService.searchTransaction()).thenReturn(dataWithSingleTransaction);
from("quartz2://tsTimer?cron=0/20+*+8-18+?+*+MON,TUE,WED,THU,FRI+*")
.bean(TradeService.class)
.marshal()
.jacksonxml(true)
.to("jms:queue:out-test")
.to("file:data/test/audit")
.end();
Run Code Online (Sandbox Code Playgroud) 我想使用camel将.xml文件创建到csv文件中.这是我的代码
CamelContext context = new DefaultCamelContext();
from("file://Input?fileName=test.xml").marshal().csv().to("file://test?fileName=test.csv");
context.start();
Run Code Online (Sandbox Code Playgroud)
但它不会在所需的文件夹"test"中创建任何文件.
apache-camel ×13
java ×6
jboss ×2
concurrency ×1
ibm-cloud ×1
integration ×1
rest ×1
routes ×1
split ×1
spring ×1
types ×1
zip ×1