-1
我必須在activemq的消費者端集成駱駝。我已經設置了activemq並嘗試配置駱駝(使用java DSL)的消費語言,但它不適合我。以下是代碼:通過Apache Camel獲取消息?
public class TestConsumer {
static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
static String subject = "Test-AMQ";
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
BrokerService broker = new BrokerService();
//broker.addConnector(url);
//broker.setBrokerName("localhost");
broker.start();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?create=false&waitForStart=10000");
context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new Routes());
context.start();
}
}
class Routes extends RouteBuilder {
@Override
public void configure() throws Exception {
from("jms:"+new TestConsumer().subject).process(new Processor() {
@Override
public void process(Exchange arg0) throws Exception {
System.out.println("Camel Test Message: " + arg0.toString());
}
});
}
}
「Test-AMQ」是AMQ隊列名稱 –
「不起作用」是什麼意思?你收到一個例外嗎? –
另外'vm:// localhost'使用嵌入的代理。 –