有人有一个 fork/join 的工作示例,因为我收到了 芭蕾舞女演员: 每次我尝试用它做某事时都会发生意外错误。
谢谢,
胡安·巴勃罗
以下是一个工作分叉连接示例。请尝试使用ballerina run main forkjoin.bal
. 您可以将 forkjoin.bal 替换为您的文件名。
import ballerina.lang.system;
import ballerina.lang.messages;
function main(string[] args) {
message m = {};
testForkJoinAll(m);
}
function testForkJoinAll(message m)(message[]) {
message[] results;
json error;
system:println("Airfare ");
fork (m) {
worker ABC_Airline (message m) {
json payload;
payload = `{"name":"abc"}`;
messages:setJsonPayload(m, payload);
reply m;
}
worker XYZ_Airline (message m) {
json payload;
payload = `{"name":"xyz"}`;
messages:setJsonPayload(m, payload);
reply m;
}
} join (all) (message[] airlineResponses) {
system:println(messages:getStringPayload(airlineResponses[0]));
system:println(messages:getStringPayload(airlineResponses[1]));
return airlineResponses;
} timeout (30000) (message[] airlineResponses) {
system:println("error occurred");
error = `{"error":{"code":"500", "reason":"timed out"}}`;
message res = {};
messages:setJsonPayload(res, error);
results[0] = m;
return results;
}
}
请张贴您的代码让我们看看有什么问题。