1

我有一个使用声明性 Http 客户端的 API 网关,并尝试将路由参数传递给其他微服务应用程序,如下所示

@Client(id="feteBirdProduct", path = "/sub-category")
public interface ISubCategoryClient extends ISubCategoryOperation{
}

@Client 上的路径path = "/sub-category"对于此 URL 是正确的http://localhost:8081/60236833af7a1d49478d2bef/sub-category

Api 网关控制器

@Controller("/api/${api.version:v1}/{categoryId}/sub-category")
public class ApiGatewaySubCategoryController implements ISubCategoryOperation{
    private final ISubCategoryClient iSubCategoryClient;

    public ApiGatewaySubCategoryController(ISubCategoryClient iSubCategoryClient) {
        this.iSubCategoryClient = iSubCategoryClient;
    }

    @Override
    public Maybe<?> get(@ValidObjectId @NotBlank String categoryId) {
        return this.iSubCategoryClient.get(categoryId);
    }
}

ISubCategoryOperation

@Get
    @Secured(SecurityRule.IS_ANONYMOUS)
    Maybe<?> get(@Parameter(description="Category id") @ValidObjectId @NotNull String categoryId);

在其他微服务中实现

@Controller("/{categoryId}/sub-category")
public class SubCategoryController implements ISubCategoryOperation {
    @Override
    public Maybe<?> get(String categoryId) {
        return iSubCategoryManager.find(categoryId);
    }
}

但是,在下面的 CURL

curl -X GET "http://localhost:8080/api/v1/60236833af7a1d49478d2bef/sub-category" -H  "accept: application/json"

永远不会达到终点,我错过了什么?

HTTP 客户端日志

DEBUG i.m.h.client.netty.DefaultHttpClient - Sending HTTP GET to http://localhost:8081/sub-category

HTTP 请求应该是http://localhost:8081/60236833af7a1d49478d2bef /sub-category

4

0 回答 0