使用Apache Camel发出API请求时,控制台上未打印日志消息

trnvg8h3  于 2022-11-07  发布在  Apache
关注(0)|答案(3)|浏览(327)

我在控制台上打印日志消息时遇到了问题。我只需要发出API请求。如果我遇到任何问题,有人能帮助我吗?

@Service
public class SftpWatcherRoute extends RouteBuilder {

  @Override
  public void configure() {

    from("direct:postCall")
        .process(exchange -> exchange.getIn().getBody())
        .setHeader(Exchange.HTTP_METHOD, constant("POST"))
        .setHeader("Content-Type",constant("application/json"))
        .to("http://localhost:8080/api/v1/start")
        .process(exchange -> log.info("The response code is: {}", exchange.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))).
        end();
  }
}

下面是上面的代码打印的日志。但是,我没有看到我想在控制台上打印的日志消息。

2021-12-27 12:51:50.099  INFO 82161 --- [           main] com.SftpFileWatcher             : Started SftpFileWatcher in 7.406 seconds (JVM running for 8.463)
2021-12-27 13:41:44.621  INFO 82161 --- [ionShutdownHook] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.14.0 (camel-1) shutting down (timeout:45s)
2021-12-27 13:41:44.626  INFO 82161 --- [ionShutdownHook] o.a.c.impl.engine.AbstractCamelContext   : Routes stopped (total:1 stopped:1)
2021-12-27 13:41:44.626  INFO 82161 --- [ionShutdownHook] o.a.c.impl.engine.AbstractCamelContext   :     Stopped route2 (direct://postCall)
2021-12-27 13:41:44.628  INFO 82161 --- [ionShutdownHook] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.14.0 (camel-1) shutdown in 7ms (uptime:49m54s)
acruukt9

acruukt91#

应该发送一条消息到“direct:postCall”以启动此路由。您可以将其更改为“timer://foo?repeatCount=1”,它将自动启动(https://camel.apache.org/components/3.14.x/timer-component.html)。

4nkexdtk

4nkexdtk2#

在您的配置中设置camel.springboot.main-run-controller=true属性。例如在application.properties中。

0lvr5msh

0lvr5msh3#

是否已启用Camel日志记录?

<logger name="org.apache.camel" level="DEBUG" additivity="false">
    <appender-ref ref="STDOUT" />
</logger>

请注意,Camel将更改其上下文中对象的日志记录类。

相关问题