使用 Apache Camel 发出 API 请求时未在控制台上打印日志消息
Log message is not printing on console while making API request using Apache Camel
我在控制台上打印日志消息时遇到问题。我只需要提出 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)
在您的配置中设置 camel.springboot.main-运行-controller=true 属性。例如在 application.properties.
应该向“direct:postCall”发送消息以启动此路由。您可以将其更改为“timer://foo?repeatCount=1”,它会自动启动 (https://camel.apache.org/components/3.14.x/timer-component.html)。
您是否启用了 Camel 日志记录?
<logger name="org.apache.camel" level="DEBUG" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
请注意,Camel 将更改其上下文中对象的日志记录 class。
我在控制台上打印日志消息时遇到问题。我只需要提出 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)
在您的配置中设置 camel.springboot.main-运行-controller=true 属性。例如在 application.properties.
应该向“direct:postCall”发送消息以启动此路由。您可以将其更改为“timer://foo?repeatCount=1”,它会自动启动 (https://camel.apache.org/components/3.14.x/timer-component.html)。
您是否启用了 Camel 日志记录?
<logger name="org.apache.camel" level="DEBUG" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
请注意,Camel 将更改其上下文中对象的日志记录 class。