如何使用带有自定义参数

时间:2017-06-07 20:18:45

标签: java spring stream cloud task

我能够运行下面提到的Spring云流,它从rabbitmq接收消息,转换为tasklaunch请求并使用Task-laucher-local触发任务。这完全没问题。

  

stream create task-stream-1 --definition" source:rabbit   --rabbit.queues = AspWorkflow --spring.rabbitmq.username = RabbitAdmin --spring.rabbitmq.password = admin --spring.rabbitmq.host = localhost --spring.rabbitmq.port = 5672 | tasklaunchrequest-transform --uri = maven://com.workflows.task:CloudTaskJavaExec:1.0-SNAPSHOT --command-line-arguments =' - executablePath = D:\ Documents \ Official \ Platform-X \ Execs \ SimpleJavaProgram-1.0-SNAPSHOT的.jar'   --spring.rabbitmq.username = RabbitAdmin --spring.rabbitmq.password = admin --spring.rabbitmq.host = localhost --spring.rabbitmq.port = 5672 | task-launcher-local --rabbit.queues = AspWorkflow - -spring.rabbitmq.username = RabbitAdmin --spring.rabbitmq.password = admin --spring.rabbitmq.host = localhost --spring.rabbitmq.port = 5672" stream deploy task-stream-1 --properties" app.source.rabbit.spring.cloud.stream.bindings.output.binder = rabbit,app.tasklaunchrequest-transform.spring.cloud.stream.bindings.input。粘合剂=兔,app.tasklaunchrequest-transform.spring.cloud.stream.bindings.output.binder =兔,app.task推出-local.spring.cloud.stream.bindings.input.binder =兔"

但是我没有直接在部署时间内传递Uri和Command行参数,而是希望从传入消息中获取这些参数,然后启动请求。

我创建了一个TaskLaunchRequest并将其提供给接收器的输入队列,但我仍然无法通过运行时参数传递来实现我需要的行为。

我的示例TaskLaunchRequest如下所示

{
  "uri": "maven://com.workflows.task:CloudTaskJavaExec:1.0-SNAPSHOT",
  "commandlineArguments": [
    "--executablePath=D:\\Documentsts\\Official\\Platform-X\\Execs\\SimpleJavaProgram-1.0-SNAPSHOT.jar"
  ],
  "environmentProperties": {

  },
  "deploymentProperties": {

  }
}

请帮助解决此问题。

1 个答案:

答案 0 :(得分:0)

我认为你应该使用TaskLaunchRequest-transform

使用任务启动程序启动任务的另一个选项是使用Tasklaunchrequest-transform处理器创建流,以将消息有效负载转换为TaskLaunchRequest。 < / p>

您应该像TasklaunchrequestTransformProcessorConfiguration一样实现自己的处理器,并从消息中设置tasklaunchrequest的命令行参数,而不是传递属性。

示例代码(不是完整代码)

@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Object setupRequest(Object message) {
    Map<String, String> properties = new HashMap<String, String>();
    Map<String, String> deploymentProperties = null;
    List<String> commandLineArgs = null;
    ...
    ...
    commandLineArgs = **<parse your message and get the commandline args>**

    TaskLaunchRequest request = new TaskLaunchRequest(
            processorProperties.getUri(),
            commandLineArgs,
            properties,
            deploymentProperties,
            null);

    return request;
}

请参阅下面的github链接,了解TasklaunchrequestTransformProcessorConfiguration的原始源代码。

https://github.com/spring-cloud-stream-app-starters/tasklaunchrequest-transform/blob/master/spring-cloud-starter-stream-processor-tasklaunchrequest-transform/src/main/java/org/springframework/cloud/stream/app/tasklaunchrequest/transform/processor/TasklaunchrequestTransformProcessorConfiguration.java

希望这有帮助。