6.7.2. Camel Java 路由
创建 camel 上下文并以编程方式声明 apns 组件
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
ApnsServiceFactory apnsServiceFactory = new ApnsServiceFactory();
apnsServiceFactory.setCertificatePath("classpath:/certificate.p12");
apnsServiceFactory.setCertificatePassword("MyCertPassword");
ApnsService apnsService = apnsServiceFactory.getApnsService(camelContext);
ApnsComponent apnsComponent = new ApnsComponent(apnsService);
camelContext.addComponent("apns", apnsComponent);
return camelContext;
}
[[APNS-ApnsProducer-iOStargetdevicedynamicallyconfiguredviaheader:"CamelApnsTokens"]] ApnsProducer - iOS 目标设备通过标头 "CamelApnsTokens"
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:test")
.setHeader(ApnsConstants.HEADER_TOKENS, constant(IOS_DEVICE_TOKEN))
.to("apns:notify");
}
}
}ApnsProducer - iOS 目标设备通过 uri 静态配置
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:test").
to("apns:notify?tokens=" + IOS_DEVICE_TOKEN);
}
};
}ApnsConsumer
from("apns:consumer?initialDelay=10&delay=3600&timeUnit=SECONDS")
.to("log:com.apache.camel.component.apns?showAll=true&multiline=true")
.to("mock:result");