dependencies {
compile 'org.apache.camel:camel-spring-boot-starter:2.18.4'
compile 'org.apache.camel:camel-groovy:2.18.4'
compile 'org.apache.camel:camel-stream:2.18.4'
compile 'org.codehaus.groovy:groovy-all:2.4.11'
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
@Component
class DirectRoute extends RouteBuilder{
@Override
void configure () throws Exception {
from ("direct:in") //tried stream:in also
.to ("stream:out")
}
}
然后我有一个驱动程序bean来尝试调用路由
@Component
public class HelloImpl implements Hello {
@Produce(uri = "direct:in")
private ProducerTemplate template;
@Override
public String say(String value) throws ExecutionException, InterruptedException {
assert template
println "def endpoint is : " + template.getDefaultEndpoint()
return template.sendBody (template.getDefaultEndpoint(), value)
}
}
最后,在springboot应用程序类中,我添加了这样一个命令行运行程序,它从spring上下文获取bean,并调用say方法。我使用的是groovy,所以我只是向命令行运行程序传递了一个闭包。
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
//return closure to run on startup - just list the beans enabled
{args ->
println("Let's inspect the beans provided by Spring Boot:")
String[] beanNames = ctx.getBeanDefinitionNames()
Arrays.sort(beanNames)
for (String beanName : beanNames) {
println(beanName)
}
println("call the direct:start route via the service")
Hello service = ctx.getBean("helloService")
def result = service.say("William")
println "service returned : $result "
}
}
当我运行我的应用程序时,我会打印出所有的bean名称(这没关系),但是当我通过producer模板调用direct:in时,我会得到这个错误(org.apache.camel.component.direct.directConsumerNotaVailableException)如下所示。
我原本期望路由被触发,发送的名称会看到它到达输出流--但这是我得到的结果。
Caused by: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[ID-MONSTER-PC2-58911-1496920205300-0-2]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1795) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:677) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:515) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:511) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:163) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.ProducerTemplate$sendBody$0.call(Unknown Source) ~[na:na]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) [groovy-all-2.4.11.jar:2.4.11]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) [groovy-all-2.4.11.jar:2.4.11]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) [groovy-all-2.4.11.jar:2.4.11]
at services.HelloImpl.say(HelloImpl.groovy:29) ~[main/:na]
at services.Hello$say.call(Unknown Source) ~[na:na]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) [groovy-all-2.4.11.jar:2.4.11]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) [groovy-all-2.4.11.jar:2.4.11]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) [groovy-all-2.4.11.jar:2.4.11]
at application.Application$_commandLineRunner_closure1.doCall(Application.groovy:47) ~[main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) ~[groovy-all-2.4.11.jar:2.4.11]
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) ~[groovy-all-2.4.11.jar:2.4.11]
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) ~[groovy-all-2.4.11.jar:2.4.11]
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022) ~[groovy-all-2.4.11.jar:2.4.11]
at groovy.lang.Closure.call(Closure.java:414) ~[groovy-all-2.4.11.jar:2.4.11]
at org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:54) ~[groovy-all-2.4.11.jar:2.4.11]
at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:124) ~[groovy-all-2.4.11.jar:2.4.11]
at com.sun.proxy.$Proxy44.run(Unknown Source) ~[na:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
... 10 common frames omitted
Caused by: org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: direct://in. Exchange[ID-MONSTER-PC2-58911-1496920205300-0-2]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:55) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:529) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:497) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:365) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:497) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:225) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:144) ~[camel-core-2.18.4.jar:2.18.4]
at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:161) ~[camel-core-2.18.4.jar:2.18.4]
我做错了什么?为什么在“direct:in”上的生产者模板调用(也尝试过流输入,但有同样的问题)不起作用?我以为.to(“stream:out”)是消费者。
在这一点上收到的任何指示或建议
我有一个关于我的问题的更新:
@SpringBootApplication
注释。所以是的,未经修饰的它只扫描子包。ScanBasePackages=
或ScanBaseClasses=
参数,但是,当我尝试对单个类进行扫描时,它似乎以任何方式扫描整个目录,并同时抓取其他目录。@configuration
注释的其他类来生成bean或使用基本的@component
。@component
注释的Camel路由,它们将在camelContext中为您自动配置。开始
而不是开始
。所以在我的commandLineRunner中,我必须开始获取spring注入的camelContext,并且必须自己启动它,完成后退出它。我有点吃惊,因为我以为SpringBootStarter会自动启动camelContext,但它似乎没有。org.apache.camel.component.direct.directConsumerNotaVailableException
异常的问题就会消失,并且开始工作--至少我正在尝试的示例是这样的。修改后的结构如下所示:
package com.softwood.application
import groovy.util.logging.Slf4j
import org.apache.camel.CamelContext
import org.springframework.beans.factory.annotation.Autowired
import com.softwood.services.Hello
/**
* Created by willw on 07/06/2017.
*/
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean
@Slf4j //inject logger
@SpringBootApplication (scanBasePackages = ["com.softwood"]) //forces scan at parent
// same as @Configuration @EnableAutoConfiguration @ComponentScan with 'defaults' e.g. sub packages
public class Application {
@Autowired
ApplicationContext ctx
@Autowired
CamelContext camelContext
public static void main(String[] args) {
SpringApplication.run(Application.class, args)
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
//return closure to run on startup - just list the beans enabled
{args ->
println("Let's inspect the beans provided by Spring Boot:")
String[] beanNames = ctx.getBeanDefinitionNames()
Arrays.sort(beanNames)
for (String beanName : beanNames) {
println(beanName)
}
/* when component scan is working - bean routes are added
automatically to camel context via springBoot, however you do have to start
the camel context, yourself
*/
println "camelCtx has following components : " + camelContext.componentNames
println "camelCtx state is : " + camelContext.status
println "starting camel context"
camelContext.start()
println "camelCtx state now is : " + camelContext.status
//log.debug "wills logging call "
println("call the direct:start route via the service")
Hello service = ctx.getBean("helloService")
def result = service.say("William")
println "service returned : $result "
println "sleep 5 seconds "
sleep (5000)
println "stop camel context"
camelContext.stop()
println "camelCtx state now is : " + camelContext.status
}
}
}
package com.softwood.services
/**
* Created by willw on 07/06/2017.
*/
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate
import org.springframework.stereotype.Component;
import java.util.concurrent.ExecutionException
@Component
public class HelloImpl implements Hello {
@Produce(uri = "direct:in") /* ?block=true */
private ProducerTemplate template
@Override
public String say(String value) throws ExecutionException, InterruptedException {
assert template
println "def endpoint is : " + template.getDefaultEndpoint()
//Future future = template.asyncSendBody(template.getDefaultEndpoint(), value)
//return future.get()
return template.sendBody (template.getDefaultEndpoint(), value)
}
}
TimedRoute只是对自身进行排序,而不需要在其中调用任何模板
package com.softwood.camelRoutes
/**
* Created by willw on 07/06/2017.
*/
import org.apache.camel.builder.RouteBuilder
import org.springframework.stereotype.Component
@Component
class TimedRoute extends RouteBuilder {
@Override
void configure () throws Exception {
from ("timer:foo")
.to ("log:com.softwood.application.Application?level=WARN")
}
}
我的简单no-op文件路由不工作(还没有),不知道为什么。我怀疑我的文件配置不对;需要玩一些游戏。
package com.softwood.camelRoutes
import org.apache.camel.builder.RouteBuilder
import org.springframework.stereotype.Component
/**
* Created by willw on 08/06/2017.
*/
@Component
class FileNoOpRoute extends RouteBuilder{
@Override
void configure () throws Exception {
from ("file:../com.softwood.file-inbox?recursive=true&noop=true&idempotent=true")
.to ("file:../com.softwood.file-outbox")
}
}
然而,基本的东西不起作用,最小的骆驼正在做一些事情,而之前我只是有一个例外,什么也没有。
我试图升级骆驼cxf从2.15.0到2.18.2和得到以下异常。 JDK版本是1.8 使用SOAP服务的CXFendpoint如下 endpoint id=“OTAHotelAvailability\u OTA\u 2012B\u endpoint”uri=“cxf:/HotelAvailabilityPort?wsdlURL=${wsdlpath}/test.wsdl 下一条从CXFendpoi
在Camel(JBoss Fuse,特别是Spring DSL)中,我试图用Camel简单表达式读取布尔值。 ${body}是一个有效的非空POJO,'fielda'是另一个嵌套POJO,fieldb是一个布尔值。Fielda可以为空,但body不能为空。 当fielda为非null时,我能够读取值而不会出错。 从各种文档来源(Apache Camel Simple、JBoss Fuse)可以看出
我正在制作一个小应用程序,我可以使用spring-boot保存用户详细信息。我创建了实体及其相应的存储库。当我发出帖子请求以添加用户的用户对象的id时,该id在保存到数据时为空base.Thisid在MySQL中自动生成(自动增量)。从POST请求中,我得到3个字段,即用户名、电子邮件、密码。用户类包含字段id、用户名、电子邮件、密码。我添加了注释 作为 id 字段。构造函数是 我的用户服务类 我
我用的是Springboot和junit,我想用Powermock来模拟静态类,添加了Powermock后,单元测试通过IntelliJ IDEA运行得很好,但是当我在terminal下运行时,它会抛出ApplicationContextException:无法启动web服务器\n无法启动嵌入式Tomcat 我的基本测试类: 测试类: 似乎无法启动springboot嵌入的tomcat,但要使用P
因此,我使用服务器(google-app-engine)在客户端应用程序上进行身份验证。当我使用JavaFX、Webview或HttpsURLConnection时,一切都很好,它们连接起来了,但是当我使用HttpClient时,它会抛出以下错误 javax.net.ssl.sslpeerunverifiedexception:peer未在sun.security.ssl.sslsessionim
嘿StackOverflow社区, 关于抛出异常。一般什么时候抛出和异常,什么时候抓取? 假设我遇到了这样的情况,我不得不退出,因为发生了一些问题,我无法从它中恢复过来。我是投还是接? 我现在就这么做: 这样做对吗?如果我只是抛出异常会更合适吗?对不起,我是例外的新手:)