gpt4 book ai didi

java - 我的 Apache Camel 处理器不工作

转载 作者:行者123 更新时间:2023-12-01 11:39:29 28 4
gpt4 key购买 nike

我正在尝试使用称为处理器Apache Camel接口(interface),但遇到了一些困难。我预计消息 1) 发送到 JBoss Fuse 应用程序服务器中的 ActiveMQ 队列,2) 由 Camel 处理器处理,然后 3) 发送到源代码中指定的不同队列。现在发生的情况是主打印中的 SOP 语句和日志记录中的一些错误消息,但程序没有将任何内容发送到队列。

这是我的代码:

/* create a Camel processor */ 

package foo;


import org.apache.camel.Processor;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;


public class MyOwnProcessor implements Processor {


//main
public static void main(String[] args) {

System.out.println("Starting main method in MyOwnProcessor.java");

RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("QueueA").processRef("MyOwnProcessor").to("QueueB");
}
};

System.out.println("main is done.");

} //end main

public void process(Exchange exchange) {
System.out.println("Hello the process was executed.");

String s = exchange.getIn().getBody(String.class);
exchange.getIn().setBody("The body of the message is: " + s);

} //end process method




} //end class

这是当前输出:

启动MyOwnProcessor.java中的main方法

SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder”。SLF4J:默认为无操作(NOP)记录器实现SLF4J:参见http://www.slf4j.org/codes.html#StaticLoggerBinder了解更多详情。

主要完成了。

最佳答案

试试这个,

public static void main(String args[]) throws Exception {
// create CamelContext
CamelContext context = new DefaultCamelContext();

// connect to embedded ActiveMQ JMS broker
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"tcp://localhost:61616");
context.addComponent("jms",
JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

// add our route to the CamelContext
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("jms:queue:QueueA")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
String s = exchange.getIn().getBody(String.class);
System.out.println("The body of the message is: " + s);
}
}).to("jms:queue:QueueB");
}
});

// start the route and let it do its work
context.start();
Thread.sleep(10000);

// stop the CamelContext
context.stop();
}

关于java - 我的 Apache Camel 处理器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29661393/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com