我正在使用 Micronaut 声明式客户端在其他微服务之间进行通信,如下所示
@Client(id="feteBirdProduct", path = "/product")
public interface IProductClient extends IProductOperation {
}
控制器方法
@Controller("/product")
public class ProductController implements IProductOperation {
@Override
public Maybe<HttpResponse<?>> post(Publisher<CompletedFileUpload> files, ProductViewModel model) {
LOG.info(String.format("Controller --> Creating new product"));
return iProductManager.Create(model).flatMap(item -> {
if (item != null)
return Maybe.just(HttpResponse.created(item, new URI(item.id())));
else
return Maybe.just(HttpResponse.serverError());
}
);
}
}
IProduct操作界面
public interface IProductOperation {
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Post
@Secured(SecurityRule.IS_ANONYMOUS)
Maybe<HttpResponse<?>> post(@NotBlank Publisher<CompletedFileUpload> files, @Body ProductViewModel model);
}
API 网关控制器
@Controller("/api/${api.version:v1}/product")
public class ApiGatewayProductController implements IProductOperation {
@Override
public Maybe<HttpResponse<?>> post(@NotBlank Publisher<CompletedFileUpload> files, @Body ProductViewModel model){
return this.iProductClient.post(files, model);
}
}
当我提出请求时,请继续获取以下日志
DEBUG i.m.h.client.netty.DefaultHttpClient - Sending HTTP POST to http://localhost:8081/product
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - Content-Type: application/json
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - Accept: multipart/form-data
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IkMzRjE0RTFCRjAzRjhDNzAxRDEwNzZBRjEwNDJBNThBIiwidHlwIjoiYXQrand0In0.eyJuYmYiOjE2MTQ5NDIzOTAsImV4cCI6MTYxNDk0MjU5MCwiaXNzIjoiaHR0cHM6Ly9mYWxjb25pZGVudGl0eXNlcnZlci5henVyZXdlYnNpdGVzLm5ldCIsImNsaWVudF9pZCI6IkZldGVfQmlyZF9VSSIsInN1YiI6I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i-goPJoAj0USSw_QWoJi9CHArIs63NTIanc9lvQJWPlO9TxVqiWm49aq5e1RJQfZKU4uk3i6cExYQDXqoMhg9GBzqrlw1HUBb1EttsRoQR94jCEl5XrRZQuSPIhxdjOrW50W2bxwrvfYXheqj0D8wmcEwD8HGo03WOMg
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - X-B3-TraceId: 8b177f888c372156
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - X-B3-SpanId: 3cce7450e87bd8b6
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - X-B3-ParentSpanId: 8b177f888c372156
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - X-B3-Sampled: 1
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - host: localhost:8081
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - connection: close
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - content-length: 46
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - Request Body
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - ----
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - {"id":"sdsdf","productOptionViewModel":"SIZE"}
22:06:42.631 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - ----
DEBUG i.m.h.client.netty.DefaultHttpClient - Received response 403 from http://localhost:8081/product
22:06:42.645 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - connection: close
22:06:42.645 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - Response Body
22:06:42.645 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - ----
22:06:42.645 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient -
22:06:42.645 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - ----
22:06:42.645 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - Full HTTP response received an empty body
22:06:42.645 [default-nioEventLoopGroup-1-8] TRACE i.m.h.client.netty.DefaultHttpClient - Unable to convert response body to target type class java.lang.String
卷曲
curl -X POST "http://localhost:8080/api/v1/product" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "id=" -F "productOptionViewModel=SIZE" -F "files=@bird.png;type=image/png"
如果我Publisher<CompletedFileUpload>
从控制器中删除,端点工作正常。