Skip to content

Commit ec11b88

Browse files
gRPC client API improvements (2.0) (helidon-io#1851)
* gRPC client API improvements * Rename @GrpcService -> @grpc and @GrpcServiceProxy -> @GrpcProxy * Rename GrpcClientProxyBuilder to GrpcProxyBuilder * Leftover @GrpcService -> @grpc changes * Added breaking change documentation to CHANGELOG.md Co-authored-by: Tomas Langer <tomas.langer@gmail.com>
1 parent 8185c08 commit ec11b88

49 files changed

Lines changed: 413 additions & 315 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ This is the fourth milestone release of Helidon 2.0.
1919

2020
### Backward incompatible changes
2121

22+
#### gRPC: Renamed several annotations and classes
23+
24+
As part of gRPC API cleanup, we have renamed the following annotations and classes:
25+
26+
| Old Name | New Name |
27+
| ------------------------ | ------------------ |
28+
| `@RpcService` | `@Grpc` |
29+
| `@RpcMethod` | `@GrpcMethod` |
30+
| `@GrpcServiceProxy` | `@GrpcProxy` |
31+
| `GrpcClientProxyBuilder` | `GrpcProxyBuilder` |
32+
33+
While in general we prefer not to break backwards compatibility by renaming public API
34+
classes, we felt that in this case the change was warranted and acceptable, for several reasons:
35+
36+
1. gRPC API was marked experimental in Helidon 1.x
37+
2. While using gRPC in our own applications, we have realized that the code in some cases
38+
does not read as well as it should, and that some class and annotation names should be changed
39+
to improve both internal API consistency and readability
40+
41+
We apologize for the inconvenience, but we do feel that the impact of the changes is minimal
42+
and that the changes will be beneficial in the long run.
43+
2244
#### Internal `helidon-common-metrics` and Related Classes Removed
2345
Later releases of Helidon 1.x included the `helidon-common-metrics` component and related
2446
classes which provided a common interface to ease the transition from MicroProfile
@@ -41,6 +63,7 @@ Any user code that used these internal classes can use the corresponding support
4163
| |`InternalMetadataImpl` |
4264
| |`InternalMetricIDImpl` |
4365

66+
4467
## [2.0.0-M3]
4568

4669
### Notes

docs/mp/grpc/01_mp_server_side_services.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ For example:
5454
.Simple gRPC Service
5555
----
5656
@ApplicationScoped
57-
@io.helidon.microprofile.grpc.core.RpcService
57+
@io.helidon.microprofile.grpc.core.Grpc
5858
public class StringService {
5959
6060
@io.helidon.microprofile.grpc.core.Unary
@@ -65,7 +65,7 @@ public class StringService {
6565
----
6666
6767
The code above is a simple service with a single unary method that just converts a String to uppercase.
68-
The important parts in the example are the `@ApplicationScoped`, `@RpcService` and `@Unary` annotations; these,
68+
The important parts in the example are the `@ApplicationScoped`, `@Grpc` and `@Unary` annotations; these,
6969
along with other annotations discussed later, allow the gRPC MP APIs to discover, configure and deploy the service.
7070
7171
Of course Helidon gRPC MP does not preclude you from using the Protobuf files approach, traditional gRPC Java services
@@ -77,22 +77,22 @@ annotations.
7777
[source,java]
7878
----
7979
@ApplicationScoped <1>
80-
@io.helidon.microprofile.grpc.core.RpcService <2>
80+
@io.helidon.microprofile.grpc.core.Grpc <2>
8181
public class StringService {
8282
----
8383
8484
<1> The `ApplicationScoped` annotation is what makes the service implementation a CDI bean and hence discoverable.
85-
<2> The `RpcService` annotation is what defines the class as a gRPC service so that when the bean is iscovered it is
85+
<2> The `Grpc` annotation is what defines the class as a gRPC service so that when the bean is discovered it is
8686
then deployed by the gRPC MP server.
8787
8888
=== Service Name
89-
By default when a class is annotated with `RpcService` the class name will be used as the gRPC service name. So in the example
89+
By default when a class is annotated with `Grpc` the class name will be used as the gRPC service name. So in the example
9090
above the service name will be `StringService`. This can be change by supplying a name to the annotation.
9191
9292
[source,java]
9393
----
9494
@ApplicationScoped
95-
@io.helidon.microprofile.grpc.core.RpcService(name="Strings") <1>
95+
@io.helidon.microprofile.grpc.core.Grpc(name="Strings") <1>
9696
public class StringService {
9797
----
9898
<1> in the example above the name of the deployed service will be `Strings`.

docs/mp/grpc/02_mp_clients.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ For example, suppose we have a simple server side service that has a unary metho
6161
.Simple gRPC Service
6262
----
6363
@ApplicationScoped
64-
@io.helidon.microprofile.grpc.core.RpcService
64+
@io.helidon.microprofile.grpc.core.Grpc
6565
public class StringService {
6666
6767
@io.helidon.microprofile.grpc.core.Unary
@@ -81,7 +81,7 @@ To write a client for the StringService all that is required is an interface.
8181
.Simple gRPC Service
8282
----
8383
@ApplicationScoped
84-
@io.helidon.microprofile.grpc.core.RpcService
84+
@io.helidon.microprofile.grpc.core.Grpc
8585
public class StringService {
8686
8787
@io.helidon.microprofile.grpc.core.Unary
@@ -100,7 +100,7 @@ unary method signature:
100100
.Simple gRPC Service
101101
----
102102
@ApplicationScoped
103-
@io.helidon.microprofile.grpc.core.RpcService
103+
@io.helidon.microprofile.grpc.core.Grpc
104104
public class StringService {
105105
106106
@io.helidon.microprofile.grpc.core.Unary
@@ -114,7 +114,7 @@ We could also have made the client asynchronous by using one of the async method
114114
.Simple gRPC Service
115115
----
116116
@ApplicationScoped
117-
@io.helidon.microprofile.grpc.core.RpcService
117+
@io.helidon.microprofile.grpc.core.Grpc
118118
public class StringService {
119119
120120
@io.helidon.microprofile.grpc.core.Unary
@@ -237,13 +237,13 @@ The field is then annotated so that CDI will inject the client proxy into the fi
237237
public class Client {
238238
239239
@Inject <1>
240-
@GrpcServiceProxy <2>
240+
@GrpcProxy <2>
241241
@GrpcChannel(name = "test-server") <3>
242242
private StringService stringService;
243243
----
244244
245245
<1> The `@Inject` annotation tells the CDI to inject the client implementation; the gRPC MP APIs have a bean provider that does this.
246-
<2> The `@GrpcServiceProxy` annotation is used by the CDI container to match the injection point to the gRPC MP APIs provider
246+
<2> The `@GrpcProxy` annotation is used by the CDI container to match the injection point to the gRPC MP APIs provider
247247
<3> The `@GrpcChannel` annotation identifies the gRPC channel to be used by the client. The name used in the annotation refers to
248248
a channel name in the application configuration.
249249

examples/grpc/microprofile/basic-client/src/main/java/io/helidon/microprofile/grpc/example/client/AsyncClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import javax.inject.Inject;
2525

2626
import io.helidon.microprofile.grpc.client.GrpcChannel;
27-
import io.helidon.microprofile.grpc.client.GrpcServiceProxy;
27+
import io.helidon.microprofile.grpc.client.GrpcProxy;
2828

2929
/**
3030
* A client to the {@link io.helidon.microprofile.grpc.example.client.AsyncStringService}.
@@ -42,7 +42,7 @@ public class AsyncClient {
4242
* This proxy will connect to the service using the default {@link io.grpc.Channel}.
4343
*/
4444
@Inject
45-
@GrpcServiceProxy
45+
@GrpcProxy
4646
@GrpcChannel(name = "test-server")
4747
private AsyncStringService stringService;
4848

examples/grpc/microprofile/basic-client/src/main/java/io/helidon/microprofile/grpc/example/client/AsyncStringService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import io.helidon.microprofile.grpc.core.Bidirectional;
2323
import io.helidon.microprofile.grpc.core.ClientStreaming;
24-
import io.helidon.microprofile.grpc.core.RpcService;
24+
import io.helidon.microprofile.grpc.core.Grpc;
2525
import io.helidon.microprofile.grpc.core.ServerStreaming;
2626
import io.helidon.microprofile.grpc.core.Unary;
2727

@@ -30,10 +30,10 @@
3030
/**
3131
* The gRPC StringService.
3232
* <p>
33-
* This class has the {@link io.helidon.microprofile.grpc.core.RpcService} annotation
33+
* This class has the {@link io.helidon.microprofile.grpc.core.Grpc} annotation
3434
* so that it will be discovered and loaded using CDI when the MP gRPC server starts.
3535
*/
36-
@RpcService
36+
@Grpc
3737
@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
3838
public interface AsyncStringService {
3939

examples/grpc/microprofile/basic-client/src/main/java/io/helidon/microprofile/grpc/example/client/Client.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import javax.inject.Inject;
2727

2828
import io.helidon.microprofile.grpc.client.GrpcChannel;
29-
import io.helidon.microprofile.grpc.client.GrpcServiceProxy;
29+
import io.helidon.microprofile.grpc.client.GrpcProxy;
3030

3131
import io.grpc.stub.StreamObserver;
3232

@@ -46,7 +46,7 @@ public class Client {
4646
* This proxy will connect to the service using the default {@link io.grpc.Channel}.
4747
*/
4848
@Inject
49-
@GrpcServiceProxy
49+
@GrpcProxy
5050
@GrpcChannel(name = "test-server")
5151
private StringService stringService;
5252

examples/grpc/microprofile/basic-client/src/main/java/io/helidon/microprofile/grpc/example/client/StringService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import io.helidon.microprofile.grpc.core.Bidirectional;
2222
import io.helidon.microprofile.grpc.core.ClientStreaming;
23-
import io.helidon.microprofile.grpc.core.RpcService;
23+
import io.helidon.microprofile.grpc.core.Grpc;
2424
import io.helidon.microprofile.grpc.core.ServerStreaming;
2525
import io.helidon.microprofile.grpc.core.Unary;
2626

@@ -29,10 +29,10 @@
2929
/**
3030
* The gRPC StringService.
3131
* <p>
32-
* This class has the {@link io.helidon.microprofile.grpc.core.RpcService} annotation
32+
* This class has the {@link io.helidon.microprofile.grpc.core.Grpc} annotation
3333
* so that it will be discovered and loaded using CDI when the MP gRPC server starts.
3434
*/
35-
@RpcService
35+
@Grpc
3636
@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
3737
public interface StringService {
3838

examples/grpc/microprofile/basic-server-implicit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It is implicit because in this example you don't write the
77

88
The gRPC services to deploy will be discovered by CDI when the gRPC server starts.
99
The `StringService` is a POJO service implementation that is annotated with the
10-
CDI qualifier `RpcService` so that it can be discovered.
10+
CDI qualifier `Grpc` so that it can be discovered.
1111

1212
Two additional services (`GreetService` and `EchoService`) that are not normally CDI
1313
managed beans are manually added as CDI managed beans in the `AdditionalServices` class

examples/grpc/microprofile/basic-server-implicit/src/main/java/io/helidon/microprofile/grpc/example/basic/implicit/AsyncStringService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import io.helidon.grpc.server.CollectingObserver;
2727
import io.helidon.microprofile.grpc.core.Bidirectional;
2828
import io.helidon.microprofile.grpc.core.ClientStreaming;
29-
import io.helidon.microprofile.grpc.core.RpcService;
29+
import io.helidon.microprofile.grpc.core.Grpc;
3030
import io.helidon.microprofile.grpc.core.ServerStreaming;
3131
import io.helidon.microprofile.grpc.core.Unary;
3232

@@ -35,11 +35,11 @@
3535
/**
3636
* The gRPC StringService implementation that uses async unary methods.
3737
* <p>
38-
* This class is a gRPC service annotated with {@link io.helidon.microprofile.grpc.core.RpcService} and
38+
* This class is a gRPC service annotated with {@link io.helidon.microprofile.grpc.core.Grpc} and
3939
* {@link javax.enterprise.context.ApplicationScoped} so that it will be discovered and deployed using
4040
* CDI when the MP gRPC server starts.
4141
*/
42-
@RpcService
42+
@Grpc
4343
@ApplicationScoped
4444
public class AsyncStringService {
4545

examples/grpc/microprofile/basic-server-implicit/src/main/java/io/helidon/microprofile/grpc/example/basic/implicit/StringService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import io.helidon.grpc.server.CollectingObserver;
2525
import io.helidon.microprofile.grpc.core.Bidirectional;
2626
import io.helidon.microprofile.grpc.core.ClientStreaming;
27-
import io.helidon.microprofile.grpc.core.RpcService;
27+
import io.helidon.microprofile.grpc.core.Grpc;
2828
import io.helidon.microprofile.grpc.core.ServerStreaming;
2929
import io.helidon.microprofile.grpc.core.Unary;
3030

@@ -33,10 +33,10 @@
3333
/**
3434
* The gRPC StringService implementation.
3535
* <p>
36-
* This class is a gRPC service annotated with {@link RpcService} and {@link ApplicationScoped}
36+
* This class is a gRPC service annotated with {@link Grpc} and {@link ApplicationScoped}
3737
* so that it will be discovered and deployed using CDI when the MP gRPC server starts.
3838
*/
39-
@RpcService
39+
@Grpc
4040
@ApplicationScoped
4141
public class StringService {
4242

0 commit comments

Comments
 (0)