3

我正在尝试将一些代码重构为在工作人员内部并出现错误:

未定义的符号 userId

似乎工作人员无法从其上方的范围内看到变量。如何让工作人员看到传入的参数?

import ballerina.net.http;
import ballerina.lang.messages;
import ballerina.lang.jsons;

@http:BasePath ("/foo")
  service barApi {
  http:ClientConnector endpointEP = create http:ClientConnector("http://example.com");

  @http:GET
  @http:Path("/users/{userId}")
  resource users (message m,
  @http:PathParam("userId") string userId) {
    worker sampleWorker(message m) {
      string requestPath = "/user/" + userId;
      message response = http:ClientConnector.get(endpointEP, requestPath, m);
4

1 回答 1

1

您可以通过工人交互的新设计将任意数量的变量传递给芭蕾舞演员。假设您想将 2 个变量从默认工作程序(主)传递给另一个工作程序 W1,这是示例代码。

import ballerina.lang.system;

function main(string[] args) {
int x = 10;
string s = "Test";
x, s -> W1;

worker W1 {
int y;
string t;
y,t <- default;
system:println("Inside worker " + y + " " + t);

}
}
于 2017-07-01T14:53:53.417 回答