![](/img/trans.png)
[英]How to implement custom kafka Partition using spring cloud stream
[英]How to launch Spring Task using Spring CLoud stream with custom parameters
我能够运行下面提到的Spring云流,该流从Rabbitmq获取消息,转换为Tasklaunch请求,并使用Task-laucher-local触发任务。 这工作得很好。
stream create task-stream-1 --definition“源: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“流部署task-stream-1-属性“ app.source.rabbit.spring.cloud.stream.bindings.output.binder = rabbit,app.tasklaunchrequest-transform.spring.cloud.stream.bindings.input.binder = rabbit ,app.tasklaunchrequest-transform.spring.cloud.stream.bindings.outpu t.binder =兔,app.task推出-local.spring.cloud.stream.bindings.input.binder =兔子”
但是,我不想在部署期间直接传递Uri和命令行参数,而是希望从传入消息中获取这些参数,然后启动一个请求。
我创建了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": {
}
}
请帮助解决此问题。
我认为您应该使用TaskLaunchRequest-transform
使用任务启动器启动任务的另一种方法是使用Tasklaunchrequest转换处理器创建流,以将消息有效负载转换为TaskLaunchRequest。
您应该实现自己的处理器,类似于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的原始源代码。
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.