标签: spring-camel

端点上没有可用的消费者:Endpoint[direct://LookUpRoute]

我是阿帕奇骆驼的新手。我正在尝试将交换从 java 方法发送到路由,但它给出了“由 org.apache.camel.component.direct.DirectConsumerNotAvailableException:端点上没有可用消费者”错误。我想了解这个错误到底是什么以及我们什么时候收到这个错误?

@EndpointInject(uri = "direct:reportRoute")
private ProducerTemplate templatereportRoute;


public void saveDataFromExchange(Map<String, Object> DataMap){

    List<Map<String, Object>> paramList = new ArrayList<Map<String, Object>>();
    
    List<Map<String, Object>> rows = templatereportRoute.requestBody("direct:reportReport", DataMap, List.class);
Run Code Online (Sandbox Code Playgroud)
<from uri="direct:reportRoute"/>

 <log message="  - ${body}"  loggingLevel="INFO"/>    

<setProperty propertyName="DataMap">
  <simple>${body}</simple>
</setProperty>
Run Code Online (Sandbox Code Playgroud)

apache-camel blueprint-osgi spring-camel

8
推荐指数
1
解决办法
2万
查看次数

如何在Camel路由中使用上下文路径?

我是骆驼新手。我正在 spring-boot 中做一个项目,使用camel作为路由。我注意到,当我去 SwaggerUi 查看 Post 调用的正确功能时,路由的 contextPath 不起作用:

public void configure() {

        restConfiguration().component("servlet").contextPath("service/");

        rest("/ocs")
            .post("/homologation")
                .id(camelRoutesIdConfig.getHomologationRequestRouteId())
                .consumes("application/json")
                .produces("application/json")
                .param()
                    .name("IntegrationRequestDto")
                    .type(RestParamType.body)
                    .required(true)
                    .description("attivazione nuovo contratto sul portale")
                .endParam()
                .to("direct:homologation")

}
Run Code Online (Sandbox Code Playgroud)

如果在 application.yml 中我像这样指定 contextPath ,则不会出现此问题:

camel:
  rest:
    component: servlet
    binding-mode: json
    enable-cors: true
    data-format-property:
      prettyPrint: false
     component:
    servlet:
      mapping:
        context-path: /service/*
Run Code Online (Sandbox Code Playgroud)

当我在一种情况下拨打 Post 电话时,它可以工作,而在路线中的 ContextPath 情况下,它无法识别该命令并给出

{
  "timestamp": "2020-11-22T17:44:26.701+0000",
  "status": 404,
  "error": "Not Found",
  "message": "Not Found",
  "path": "/service/ocs/homologation"
}
Run Code Online (Sandbox Code Playgroud)

为什么会出现这个问题呢?为什么我还被迫在 application.yml 中指定,而不是在路由中仅使用一次?感谢大家提供可能的答案

java routes apache-camel spring-boot spring-camel

7
推荐指数
1
解决办法
3982
查看次数

使用@SpringBootTest进行Spring Boot和Camel测试

我有spring boot app,有1.5.8版本的spring boot。 camel 2.20.1

简单路线:

@Component
public class MyRoute extends RouteBuilder {

  public static final String IN = "file://in";

  public static final String OUT = "file://out";

  @Override
  public void configure() throws Exception {
    from(IN).routeId("myId").to(OUT);
  }
}
Run Code Online (Sandbox Code Playgroud)

Und简单测试:

//@SpringBootTest
public class MyRouteTest extends CamelTestSupport {


      @Produce(uri = MyRoute.IN)
      private ProducerTemplate producerTemplate;

      @EndpointInject(uri = "mock:file:out")
      private MockEndpoint mockEndpointOut;

      @Override
      public String isMockEndpoints() {
        return "*";
      }

      @Test
      public void simpleTest() throws Exception {
        mockEndpointOut.expectedMessageCount(1);
        producerTemplate.sendBody("Test");
        mockEndpointOut.assertIsSatisfied();
      }

      @Override
      protected RoutesBuilder …
Run Code Online (Sandbox Code Playgroud)

java apache-camel spring-boot spring-boot-test spring-camel

6
推荐指数
2
解决办法
6803
查看次数

为什么camel-jackson-starter 中 autoDiscoverObjectMapper 默认为 false?

目前,我们正在将应用程序从 Camel 2.x 迁移到 Camel 3.x,并面临默认情况下JacksonDataFormat不再使用应用程序上下文中的问题。ObjectMapper相反,您需要提供一个属性camel.dataformat.json-jackson.auto-discover-object-mapper=true才能使此功能发挥作用。我不明白为什么这不等于模块true的默认值camel-jackson-starter,这对我来说似乎不合逻辑。也许有人知道这背后的原因?

java apache-camel spring-camel camel-jackson

6
推荐指数
1
解决办法
1959
查看次数

org.apache.camel.NoSuchBeanException:在注册表中找不到 bean:

我有以下路线定义:

@Component
public class CamelRoutes extends RouteBuilder {
    @Override
    public void configure() throws Exception {
           from("seda:second")                   
                .bean("helloWorld?method=smth")    
                .process(exchange -> {
                    System.out.println("Message:" + exchange.getIn().getBody());
                })
                .log("body:${body}");
Run Code Online (Sandbox Code Playgroud)

和以下豆:

public static class HelloWorld {
       public void execute(String str){
           System.out.println("HelloWorld#execute: " + str);
       }
        public void smth(String str){
            System.out.println("HelloWorld#smth: " + str);
        }
    }
Run Code Online (Sandbox Code Playgroud)

但应用程序没有启动。
痕迹:

org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route4 at: >>> Bean[ref:helloWorld?method=smth] <<< in route: Route(route4)[[From[seda:second]] -> [Bean[ref:helloWorld?me... because of No bean could be found in the registry for: helloWorld?method=smth …
Run Code Online (Sandbox Code Playgroud)

java spring apache-camel spring-camel

5
推荐指数
1
解决办法
3万
查看次数

org.apache.camel.NoTypeConversionAvailableException:没有可用于转换类型的类型转换器:

我首先有多部分文件,我想将其发送到骆驼管道并使用原始名称保存该文件。

我的代码:

@Autowired
ProducerTemplate producerTemplate;
...
      producerTemplate.sendBody("seda:rest_upload", multipartFile);
Run Code Online (Sandbox Code Playgroud)

在另一边我有:

from("seda:rest_upload").convertBodyTo(File.class).to("file://rest_files");

我还尝试注册转换器:

@Converter
public class MultiPartFileToFileConvertor {
    @Converter
    public static File toFile(MultipartFile multipartFile) throws IOException {
        File convFile = new File(multipartFile.getOriginalFilename());
        multipartFile.transferTo(convFile);
        return convFile;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我执行代码时,我看到以下堆栈跟踪:

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route2            ] [route2            ] [seda://rest_upload                                                            ] [         3]
[route2            ] [convertBodyTo1    ] [convertBodyTo[java.io.File]                                                   ] [         2]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------

org.apache.camel.InvalidPayloadException: No body available of type: java.io.File but has value: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile@24c9ecc7 of type: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile on: Message[ID-ntkachev-1509013331141-0-13]. …
Run Code Online (Sandbox Code Playgroud)

java spring type-conversion apache-camel spring-camel

5
推荐指数
2
解决办法
3万
查看次数

Apache Camel 的 JsonMappingException

我在骆驼路线上遇到以下异常

Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.apache.camel.converter.stream.InputStreamCache and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:284)
    at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110)
    at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1135)
    at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
    at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
    at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1429)
    at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1158)
Run Code Online (Sandbox Code Playgroud)

骆驼路线:

restConfiguration().producerComponent("http4").host("localhost").port(9080);


    from("direct:getSubscriptions")
        .hystrix()
        .to("rest:get:testendpoint?carrier={carrier}&flightNumber={flightNumber}&origin={origin}&destination={destination}&date={date}")
        .log(">> - ${body}")
        .marshal().json(JsonLibrary.Jackson)
        .split().jsonpathWriteAsString("$.[1]", true)
        .log("${body}");
Run Code Online (Sandbox Code Playgroud)

不确定我这样做是否正确?任何建议将不胜感激

json split apache-camel spring-camel

5
推荐指数
1
解决办法
6904
查看次数

使用bean ref在camel路由中设置标头

 from("direct:myRoute1")
                .bean(new DemoRoute(), "test(Demo,xxx)")
                .end();


 from("direct:myRoute2")
                .bean(new DemoRoute(), "test(Demo,xxx)")
                .end(); 



public interface Shape

@Component
class Circle implements Shape{
}

@Component
class Square implements Shape{}
Run Code Online (Sandbox Code Playgroud)

我想在路线中注入Shape实现 test(Demo,xxx)

  1. setHeader()可以帮助在路由中添加Shape实现.
  2. 除了在骆驼路线中设置标题之外,还有其他选择,因为它有其优点和缺点

在Camel Exchange中设置批量标题的优点和缺点

java apache-camel spring-camel

5
推荐指数
1
解决办法
270
查看次数

Camel从类路径资源读取文件?

我在 Spring Boot 应用程序的“resources/file.txt”的类路径上有一个文件。

我如何在骆驼路线中引用它?

我努力了:

from("file:resource:classpath:?fileName=file.txt") 及其变体。似乎什么都不起作用。

请问这里有什么解决方法吗?

谢谢

apache-camel spring-camel

5
推荐指数
1
解决办法
4725
查看次数

Camel 测试 - 无法创建路由...因为必须在以下位置指定 ref:进程

我写了这条骆驼路线:

@Component
public class FirstRoute extends RouteBuilder {

    private static final String DIRECT_ENDPOINT = "direct:test_direct";
    private static final String HTTP_ENDPOINT = "http:test_http";

    @Autowired
    private URIProcessor uriProcessor;

    @Override
    public void configure() throws Exception {
        restConfiguration().component("servlet").bindingMode(RestBindingMode.json);

        rest("/doTest/").post("/{comp}").to(DIRECT_ENDPOINT);

        test();
    }

    public void test() {        
        from(DIRECT_ENDPOINT).routeId("route_rest")
        .marshal().json(JsonLibrary.Jackson)
        .process(uriProcessor)
        .to(HTTP_ENDPOINT).unmarshal().json(JsonLibrary.Jackson, TestDto.class);

    }


}
Run Code Online (Sandbox Code Playgroud)

效果很好。

我想为这条路线编写一个测试类,所以在测试类中我写道:

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new FirstRoute();
Run Code Online (Sandbox Code Playgroud)

但是当我运行测试时出现错误。

这是错误日志:

org.apache.camel.FailedToCreateRouteException: Failed to create route route_rest at: >>> process[Processor@0x0] <<< in route: Route(route_rest)[[From[direct:testEsenzioneReddito]] -> [Ma... because of ref …
Run Code Online (Sandbox Code Playgroud)

java apache-camel spring-camel

5
推荐指数
0
解决办法
2776
查看次数