在驼峰路由使用exec组件使用grep进行curl但使用$ {HOSTNAME}无效的grep

问题描述 投票:2回答:1

在驼峰路线中,我使用exec组件使用grep进行curl但使用$ {HOSTNAME}无效的grep,下面是我的驼峰路径。请在此方面需要帮助。

@Component
public class VideoFilesOperationRoute extends RouteBuilder {

    @Value("${scheduler.cronExpression}")
    private String cron;

    @Override
    public void configure() throws Exception {

        from("quartz2://videoFilesOperations/everydayMidnight?cron=" + cron)
                .to("exec:curl?args= --silent http://localhost:4040/ | grep ${HOSTNAME}&useStderrOnEmptyStdout=true")
                .to("bean:videoFilesOperationImpl?method=videoFilesOperation");

    }
}

尝试下面的解决方案,但仍然是同样的问题:

//Tried this first
List<String> args = new ArrayList<>();
args.add("-c");
args.add("curl --silent http://localhost:4040/ | grep ${HOSTNAME}");
from("quartz2://videoFilesOperations/everydayMidnight?cron=" + cron)
.setHeader(ExecBinding.EXEC_COMMAND_ARGS, constant(args))
.to("exec:/bin/sh")
.to("bean:videoFilesOperationImpl?method=videoFilesOperation");


//Tried this next
from("quartz2://videoFilesOperations/everydayMidnight?cron=" + cron)
.to("exec:scripts/curl.sh")
.to("bean:videoFilesOperationImpl?method=videoFilesOperation");
java spring-boot apache-camel
1个回答
1
投票

问题是camel-exec命令参数是以空格分隔的。所以你尝试将curl的输出管道输出到grep不会起作用。

尝试这样的事情:

@Override
public void configure() throws Exception {
    List<String> args = new ArrayList<>();
    args.add("-c");
    args.add("curl --silent http://localhost:4040/ | grep ${HOSTNAME}");

    from("quartz2://videoFilesOperations/everydayMidnight?cron=" + cron)
        .setHeader(ExecBinding.EXEC_COMMAND_ARGS, constant(args))
        .to("exec:/bin/sh");
}

或者你可以将curl&grep命令包装在shell脚本中并让camel-exec调用它。

© www.soinside.com 2019 - 2024. All rights reserved.