From 2ff033f9c2078a24464977747182fe5b0c59d6c1 Mon Sep 17 00:00:00 2001 From: Renato Cavalcanti Date: Tue, 14 Dec 2021 11:47:01 +0100 Subject: [PATCH] docs: adapt samples and documentation for new codegen annotation (#748) Co-authored-by: Peter Vlugter --- .../test-shoppingcart/shoppingcart_api.proto | 24 +-- .../shoppingcart_domain.proto | 20 -- .../pages/actions-publishing-subscribing.adoc | 12 +- docs/src/modules/java/pages/actions.adoc | 4 +- .../java/pages/event-sourced-entities.adoc | 53 ++---- .../java/pages/replicated-entity-crdt.adoc | 171 ++++++++++-------- docs/src/modules/java/pages/side-effects.adoc | 4 +- docs/src/modules/java/pages/value-entity.adoc | 37 ++-- docs/src/modules/java/pages/views.adoc | 46 +++-- .../writing-grpc-descriptors-protobuf.adoc | 40 ++-- .../__packageInPathFormat__/counter_api.proto | 39 ++-- .../domain/counter_domain.proto | 15 +- .../__packageInPathFormat__/counter_api.proto | 35 ++-- .../domain/counter_domain.proto | 10 +- .../com/example/delegating_service.proto | 4 +- .../proto/com/example/json/json_api.proto | 4 +- .../proto/com/example/topics_action.proto | 4 +- .../com/example/actions/counter_topic.proto | 4 +- .../example/actions/counter_topic_sub.proto | 4 +- .../main/proto/com/example/counter_api.proto | 15 +- .../com/example/domain/counter_domain.proto | 9 - .../proto/customer/api/customer_api.proto | 25 +-- .../customer/domain/customer_domain.proto | 16 +- .../proto/customer/view/customer_view.proto | 4 +- .../domain/shoppingcart_domain.proto | 14 +- .../shoppingcart/shoppingcart_api.proto | 12 +- .../view/shopping_cart_view_model.proto | 4 +- .../com/example/fibonacci/fibonacci.proto | 4 +- .../main/proto/com/example/counter_api.proto | 34 ++-- .../com/example/domain/counter_domain.proto | 10 +- .../replicated/counter/counter_api.proto | 11 +- .../counter/domain/counter_domain.proto | 15 -- .../countermap/counter_map_api.proto | 13 +- .../domain/counter_map_domain.proto | 31 ---- .../replicated/map/domain/map_domain.proto | 12 -- .../com/example/replicated/map/map_api.proto | 13 +- .../multimap/domain/multi_map_domain.proto | 32 ---- .../replicated/multimap/multi_map_api.proto | 14 +- .../register/domain/register_domain.proto | 10 - .../replicated/register/register_api.proto | 13 +- .../domain/register_map_domain.proto | 15 +- .../registermap/register_map_api.proto | 15 +- .../replicated/set/domain/set_domain.proto | 31 ---- .../com/example/replicated/set/set_api.proto | 13 +- .../domain/shoppingcart_domain.proto | 13 +- .../shoppingcart/shoppingcart_api.proto | 12 +- .../example/actions/counter_states_sub.proto | 4 +- .../com/example/actions/double-counter.proto | 4 +- .../main/proto/com/example/counter_api.proto | 9 +- .../com/example/domain/counter_domain.proto | 12 +- .../customer/action/customer_action.proto | 4 +- .../proto/customer/api/customer_api.proto | 17 +- .../customer/domain/customer_domain.proto | 11 -- .../proto/customer/view/customer_view.proto | 26 +-- .../domain/shoppingcart_domain.proto | 23 +-- .../shoppingcart/shoppingcart_api.proto | 44 +++-- .../shoppingcart_controller_api.proto | 4 +- .../com/example/delegating_service.proto | 4 +- .../proto/com/example/json/json_api.proto | 4 +- .../proto/com/example/topics_action.proto | 4 +- .../com/example/actions/counter_topic.proto | 4 +- .../example/actions/counter_topic_sub.proto | 4 +- .../main/proto/com/example/counter_api.proto | 14 +- .../com/example/domain/counter_domain.proto | 9 - .../proto/customer/api/customer_api.proto | 26 ++- .../customer/domain/customer_domain.proto | 15 +- .../proto/customer/view/customer_view.proto | 4 +- .../domain/shoppingcart_domain.proto | 12 -- .../shoppingcart/shoppingcart_api.proto | 12 +- .../com/example/fibonacci/fibonacci.proto | 4 +- .../main/proto/com/example/counter_api.proto | 35 ++-- .../proto/com/example/counter_domain.proto | 10 +- .../replicated/counter/counter_api.proto | 11 +- .../countermap/counter_map_api.proto | 14 +- .../domain/counter_map_domain.proto | 29 --- .../replicated/map/domain/map_domain.proto | 14 +- .../com/example/replicated/map/map_api.proto | 13 +- .../multimap/domain/multi_map_domain.proto | 30 --- .../replicated/multimap/multi_map_api.proto | 15 +- .../register/domain/register_domain.proto | 10 - .../replicated/register/register_api.proto | 13 +- .../registermap/register_map_api.proto | 14 +- .../replicated/set/domain/set_domain.proto | 29 --- .../com/example/replicated/set/set_api.proto | 13 +- .../domain/shoppingcart_domain.proto | 11 -- .../shoppingcart/shoppingcart_api.proto | 11 +- .../example/actions/counter_states_sub.proto | 4 +- .../com/example/actions/double-counter.proto | 4 +- .../main/proto/com/example/counter_api.proto | 9 +- .../com/example/domain/counter_domain.proto | 10 +- .../customer/action/customer_action.proto | 4 +- .../proto/customer/api/customer_api.proto | 14 +- .../customer/domain/customer_domain.proto | 10 - .../proto/customer/view/customer_view.proto | 26 +-- .../domain/shoppingcart_domain.proto | 13 -- .../shoppingcart/shoppingcart_api.proto | 9 +- .../shoppingcart_controller_api.proto | 4 +- .../example/eventing/raw_eventing_types.proto | 4 +- .../protobuf/com/example/view/user_view.proto | 4 +- 99 files changed, 663 insertions(+), 938 deletions(-) delete mode 100644 samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/domain/counter_domain.proto delete mode 100644 samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto delete mode 100644 samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto delete mode 100644 samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto delete mode 100644 samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto delete mode 100644 samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto delete mode 100644 samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto diff --git a/codegen/core/src/test/resources/test-shoppingcart/shoppingcart_api.proto b/codegen/core/src/test/resources/test-shoppingcart/shoppingcart_api.proto index 49885750d2..4673fd5985 100644 --- a/codegen/core/src/test/resources/test-shoppingcart/shoppingcart_api.proto +++ b/codegen/core/src/test/resources/test-shoppingcart/shoppingcart_api.proto @@ -14,16 +14,16 @@ syntax = "proto3"; -package com.example.shoppingcart; // <1> +package com.example.shoppingcart; -import "google/protobuf/empty.proto"; // <2> +import "google/protobuf/empty.proto"; import "akkaserverless/annotations.proto"; import "google/api/annotations.proto"; -option java_outer_classname = "ShoppingCartApi"; // <3> +option java_outer_classname = "ShoppingCartApi"; -message AddLineItem { // <4> - string cart_id = 1 [(akkaserverless.field).entity_key = true]; // <5> +message AddLineItem { + string cart_id = 1 [(akkaserverless.field).entity_key = true]; string product_id = 2; string name = 3; int32 quantity = 4; @@ -49,14 +49,17 @@ message LineItem { int64 quantity = 3; } -message Cart { // <6> +message Cart { repeated LineItem items = 1; } -service ShoppingCartService { // <7> - option (akkaserverless.service) = { // <8> - type: SERVICE_TYPE_ENTITY - component: ".domain.ShoppingCart" +service ShoppingCartService { + option (akkaserverless.codegen) = { + value_entity: { + name: ".domain.ShoppingCart" + entity_type: "shopping-cart" + state: ".domain.Cart" + } }; rpc AddItem (AddLineItem) returns (google.protobuf.Empty) { @@ -86,4 +89,3 @@ service ShoppingCartService { // <7> option (google.api.http).post = "/carts/{cart_id}/remove"; } } - diff --git a/codegen/core/src/test/resources/test-shoppingcart/shoppingcart_domain.proto b/codegen/core/src/test/resources/test-shoppingcart/shoppingcart_domain.proto index 56e6d288d1..2c3976e521 100644 --- a/codegen/core/src/test/resources/test-shoppingcart/shoppingcart_domain.proto +++ b/codegen/core/src/test/resources/test-shoppingcart/shoppingcart_domain.proto @@ -13,30 +13,12 @@ // limitations under the License. // These are the messages that get persisted - the current state (Cart). - -// tag::domain[] -// tag::proto_syntax[] syntax = "proto3"; -// end::proto_syntax[] package com.example.shoppingcart.domain; option java_outer_classname = "ShoppingCartDomain"; -// tag::proto_imports[] -import "akkaserverless/annotations.proto"; -// end::proto_imports[] - -// tag::proto_state[] -// Describes how this domain relates to a value entity -option (akkaserverless.file).value_entity = { - name: "ShoppingCart" - entity_type: "shopping-cart" - state: "Cart" -}; -// end::proto_state[] - -// tag::proto_messages[] message LineItem { string productId = 1; string name = 2; @@ -47,5 +29,3 @@ message LineItem { message Cart { repeated LineItem items = 1; } -// end::proto_messages[] -// end::domain[] diff --git a/docs/src/modules/java/pages/actions-publishing-subscribing.adoc b/docs/src/modules/java/pages/actions-publishing-subscribing.adoc index b0b417451f..00bea3331e 100644 --- a/docs/src/modules/java/pages/actions-publishing-subscribing.adoc +++ b/docs/src/modules/java/pages/actions-publishing-subscribing.adoc @@ -29,7 +29,7 @@ Java:: include::example$java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto[tag=counter-topic] ---- <1> Import the Counter Domain file containing the definitions of the events. This is typically a proto definition within the same service. -<2> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. +<2> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. <3> The `Increase` method receives the event `ValueIncreased` and returns the transformed type `Increased`. <4> The `(akkaserverless.method).eventing.in` annotation indicates that events from the entity type `counter` should be delivered to this method (when the type is `ValueIncreased`). <5> The `(akkaserverless.method).eventing.out` annotation indicates that the returned value from this method should be published to the topic called `counter-events`. @@ -42,7 +42,7 @@ Scala:: include::example$scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto[tag=counter-topic] ---- <1> Import the Counter Domain file containing the definitions of the events. This is typically a proto definition within the same service. -<2> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless sbt plugin. This annotation indicates to the code-generation that an Action must be generated. +<2> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless sbt plugin. This annotation indicates to the code-generation that an Action must be generated. <3> The `Increase` method receives the event `ValueIncreased` and returns the transformed type `Increased`. <4> The `(akkaserverless.method).eventing.in` annotation indicates that events from the entity type `counter` should be delivered to this method (when the type is `ValueIncreased`). <5> The `(akkaserverless.method).eventing.out` annotation indicates that the returned value from this method should be published to the topic called `counter-events`. @@ -84,7 +84,7 @@ Java:: include::example$java-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto[tag=state-subscription] ---- <1> Import the Counter Domain from the Value Entity example (see xref:java:value-entity.adoc[Implementing Value Entities]) -<2> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. +<2> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. <3> The `(akkaserverless.method).eventing.in` annotation indicates that state changes from the value entity type `counter` should be delivered to this method. Scala:: @@ -95,7 +95,7 @@ Scala:: include::example$scala-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto[tag=state-subscription] ---- <1> Import the Counter Domain from the Value Entity example (see xref:java:value-entity.adoc[Implementing Value Entities]) -<2> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless sbt plugin. This annotation indicates to the code-generation that an Action must be generated. +<2> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless sbt plugin. This annotation indicates to the code-generation that an Action must be generated. <3> The `(akkaserverless.method).eventing.in` annotation indicates that state changes from the value entity type `counter` should be delivered to this method. == Subscribing to a Topic @@ -115,7 +115,7 @@ Java:: include::example$java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto[tag=counter-topic-sub] ---- <1> Import the Counter Topic types from previous example. -<2> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. +<2> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. <3> Define methods for each of the possible incoming messages and annotate them with `(akkaserverless.method).eventing.in` indicating that the source of events is the topic `counter-events`. Scala:: @@ -126,7 +126,7 @@ Scala:: include::example$scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto[tag=counter-topic-sub] ---- <1> Import the Counter Topic types from previous example. -<2> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless sbt plugin. This annotation indicates to the code-generation that an Action must be generated. +<2> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless sbt plugin. This annotation indicates to the code-generation that an Action must be generated. <3> Define methods for each of the possible incoming messages and annotate them with `(akkaserverless.method).eventing.in` indicating that the source of events is the topic `counter-events`. The class `CounterTopicSubscriptionAction` gets generated for us based on the proto file defined above. diff --git a/docs/src/modules/java/pages/actions.adoc b/docs/src/modules/java/pages/actions.adoc index b27ff0334c..5ab6763b25 100644 --- a/docs/src/modules/java/pages/actions.adoc +++ b/docs/src/modules/java/pages/actions.adoc @@ -21,7 +21,7 @@ include::example$java-fibonacci-action/src/main/proto/com/example/fibonacci/fibo <1> Any classes generated from this protobuf file will be in the `com.example.fibonacci` package. <2> Import the Akka Serverless protobuf annotations or options. <3> Let the messages declared in this protobuf file be inner classes to the Java class `FibonacciApi`. -<4> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. +<4> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. Scala:: + @@ -32,7 +32,7 @@ include::example$scala-fibonacci-action/src/main/proto/com/example/fibonacci/fib ---- <1> Any classes generated from this protobuf file will be in the `com.example.fibonacci` package. <2> Import the Akka Serverless protobuf annotations or options. -<3> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless sbt plugin. This annotation indicates to the code-generation that an Action must be generated. +<3> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless sbt plugin. This annotation indicates to the code-generation that an Action must be generated. == Implementing the Action diff --git a/docs/src/modules/java/pages/event-sourced-entities.adoc b/docs/src/modules/java/pages/event-sourced-entities.adoc index afa2653536..4f211e7480 100644 --- a/docs/src/modules/java/pages/event-sourced-entities.adoc +++ b/docs/src/modules/java/pages/event-sourced-entities.adoc @@ -33,13 +33,7 @@ Java:: include::example$java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[tag=domain] ---- <1> Any classes generated from this protobuf file will be in the Java package `com.example.shoppingcart.domain`. -<2> Import the Akka Serverless protobuf annotations or options. -<3> Let the messages declared in this protobuf file be inner classes to the Java class `ShoppingCartDomain`. -<4> The protobuf option `(akkaserverless.file).event_sourced_entity` is specific to code-generation as provided by the Akka Serverless Maven plugin. -<5> `name` denotes the base name for the Event Sourced Entity, the code-generation will create initial sources `ShoppingCart`, `ShoppingCartTest` and `ShoppingCartIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. -<6> `entity_type` is a unique identifier of the "state storage". The entity name may be changed even after data has been created, the `entity_type` can't. -<7> `state` points to the protobuf message representing the entity's state which is kept by Akka Serverless. It is stored as snapshots. -<8> `events` points to the protobuf message representing the entity's events, which are stored by Akka Serverless. +<2> Let the messages declared in this protobuf file be inner classes to the Java class `ShoppingCartDomain`. Scala:: + @@ -49,13 +43,6 @@ Scala:: include::example$scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[tag=domain] ---- <1> Any classes generated from this protobuf file will be in the Scala package `com.example.shoppingcart.domain`. -<2> Import the Akka Serverless protobuf annotations or options. -<3> The protobuf option `(akkaserverless.file).event_sourced_entity` is specific to code-generation as provided by the Akka Serverless sbt plugin. -<4> `name` denotes the base name for the Event Sourced Entity, the code-generation will create initial sources `ShoppingCart`, `ShoppingCartTest` and `ShoppingCartIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. -<5> `entity_type` is a unique identifier of the "state storage". The entity name may be changed even after data has been created, the `entity_type` can't. -<6> `state` points to the protobuf message representing the entity's state which is kept by Akka Serverless. It is stored as snapshots. -<7> `events` points to the protobuf message representing the entity's events, which are stored by Akka Serverless. - The `shoppingcart_api.proto` file defines the commands we can send to the shopping cart service to manipulate or access the cart's state. They make up the service API: @@ -74,7 +61,13 @@ include::example$java-eventsourced-shopping-cart/src/main/proto/com/example/shop <5> Every Command must contain a `string` field that contains the entity ID and is marked with the `(akkaserverless.field).entity_key` option. <6> Messages describe the return value for our API. For methods that don't have return values, we use `google.protobuf.Empty`. <7> The service descriptor shows the API of the entity. It lists the methods a client can use to issue Commands to the entity. -<8> The protobuf option `(akkaserverless.service)` is specific to code-generation as provided by the Akka Serverless Maven plugin and points to the protobuf definition `ShoppingCart` we've seen above (in the `com.example.shoppingcart.domain` package). +<8> The protobuf option `(akkaserverless.codegen)` is specific to code-generation as provided by the Akka Serverless Maven plugin. +<9> `event_sourced_entity` indicates that we want the codegen to generate an Event Sourced Entity for this service. +<10> `name` denotes the base name for the Event Sourced Entity, the code-generation will create initial sources `ShoppingCart`, `ShoppingCartTest` and `ShoppingCartIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. +<11> `entity_type` is a unique identifier of the "state storage". The entity name may be changed even after data has been created, the `entity_type` can't. +<12> `state` points to the protobuf message representing the entity's state which is kept by Akka Serverless. It is stored as snapshots. +<13> `events` points to the protobuf message representing the entity's events, which are stored by Akka Serverless. + Scala:: + @@ -89,7 +82,12 @@ include::example$scala-eventsourced-shopping-cart/src/main/proto/com/example/sho <4> Every Command must contain a `string` field that contains the entity ID and is marked with the `(akkaserverless.field).entity_key` option. <5> Messages describe the return value for our API. For methods that don't have return values, we use `google.protobuf.Empty`. <6> The service descriptor shows the API of the entity. It lists the methods a client can use to issue Commands to the entity. -<7> The protobuf option `(akkaserverless.service)` is specific to code-generation as provided by the Akka Serverless sbt plugin and points to the protobuf definition `ShoppingCart` we've seen above (in the `com.example.shoppingcart.domain` package). +<7> The protobuf option `(akkaserverless.codegen)` is specific to code-generation as provided by the Akka Serverless sbt plugin. +<8> `event_sourced_entity` indicates that we want the codegen to generate an Event Sourced Entity for this service. +<9> `name` denotes the base name for the Event Sourced Entity, the code-generation will create initial sources `ShoppingCart`, `ShoppingCartTest` and `ShoppingCartIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. +<10> `entity_type` is a unique identifier of the "state storage". The entity name may be changed even after data has been created, the `entity_type` can't. +<11> `state` points to the protobuf message representing the entity's state which is kept by Akka Serverless. It is stored as snapshots. +<12> `events` points to the protobuf message representing the entity's events, which are stored by Akka Serverless. == Implementing behavior @@ -157,7 +155,7 @@ include::example$scala-eventsourced-shopping-cart/src/main/scala/com/example/sho <3> We store the event by returning an `Effect` with `effects.emitEvent`. <4> The acknowledgment that the command was successfully processed is only sent if the event was successfully stored, otherwise there will be an error reply. -The new state is created from the event and the previous state in the event handler. Event handlers are implemented in the `ShoppingCart` class as methods that override abstract methods from `AbstractShoppingCart`. +The new state is created from the event and the previous state in the event handler. Event handlers are implemented in the `ShoppingCart` class as methods that override abstract methods from `AbstractShoppingCart`. Event handlers are generated for each event declared in `(akkaserverless.codegen).event_sourced_entity.events`. [.tabset] Java:: @@ -177,26 +175,6 @@ include::example$scala-eventsourced-shopping-cart/src/main/scala/com/example/sho ---- -Note that you have to define the events in the `(akkaserverless.file).event_sourced_entity`: - -[.tabset] -Java:: -+ -[source,proto] -.src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto ----- -include::example$java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[tag=event_sourced_entity] ----- - -Scala:: -+ -[source,proto] -.src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto ----- -include::example$scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[tag=event_sourced_entity] ----- - - === Retrieving state The following example shows the implementation of the `GetCart` command handler. This command handler is a read-only command handler--it doesn't update the state, it just returns it: @@ -344,4 +322,3 @@ This class is generated by AkkaServerless when the project is compiled and locat * `currentState` - the current state of the entity, it is updated on each method call emitting events. * `allEvents` - all events emitted since the creation of the testkit instance. - diff --git a/docs/src/modules/java/pages/replicated-entity-crdt.adoc b/docs/src/modules/java/pages/replicated-entity-crdt.adoc index 56d4d2cecf..b410009b6d 100644 --- a/docs/src/modules/java/pages/replicated-entity-crdt.adoc +++ b/docs/src/modules/java/pages/replicated-entity-crdt.adoc @@ -34,13 +34,7 @@ Java:: include::example$java-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[] ---- <1> Any classes generated from this protobuf file will be in the Java package `com.example.shoppingcart.domain`. -<2> Import the Akka Serverless protobuf annotations, or options. -<3> Let the messages declared in this protobuf file be inner classes to the Java class `ShoppingCartDomain`. -<4> The protobuf option `(akkaserverless.file).replicated_entity` is specific to code-generation as provided by the Akka Serverless Maven plugin. -<5> `name` denotes the base name for the Replicated Entity. The code-generation will create initial sources `ShoppingCart` and `ShoppingCartIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. -<6> `entity_type` is a unique identifier for data replication. The entity name may be changed even after data has been created, the `entity_type` can't be changed. -<7> `replicated_counter_map` describes the Replicated Data type for this entity. -<8> `key` points to the protobuf message representing the counter map's key type. +<2> Let the messages declared in this protobuf file be inner classes to the Java class `ShoppingCartDomain`. Scala:: + @@ -50,12 +44,7 @@ Scala:: include::example$scala-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[] ---- <1> Any classes generated from this protobuf file will be in the package `com.example.shoppingcart.domain`. -<2> Import the Akka Serverless protobuf annotations, or options. -<3> The protobuf option `(akkaserverless.file).replicated_entity` is specific to code-generation as provided by the Akka Serverless Maven plugin. -<4> `name` denotes the base name for the Replicated Entity. The code-generation will create initial sources `ShoppingCart` and `ShoppingCartIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. -<5> `entity_type` is a unique identifier for data replication. The entity name may be changed even after data has been created, the `entity_type` can't be changed. -<6> `replicated_counter_map` describes the Replicated Data type for this entity. -<7> `key` points to the protobuf message representing the counter map's key type. + NOTE: Each Replicated Entity is associated with one underlying Replicated Data type. Replicated Data types that are generic, accepting type parameters for key, value, or element types, are used with `protobuf` messages and can represent structured data. In this shopping cart example, the keys of the counter map are products that have an id and name. @@ -76,7 +65,12 @@ include::example$java-replicatedentity-shopping-cart/src/main/proto/com/example/ <5> Every Command must contain a `string` field that contains the entity ID and is marked with the `(akkaserverless.field).entity_key` option. <6> Messages describe the return value for our API. For methods that don't have return values, we use `google.protobuf.Empty`. <7> The service descriptor shows the API of the entity. It lists the methods a client can use to issue Commands to the entity. -<8> The protobuf option `(akkaserverless.service)` is specific to code-generation as provided by the Akka Serverless Maven plugin and points to the protobuf definition `ShoppingCart` we've seen above (in the `com.example.shoppingcart.domain` package). +<8> The protobuf option `(akkaserverless.codegen)` is specific to code-generation as provided by the Akka Serverless Maven plugin. +<9> `replicated_entity` indicates that we want the codegen to generate a Replicated Entity for this service. +<10> `name` denotes the base name for the Replicated Entity. The code-generation will create initial sources `ShoppingCart` and `ShoppingCartIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. +<11> `entity_type` is a unique identifier for data replication. The entity name may be changed even after data has been created, the `entity_type` can't be changed. +<12> `replicated_counter_map` describes the Replicated Data type for this entity. +<13> `key` points to the protobuf message representing the counter map's key type. Scala:: + @@ -91,7 +85,12 @@ include::example$scala-replicatedentity-shopping-cart/src/main/proto/com/example <4> Every Command must contain a `string` field that contains the entity ID and is marked with the `(akkaserverless.field).entity_key` option. <5> Messages describe the return value for our API. For methods that don't have return values, we use `google.protobuf.Empty`. <6> The service descriptor shows the API of the entity. It lists the methods a client can use to issue Commands to the entity. -<7> The protobuf option `(akkaserverless.service)` is specific to code-generation as provided by the Akka Serverless Maven plugin and points to the protobuf definition `ShoppingCart` we've seen above (in the `com.example.shoppingcart.domain` package). +<7> The protobuf option `(akkaserverless.codegen)` is specific to code-generation as provided by the Akka Serverless Maven plugin. +<8> `replicated_entity` indicates that we want the codegen to generate a Replicated Entity for this service. +<9> `name` denotes the base name for the Replicated Entity. The code-generation will create initial sources `ShoppingCart` and `ShoppingCartIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. +<10> `entity_type` is a unique identifier for data replication. The entity name may be changed even after data has been created, the `entity_type` can't be changed. +<11> `replicated_counter_map` describes the Replicated Data type for this entity. +<12> `key` points to the protobuf message representing the counter map's key type. == Implementing behavior @@ -249,28 +248,30 @@ IMPORTANT: The **only** way for a command handler to modify the underlying data A link:{attachmentsdir}/api/com/akkaserverless/javasdk/replicatedentity/ReplicatedCounter.html[`ReplicatedCounter` {tab-icon}, window="new"] can be incremented and decremented. -To configure a Replicated Entity with a Replicated Counter, use the `replicated_counter` option when <<_defining_the_proto_files,defining the `proto` file>> for the entity domain: +To configure a Replicated Entity with a Replicated Counter, use the `replicated_counter` option when <<_defining_the_proto_files,defining the `proto` file>>: [.tabset] Java:: + [source,proto] -.src/main/proto/com/example/replicated/counter/domain/counter_domain.proto +.src/main/proto/com/example/replicated/counter/counter_api.proto ---- -include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/domain/counter_domain.proto[tag=replicated_entity] +include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto[tag=replicated_entity] ---- + -<1> Specify the Replicated Data type as a Replicated Counter. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Counter. Scala:: + [source,proto] -.src/main/proto/com/example/replicated/counter/domain/counter_domain.proto +.src/main/proto/com/example/replicated/counter/counter_api.proto ---- -include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/counter/domain/counter_domain.proto[tag=replicated_entity] +include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto[tag=replicated_entity] ---- + -<1> Specify the Replicated Data type as a Replicated Counter. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Counter. When implementing a Replicated Counter entity, the state can be updated by calling the `increment` or `decrement` methods on the current data object, and then triggering an update with the modified data object: @@ -325,28 +326,30 @@ A [.group-java]#link:{attachmentsdir}/api/com/akkaserverless/javasdk/replicatede ifdef::todo[TODO: configuring clocks for register replication] -To configure a Replicated Entity with a Replicated Register, use the `replicated_register` option when <<_defining_the_proto_files,defining the `proto` file>> for the entity domain: +To configure a Replicated Entity with a Replicated Register, use the `replicated_register` option when <<_defining_the_proto_files,defining the `proto` file>>: [.tabset] Java:: + [source,proto] -.src/main/proto/com/example/replicated/register/domain/register_domain.proto +.src/main/proto/com/example/replicated/register/register_api.proto ---- -include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto[tag=replicated_entity] +include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Register. -<2> Specify the `protobuf` type for the value of the Replicated Register. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Register. +<3> Specify the `protobuf` type for the value of the Replicated Register. Scala:: + [source,proto] -.src/main/proto/com/example/replicated/register/domain/register_domain.proto +.src/main/proto/com/example/replicated/register/register_api.proto ---- -include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto[tag=replicated_entity] +include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Register. -<2> Specify the `protobuf` type for the value of the Replicated Register. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Register. +<3> Specify the `protobuf` type for the value of the Replicated Register. NOTE: The type for the value can be a `protobuf` https://developers.google.com/protocol-buffers/docs/proto3#simple[message type] or https://developers.google.com/protocol-buffers/docs/proto3#scalar[scalar value type]. The generated code will use the corresponding Java type. A message type is being used for the value type in this example. @@ -423,28 +426,30 @@ NOTE: The current value may not be the most up-to-date value when there are conc A [.group-java]#link:{attachmentsdir}/api/com/akkaserverless/javasdk/replicatedentity/ReplicatedSet.html[`ReplicatedSet` {tab-icon}, window="new"]# [.group-scala]#link:{attachmentsdir}/scala-api/com/akkaserverless/scalasdk/replicatedentity/ReplicatedSet.html[`ReplicatedSet` {tab-icon}, window="new"]# is a set of (serializable) values, where elements can be added or removed. -To configure a Replicated Entity with a Replicated Set, use the `replicated_set` option when <<_defining_the_proto_files,defining the `proto` file>> for the entity domain: +To configure a Replicated Entity with a Replicated Set, use the `replicated_set` option when <<_defining_the_proto_files,defining the `proto` file>>: [.tabset] Java:: + [source,proto] -.src/main/proto/com/example/replicated/set/domain/set_domain.proto +.src/main/proto/com/example/replicated/set/set_api.proto ---- -include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto[tag=replicated_entity] +include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Set. -<2> Specify the `protobuf` type for the elements of the Replicated Set. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Set. +<3> Specify the `protobuf` type for the elements of the Replicated Set. In this case, the scalar type `string`. Scala:: + [source,proto] -.src/main/proto/com/example/replicated/set/domain/set_domain.proto +.src/main/proto/com/example/replicated/set/set_api.proto ---- -include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto[tag=replicated_entity] +include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Set. -<2> Specify the `protobuf` type for the elements of the Replicated Set. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Set. +<3> Specify the `protobuf` type for the elements of the Replicated Set. In this case, the scalar type `string`. NOTE: The type for the elements can be a `protobuf` https://developers.google.com/protocol-buffers/docs/proto3#simple[message type] or https://developers.google.com/protocol-buffers/docs/proto3#scalar[scalar value type]. The generated code will use the corresponding Java type. The `string` scalar type is being used for the element type in this example, which corresponds to the Java `String` class. @@ -505,28 +510,32 @@ NOTE: The current value may not be the most up-to-date view of the set when ther A [.group-java]#link:{attachmentsdir}/api/com/akkaserverless/javasdk/replicatedentity/ReplicatedCounterMap.html[`ReplicatedCounterMap` {tab-icon}, window="new"]# [.group-scala]#link:{attachmentsdir}/scala-api/com/akkaserverless/scalasdk/replicatedentity/ReplicatedCounterMap.html[`ReplicatedCounterMap` {tab-icon}, window="new"]# maps (serializable) keys to replicated counters, where each value can be incremented and decremented. -To configure a Replicated Entity with a Replicated Counter Map, use the `replicated_counter_map` option when <<_defining_the_proto_files,defining the `proto` file>> for the entity domain: +To configure a Replicated Entity with a Replicated Counter Map, use the `replicated_counter_map` option when <<_defining_the_proto_files,defining the `proto` file>>. [.tabset] Java:: + [source,proto] -.src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto +.src/main/proto/com/example/replicated/countermap/counter_map_api.proto ---- -include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto[tag=replicated_entity] +include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Counter Map. -<2> Specify the `protobuf` type for the keys of the Replicated Counter Map. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Counter Map. +<3> Specify the `protobuf` type for the keys of the Replicated Counter Map. In this case, the scalar type `string`. + Scala:: + [source,proto] -.src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto +.src/main/proto/com/example/replicated/countermap/counter_map_api.proto ---- -include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto[tag=replicated_entity] +include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Counter Map. -<2> Specify the `protobuf` type for the keys of the Replicated Counter Map. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Counter Map. +<3> Specify the `protobuf` type for the keys of the Replicated Counter Map. In this case, the scalar type `string`. + NOTE: The type for the key can be a `protobuf` https://developers.google.com/protocol-buffers/docs/proto3#simple[message type] or https://developers.google.com/protocol-buffers/docs/proto3#scalar[scalar value type]. The generated code will use the corresponding Java type. The `string` scalar type is being used for the key type in this example, which corresponds to the Java `String` class. @@ -586,30 +595,32 @@ A [.group-java]#link:{attachmentsdir}/api/com/akkaserverless/javasdk/replicatede ifdef::todo[TODO: configuring clocks for register replication] -To configure a Replicated Entity with a Replicated Register Map, use the `replicated_register_map` option when <<_defining_the_proto_files,defining the `proto` file>> for the entity domain: +To configure a Replicated Entity with a Replicated Register Map, use the `replicated_register_map` option when <<_defining_the_proto_files,defining the `proto` file>>. [.tabset] Java:: + [source,proto] -.src/main/proto/com/example/replicated/registermap/domain/register_map_domain.proto +.src/main/proto/com/example/replicated/registermap/register_map_api.proto ---- -include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/domain/register_map_domain.proto[tag=replicated_entity] +include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Register Map. -<2> Specify the `protobuf` type for the keys of the Replicated Register Map. -<3> Specify the `protobuf` type for the values of the Replicated Register Map. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Register Map. +<3> Specify the `protobuf` type for the keys of the Replicated Register Map. +<4> Specify the `protobuf` type for the values of the Replicated Register Map. Scala:: + [source,proto] .src/main/proto/com/example/replicated/registermap/domain/register_map_domain.proto ---- -include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/domain/register_map_domain.proto[tag=replicated_entity] +include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Register Map. -<2> Specify the `protobuf` type for the keys of the Replicated Register Map. -<3> Specify the `protobuf` type for the values of the Replicated Register Map. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Register Map. +<3> Specify the `protobuf` type for the keys of the Replicated Register Map. +<4> Specify the `protobuf` type for the values of the Replicated Register Map. NOTE: The type for the key or value can be a `protobuf` https://developers.google.com/protocol-buffers/docs/proto3#simple[message type] or https://developers.google.com/protocol-buffers/docs/proto3#scalar[scalar value type]. The generated code will use the corresponding Java type. Message types are being used for both the key and value types in this example. @@ -675,30 +686,32 @@ NOTE: Entries may not contain the most up-to-date values for registers when ther A [.group-java]#link:{attachmentsdir}/api/com/akkaserverless/javasdk/replicatedentity/ReplicatedMultiMap.html[`ReplicatedMultiMap` {tab-icon}, window="new"]# [.group-scala]#link:{attachmentsdir}/scala-api/com/akkaserverless/scalasdk/replicatedentity/ReplicatedMultiMap.html[`ReplicatedMultiMap` {tab-icon}, window="new"]# maps (serializable) keys to replicated sets of (serializable) values, providing a multi-map interface that can associate multiple values with each key. -To configure a Replicated Entity with a Replicated Multi-Map, use the `replicated_multi_map` option when <<_defining_the_proto_files,defining the `proto` file>> for the entity domain: +To configure a Replicated Entity with a Replicated Multi-Map, use the `replicated_multi_map` option when <<_defining_the_proto_files,defining the `proto` file>>. [.tabset] Java:: + [source,proto] -.src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto +.src/main/proto/com/example/replicated/multimap/multi_map_api.proto ---- -include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto[tag=replicated_entity] +include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Multi-Map. -<2> Specify the `protobuf` type for the keys of the Replicated Multi-Map. -<3> Specify the `protobuf` type for the values of the Replicated Multi-Map. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Multi-Map. +<3> Specify the `protobuf` type for the keys of the Replicated Multi-Map. In this case, the scalar type `string`. +<4> Specify the `protobuf` type for the values of the Replicated Multi-Map. In this case, the scalar type `double`. Scala:: + [source,proto] .src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto ---- -include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto[tag=replicated_entity] +include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Multi-Map. -<2> Specify the `protobuf` type for the keys of the Replicated Multi-Map. -<3> Specify the `protobuf` type for the values of the Replicated Multi-Map. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Multi-Map. +<3> Specify the `protobuf` type for the keys of the Replicated Multi-Map. In this case, the scalar type `string`. +<4> Specify the `protobuf` type for the values of the Replicated Multi-Map. In this case, the scalar type `double`. NOTE: The type for the key or value can be a `protobuf` https://developers.google.com/protocol-buffers/docs/proto3#simple[message type] or https://developers.google.com/protocol-buffers/docs/proto3#scalar[scalar value type]. The generated code will use the corresponding Java type. The `string` scalar type is being used for the key type and the `double` scalar type for the value type in this example, which correspond to the Java types for `String` and `Double`. @@ -757,28 +770,30 @@ A [.group-java]#link:{attachmentsdir}/api/com/akkaserverless/javasdk/replicatede NOTE: Prefer to use the specialized replicated maps (<<_replicated_counter_map>>, <<_replicated_register_map>>, or <<_replicated_multi_map>>) whenever the values of the map are of the same type -- counters, registers, or sets. -To configure a Replicated Entity with a (heterogeneous) Replicated Map, use the `replicated_map` option when <<_defining_the_proto_files,defining the `proto` file>> for the entity domain: +To configure a Replicated Entity with a (heterogeneous) Replicated Map, use the `replicated_map` option when <<_defining_the_proto_files,defining the `proto` file>>. [.tabset] Java:: + [source,proto] -.src/main/proto/com/example/replicated/map/domain/map_domain.proto +.src/main/proto/com/example/replicated/map/map_api.proto ---- -include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto[tag=replicated_entity] +include::example$java-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Map. -<2> Specify the `protobuf` type for the keys of the map. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Map. +<3> Specify the `protobuf` type for the keys of the map. Scala:: + [source,proto] -.src/main/proto/com/example/replicated/map/domain/map_domain.proto +.src/main/proto/com/example/replicated/map/map_api.proto ---- -include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto[tag=replicated_entity] +include::example$scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto[tag=replicated_entity] ---- -<1> Specify the Replicated Data type as a Replicated Map. -<2> Specify the `protobuf` type for the keys of the map. +<1> The fully-qualified class name for this replicated entity. +<2> Specify the Replicated Data type as a Replicated Map. +<3> Specify the `protobuf` type for the keys of the map. NOTE: The type for the key can be a `protobuf` https://developers.google.com/protocol-buffers/docs/proto3#simple[message type] or https://developers.google.com/protocol-buffers/docs/proto3#scalar[scalar value type]. The generated code will use the corresponding Java type. A message type is being used for the key type in this example. diff --git a/docs/src/modules/java/pages/side-effects.adoc b/docs/src/modules/java/pages/side-effects.adoc index ac95c3cb78..a64c4f4070 100644 --- a/docs/src/modules/java/pages/side-effects.adoc +++ b/docs/src/modules/java/pages/side-effects.adoc @@ -32,7 +32,7 @@ Java:: include::example$java-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto[tag=whole-double-action-proto] ---- <1> Import the Counter API definition -<2> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. +<2> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. <3> The Action mimics the Counter API with a forward <4> The Action mimics the Counter API with a side effect @@ -44,7 +44,7 @@ Scala:: include::example$scala-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto[tag=whole-double-action-proto] ---- <1> Import the Counter API definition -<2> The protobuf option (akkaserverless.service) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. +<2> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that an Action must be generated. <3> The Action mimics the Counter API with a forward <4> The Action mimics the Counter API with a side effect diff --git a/docs/src/modules/java/pages/value-entity.adoc b/docs/src/modules/java/pages/value-entity.adoc index 3728c8e6d3..4c6561c4c1 100644 --- a/docs/src/modules/java/pages/value-entity.adoc +++ b/docs/src/modules/java/pages/value-entity.adoc @@ -19,7 +19,7 @@ The sections on this page walk through these steps using a counter service as an NOTE: Our Value Entity example starts with the "Counter" service as included in the xref:quickstart-template.adoc[project template]. -The following `counter_domain.proto` file defines our "Counter" Value Entity. The entity stores an integer value as represented in the message `CounterState`. Real-world entities store much more data -- often structured data -- they represent an _Entity_ in the https://en.wikipedia.org/wiki/Domain-driven_design[domain-driven design] sense of the term. +The following `counter_domain.proto` file defines state the Entity will hold. The entity stores an integer value as represented in the message `CounterState`. Real-world entities store much more data -- often structured data -- they represent an _Entity_ in the https://en.wikipedia.org/wiki/Domain-driven_design[domain-driven design] sense of the term. [.tabset] Java:: @@ -30,13 +30,8 @@ Java:: include::example$java-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto[] ---- <1> Any classes generated from this protobuf file will be in the Java package `com.example.domain`. -<2> Import the Akka Serverless protobuf annotations or options. -<3> Let the messages declared in this protobuf file be inner classes to the Java class `CounterDomain`. -<4> The protobuf option `(akkaserverless.file).value_entity` is specific to code-generation as provided by the Akka Serverless Maven plugin. -<5> `name` denotes the base name for the Value Entity, the code-generation will create initial sources `Counter`, `CounterTest` and `CounterIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. -<6> `entity_type` is a unique identifier of the "state storage". The entity name may be changed even after data has been created, the `entity_type` can't. -<7> `state` points to the protobuf message representing the Value Entity's state which is kept by Akka Serverless. -<8> The `CounterState` protobuf message is what Akka Serverless stores for this entity. +<2> Let the messages declared in this protobuf file be inner classes to the Java class `CounterDomain`. +<3> The `CounterState` protobuf message is what Akka Serverless stores for this entity. Scala:: + @@ -46,14 +41,13 @@ Scala:: include::example$scala-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto[] ---- <1> Any classes generated from this protobuf file will be in the Scala package `com.example.domain`. -<2> Import the Akka Serverless protobuf annotations, or options. -<3> The protobuf option `(akkaserverless.file).value_entity` is specific to code-generation as provided by the Akka Serverless sbt plugin. -<4> `name` denotes the base name for the Value Entity, the code-generation will create initial sources `Counter`, `CounterTest` and `CounterIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. -<5> `entity_type` is a unique identifier of the "state storage". The entity name may be changed even after data has been created, the `entity_type` can't. -<6> `state` points to the protobuf message representing the Value Entity's state which is kept by Akka Serverless. -<7> The `CounterState` protobuf message is what Akka Serverless stores for this entity. +<2> The `CounterState` protobuf message is what Akka Serverless stores for this entity. + +The `counter_api.proto` file defines the commands we can send to the Counter service to manipulate or access the Counter's state. -The `counter_api.proto` file defines the commands we can send to the Counter service to manipulate or access the Counter's state. They make up the service API: +In this file we instruct the Akka Serverless Codegen which kind of component we want to create. The codegen will generate all stubs for your entity/service and corresponding tests, as well as an abstract class for your implementation to extend. + +They make up the service API: [.tabset] Java:: @@ -70,7 +64,11 @@ include::example$java-valueentity-counter/src/main/proto/com/example/counter_api <5> Every Command must contain a `string` field that contains the entity ID and is marked with the `(akkaserverless.field).entity_key` option. <6> Messages describe the return value for our API. For methods that don't have return values, we use `google.protobuf.Empty`. <7> The service descriptor shows the API of the entity. It lists the methods a client can use to issue Commands to the entity. -<8> The protobuf option `(akkaserverless.service)` is specific to code-generation as provided by the Akka Serverless Maven plugin and points to the protobuf definition `Counter` we've seen above (in the `com.example.domain` package). +<8> The protobuf option `(akkaserverless.codegen)` is specific to code-generation as provided by the Akka Serverless Maven plugin. +<9> `value_entity` indicates that we want the codegen to generate a Value Entity for this service. +<10> `name` denotes the base name for the Value Entity, the code-generation will create initial sources `Counter`, `CounterTest` and `CounterIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. +<11> `entity_type` is a unique identifier of the "state storage". The entity name may be changed even after data has been created, the `entity_type` can't. +<12> `state` points to the protobuf message representing the Value Entity's state which is kept by Akka Serverless. Note, the package and name follow the definion in the domain.proto file. Scala:: + @@ -85,7 +83,12 @@ include::example$scala-valueentity-counter/src/main/proto/com/example/counter_ap <4> Every Command must contain a `string` field that contains the entity ID and is marked with the `(akkaserverless.field).entity_key` option. <5> Messages describe the return value for our API. For methods that don't have return values, we use `google.protobuf.Empty`. <6> The service descriptor shows the API of the entity. It lists the methods a client can use to issue Commands to the entity. -<7> The protobuf option `(akkaserverless.service)` is specific to code-generation as provided by the Akka Serverless sbt plugin and points to the protobuf definition `Counter` we've seen above (in the `com.example.domain` package). +<7> The protobuf option `(akkaserverless.codegen)` is specific to code-generation as provided by the Akka Serverless Maven plugin. +<8> `value_entity` indicates that we want the codegen to generate a Value Entity for this service. +<9> `name` denotes the base name for the Value Entity, the code-generation will create initial sources `Counter`, `CounterTest` and `CounterIntegrationTest`. Once these files exist, they are not overwritten, so you can freely add logic to them. +<10> `entity_type` is a unique identifier of the "state storage". The entity name may be changed even after data has been created, the `entity_type` can't. +<11> `state` points to the protobuf message representing the Value Entity's state which is kept by Akka Serverless. Note, the package and name follow the definion in the domain.proto file. + == Implementing behavior diff --git a/docs/src/modules/java/pages/views.adoc b/docs/src/modules/java/pages/views.adoc index 682a351770..42067329a6 100644 --- a/docs/src/modules/java/pages/views.adoc +++ b/docs/src/modules/java/pages/views.adoc @@ -46,7 +46,26 @@ Scala:: include::example$scala-valueentity-customer-registry/src/main/proto/customer/domain/customer_domain.proto[tags=declarations;domain] ---- -<1> The `(akkaserverless.file).value_entity` option configures code generation to provide base classes and initial implementations for a Value Entity. + +As well as a Value Entity service that will produce the state changes consumed by the View: + +[.tabset] +Java:: ++ +[source,proto,indent=0] +.src/main/proto/customer/api/customer_api.proto +---- +include::example$java-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto[tags=value-entity] +---- + +Scala:: ++ +[source,proto,indent=0] +.src/main/proto/customer/api/customer_api.proto +---- +include::example$scala-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto[tags=value-entity] +---- + === Define the View service descriptor @@ -69,11 +88,12 @@ Scala:: include::example$scala-valueentity-customer-registry/src/main/proto/customer/view/customer_view.proto[tags=declarations;service] ---- -<1> The `UpdateCustomer` method defines how Akka Serverless will update the view. -<2> The source of the View is the `"customers"` Value Entity. This identifier is defined in the `entity_type: "customers"` property of the `(akkaserverless.file).value_entity` option in the `customer_domain.proto` file. -<3> The `(akkaserverless.method).view.update` annotation defines that this method is used for updating the View. You must define the `table` attribute for the table to be used in the query. Pick any name and use it in the query `SELECT` statement. -<4> The `GetCustomers` method defines the query to retrieve a stream of customers. -<5> The `(akkaserverless.method).view.query` annotation defines that this method is used as a query of the View. +<1> The protobuf option (akkaserverless.codegen) is specific to code-generation as provided by the Akka Serverless Maven plugin. This annotation indicates to the code-generation that a View must be generated. +<2> The `UpdateCustomer` method defines how Akka Serverless will update the view. +<3> The source of the View is the `"customers"` Value Entity. This identifier is defined in the `entity_type: "customers"` property of the `(akkaserverless.codegen).value_entity` option in the `customer_api.proto` file. +<4> The `(akkaserverless.method).view.update` annotation defines that this method is used for updating the View. You must define the `table` attribute for the table to be used in the query. Pick any name and use it in the query `SELECT` statement. +<5> The `GetCustomers` method defines the query to retrieve a stream of customers. +<6> The `(akkaserverless.method).view.query` annotation defines that this method is used as a query of the View. NOTE: In this sample we use the internal `domain.CustomerState` as the state of the view. This is convenient since it allows automatic updates of the view without any logic but has the draw back that it implicitly makes the `domain.CustomerState` type a part of the public service API. Transforming the state to another type than the incoming update to avoid this can be seen in <<#event-sourced-entity>>. @@ -139,7 +159,7 @@ Java:: [source,proto,indent=0] .src/main/proto/customer/domain/customer_domain.proto ---- -include::example$java-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto[tags=declarations;domain;events] +include::example$java-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto[tags=declarations;state;events] ---- Scala:: @@ -147,10 +167,10 @@ Scala:: [source,proto,indent=0] .src/main/proto/customer/domain/customer_domain.proto ---- -include::example$scala-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto[tags=declarations;domain;events] +include::example$scala-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto[tags=declarations;state;events] ---- -It also assumes a `customer_api.proto` that defines the state stored in the view and returned by queries: +As well as an Event Sourced Entity service that will produce the events consumed by the View: [.tabset] Java:: @@ -158,7 +178,7 @@ Java:: [source,proto,indent=0] .src/main/proto/customer/api/customer_api.proto ---- -include::example$java-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto[tags=declarations;view] +include::example$java-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto[tags=eventsourced-entity] ---- Scala:: @@ -166,7 +186,7 @@ Scala:: [source,proto,indent=0] .src/main/proto/customer/api/customer_api.proto ---- -include::example$scala-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto[tags=declarations;view] +include::example$scala-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto[tags=eventsourced-entity] ---- @@ -182,9 +202,9 @@ Java:: ---- include::example$java-eventsourced-customer-registry/src/main/proto/customer/view/customer_view.proto[tags=declarations;service-event-sourced] ---- -<1> The `akkaserverless.service` option configures code generation to provide base classes and an initial implementation for the class transforming events to updates of the state. +<1> The `akkaserverless.codegen` option configures code generation to provide base classes and an initial implementation for the class transforming events to updates of the state. <2> Define an update method for each event. -<3> The source of the View is from the journal of the `"customers"` Event Sourced Entity. This identifier is defined in the entity_type: "customers"` property of the `(akkaserverless.file).event_sourced_entity` option in the `customer_domain.proto` file. +<3> The source of the View is from the journal of the `"customers"` Event Sourced Entity. This identifier is defined in the entity_type: "customers"` property of the `(akkaserverless.codegen).event_sourced_entity` option in the `customer_api.proto` file. <4> Enable `transform_updates` to build the View state from the events. <5> The same `event_sourced_entity` for all update methods. Note the required `table` attribute. Use any name, which you will reference in the query `SELECT` statement. <6> Enable `transform_updates` for all update methods. diff --git a/docs/src/modules/java/pages/writing-grpc-descriptors-protobuf.adoc b/docs/src/modules/java/pages/writing-grpc-descriptors-protobuf.adoc index 132dfb5dcc..b036764f09 100644 --- a/docs/src/modules/java/pages/writing-grpc-descriptors-protobuf.adoc +++ b/docs/src/modules/java/pages/writing-grpc-descriptors-protobuf.adoc @@ -54,6 +54,7 @@ To use a multi-field key, add the `entity_key` notation to each field. For examp message SomeMessage { string first_field = 1 [(akkaserverless.field).entity_key = true]; string second_field = 2 [(akkaserverless.field).entity_key = true]; +} ---- === Service @@ -62,48 +63,33 @@ This section of the `.proto` file declares the API of the service itself, along The `AddItem` and `RemoveItem` methods have no return value (the `Empty` type). -See <<_transcoding_http>> for an explanation of the HTTP annotations. +Most importantly, in this file we instruct the Akka Serverless Codegen which kind of component we want to create. The codegen will generate all stubs for your entity/service and corresponding tests, as well as an abstract class for your implementation to extend. .src/main/proto/com/example/shoppingcart/shoppingcart_api.proto [source,proto] ---- include::example$java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto[tag=proto_service] ---- -<1> See <<_transcoding_http>> below -<2> See <<_transcoding_http>> below -<3> See <<_transcoding_http>> below + +<1> Indicates to the codegen that we want to generate a Value Entity +<2> The package and name of our Value Entity +<3> Unique identifier of the "state storage" for this entity. The entity name may be changed even after data has been created, the `entity_type` can't. +<4> The Entity state using a fully-qualified name. Note, the package and name follow the definion in the domain.proto file (see below) == The domain proto file -The `shoppingcart_domain.proto` file specifies the state and messages for an Event Sourced Entity. It defines the gRPC version: +The `shoppingcart_domain.proto` file specifies the state and messages for an Event Sourced Entity. .src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto [source,proto] ---- -include::example$java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[tag=proto_syntax] ----- - -It only needs to include the import for `akkaserverless/annotations.proto`: - -[source,proto] ----- -include::example$java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[tag=proto_imports] ----- - -The following defines the `ShoppingCart` Entity state: - -[source,proto] ----- -include::example$java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[tag=proto_state] +include::example$java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[tag=domain] ---- -It includes the messages that define the entity state: - -[source,proto] ----- -include::example$java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto[tag=proto_messages] ----- +<1> Defines the gRPC version +<2> The proto package for the state +<3> The Entity's state defined as a proto message [#_transcoding_http] == Transcoding HTTP @@ -115,7 +101,7 @@ In the example below, the optional transcoding of the service to bind the variou [source,proto] .src/main/proto/com/example/shoppingcart/shoppingcart_api.proto ---- -include::example$java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto[tag=proto_service] +include::example$java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto[tag=http-transcoding] ---- <1> This extra annotation specifies that you can call this endpoint using the POST method with the URI `/cart/\{user_id}/items/add`, where `\{user_id}` is the actual user id we want the cart for. <2> A URL that accepts a POST method to remove a line item. diff --git a/maven-java/akkaserverless-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/counter_api.proto b/maven-java/akkaserverless-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/counter_api.proto index fbf82083eb..1b7128b28e 100644 --- a/maven-java/akkaserverless-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/counter_api.proto +++ b/maven-java/akkaserverless-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/counter_api.proto @@ -10,35 +10,42 @@ package $package; option java_outer_classname = "CounterApi"; message IncreaseValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; - int32 value = 2; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; + int32 value = 2; } message DecreaseValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; - int32 value = 2; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; + int32 value = 2; } message ResetValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; } message GetCounter { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; } message CurrentCounter { - int32 value = 1; + int32 value = 1; } service CounterService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ENTITY - component : "${package}.domain.Counter" - }; - - rpc Increase(IncreaseValue) returns (google.protobuf.Empty); - rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); - rpc Reset(ResetValue) returns (google.protobuf.Empty); - rpc GetCurrentCounter(GetCounter) returns (CurrentCounter); + option (akkaserverless.codegen) = { + event_sourced_entity: { + name: "${package}.domain.Counter" + entity_type: "counter" + state: "${package}.domain.CounterState" + events: [ + "${package}.domain.ValueIncreased", + "${package}.domain.ValueDecreased", + "${package}.domain.ValueReset"] + } + }; + + rpc Increase(IncreaseValue) returns (google.protobuf.Empty); + rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); + rpc Reset(ResetValue) returns (google.protobuf.Empty); + rpc GetCurrentCounter(GetCounter) returns (CurrentCounter); } \ No newline at end of file diff --git a/maven-java/akkaserverless-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/domain/counter_domain.proto b/maven-java/akkaserverless-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/domain/counter_domain.proto index f3183dca64..68a5647abf 100644 --- a/maven-java/akkaserverless-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/domain/counter_domain.proto +++ b/maven-java/akkaserverless-maven-archetype-event-sourced-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/domain/counter_domain.proto @@ -2,27 +2,18 @@ syntax = "proto3"; package ${package}.domain; -import "akkaserverless/annotations.proto"; - option java_outer_classname = "CounterDomain"; -option (akkaserverless.file).event_sourced_entity = { - name: "Counter" - entity_type: "counter" - state: "CounterState" - events: ["ValueIncreased","ValueDecreased","ValueReset"] -}; - message CounterState { - int32 value = 1; + int32 value = 1; } message ValueIncreased { - int32 value = 1; + int32 value = 1; } message ValueDecreased { - int32 value = 1; + int32 value = 1; } message ValueReset { diff --git a/maven-java/akkaserverless-maven-archetype-value-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/counter_api.proto b/maven-java/akkaserverless-maven-archetype-value-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/counter_api.proto index 14e081cc45..81f68b4013 100644 --- a/maven-java/akkaserverless-maven-archetype-value-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/counter_api.proto +++ b/maven-java/akkaserverless-maven-archetype-value-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/counter_api.proto @@ -10,35 +10,38 @@ package $package; option java_outer_classname = "CounterApi"; message IncreaseValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; - int32 value = 2; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; + int32 value = 2; } message DecreaseValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; - int32 value = 2; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; + int32 value = 2; } message ResetValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; } message GetCounter { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; } message CurrentCounter { - int32 value = 1; + int32 value = 1; } service CounterService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ENTITY - component : "${package}.domain.Counter" - }; - - rpc Increase(IncreaseValue) returns (google.protobuf.Empty); - rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); - rpc Reset(ResetValue) returns (google.protobuf.Empty); - rpc GetCurrentCounter(GetCounter) returns (CurrentCounter); + option (akkaserverless.codegen) = { + value_entity: { + name: "${package}.domain.Counter" + entity_type: "counter" + state: "${package}.domain.CounterState" + } + }; + + rpc Increase(IncreaseValue) returns (google.protobuf.Empty); + rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); + rpc Reset(ResetValue) returns (google.protobuf.Empty); + rpc GetCurrentCounter(GetCounter) returns (CurrentCounter); } diff --git a/maven-java/akkaserverless-maven-archetype-value-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/domain/counter_domain.proto b/maven-java/akkaserverless-maven-archetype-value-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/domain/counter_domain.proto index 91243e7a54..d55c095508 100644 --- a/maven-java/akkaserverless-maven-archetype-value-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/domain/counter_domain.proto +++ b/maven-java/akkaserverless-maven-archetype-value-entity/src/main/resources/archetype-resources/src/main/proto/__packageInPathFormat__/domain/counter_domain.proto @@ -2,16 +2,8 @@ syntax = "proto3"; package ${package}.domain; -import "akkaserverless/annotations.proto"; - option java_outer_classname = "CounterDomain"; -option (akkaserverless.file).value_entity = { - name: "Counter" - entity_type: "counter" - state: "CounterState" -}; - message CounterState { - int32 value = 1; + int32 value = 1; } diff --git a/samples/java-doc-snippets/src/main/proto/com/example/delegating_service.proto b/samples/java-doc-snippets/src/main/proto/com/example/delegating_service.proto index e36b99ddf9..28167a2f0b 100644 --- a/samples/java-doc-snippets/src/main/proto/com/example/delegating_service.proto +++ b/samples/java-doc-snippets/src/main/proto/com/example/delegating_service.proto @@ -15,8 +15,8 @@ message Result { } service DelegatingService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; rpc AddAndReturn(Request) returns (Result); diff --git a/samples/java-doc-snippets/src/main/proto/com/example/json/json_api.proto b/samples/java-doc-snippets/src/main/proto/com/example/json/json_api.proto index 2ab13a428f..b6c98241ec 100644 --- a/samples/java-doc-snippets/src/main/proto/com/example/json/json_api.proto +++ b/samples/java-doc-snippets/src/main/proto/com/example/json/json_api.proto @@ -14,8 +14,8 @@ message KeyValue { } service MyService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; rpc Consume(google.protobuf.Any) returns (google.protobuf.Empty) { // <1> diff --git a/samples/java-doc-snippets/src/main/proto/com/example/topics_action.proto b/samples/java-doc-snippets/src/main/proto/com/example/topics_action.proto index b5ca87c3be..799f42b047 100644 --- a/samples/java-doc-snippets/src/main/proto/com/example/topics_action.proto +++ b/samples/java-doc-snippets/src/main/proto/com/example/topics_action.proto @@ -21,8 +21,8 @@ message TopicOperation { // tag::text[] service MyTopicsAction { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; // end::bytes[] diff --git a/samples/java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto b/samples/java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto index 924daa4eef..df081d9bce 100644 --- a/samples/java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto +++ b/samples/java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto @@ -34,8 +34,8 @@ message Decreased { } service CounterJournalToTopic { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <2> + option (akkaserverless.codegen) = { + action: {} // <2> }; rpc Increase (com.example.domain.ValueIncreased) returns (Increased) { // <3> diff --git a/samples/java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto b/samples/java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto index 75ec4f37e3..fb2e45e442 100644 --- a/samples/java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto +++ b/samples/java-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto @@ -23,8 +23,8 @@ import "google/protobuf/empty.proto"; option java_outer_classname = "CounterTopicSubApi"; service CounterTopicSubscription { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <2> + option (akkaserverless.codegen) = { + action: {} // <2> }; rpc Increase (com.example.actions.Increased) returns (google.protobuf.Empty) { diff --git a/samples/java-eventsourced-counter/src/main/proto/com/example/counter_api.proto b/samples/java-eventsourced-counter/src/main/proto/com/example/counter_api.proto index 16276ccad4..fc3d5c2374 100644 --- a/samples/java-eventsourced-counter/src/main/proto/com/example/counter_api.proto +++ b/samples/java-eventsourced-counter/src/main/proto/com/example/counter_api.proto @@ -32,10 +32,17 @@ message CurrentCounter { } service CounterService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ENTITY - component : "com.example.domain.Counter" - }; + option (akkaserverless.codegen) = { + event_sourced_entity: { + name: "com.example.domain.Counter" + entity_type: "counter" + state: "com.example.domain.CounterState" + events: [ + "com.example.domain.ValueIncreased", + "com.example.domain.ValueDecreased", + "com.example.domain.ValueReset"] + } + }; rpc Increase(IncreaseValue) returns (google.protobuf.Empty); rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); diff --git a/samples/java-eventsourced-counter/src/main/proto/com/example/domain/counter_domain.proto b/samples/java-eventsourced-counter/src/main/proto/com/example/domain/counter_domain.proto index 988eb7cffc..0461d3064e 100644 --- a/samples/java-eventsourced-counter/src/main/proto/com/example/domain/counter_domain.proto +++ b/samples/java-eventsourced-counter/src/main/proto/com/example/domain/counter_domain.proto @@ -2,17 +2,8 @@ syntax = "proto3"; package com.example.domain; -import "akkaserverless/annotations.proto"; - option java_outer_classname = "CounterDomain"; -option (akkaserverless.file).event_sourced_entity = { - name: "Counter" - entity_type: "counter" - state: "CounterState" - events: ["ValueIncreased","ValueDecreased","ValueReset"] -}; - message CounterState { int32 value = 1; } diff --git a/samples/java-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto b/samples/java-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto index 41f7084536..df14d9383c 100644 --- a/samples/java-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto +++ b/samples/java-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto @@ -16,15 +16,11 @@ syntax = "proto3"; package customer.api; -// tag::declarations[] option java_outer_classname = "CustomerApi"; import "google/protobuf/empty.proto"; import "akkaserverless/annotations.proto"; -// end::declarations[] - -// tag::view[] message Customer { string customer_id = 1 [(akkaserverless.field).entity_key = true]; string email = 2; @@ -36,7 +32,6 @@ message Address { string street = 1; string city = 2; } -// end::view[] message GetCustomerRequest { string customer_id = 1 [(akkaserverless.field).entity_key = true]; @@ -52,17 +47,23 @@ message ChangeAddressRequest { Address new_address = 2; } + +// tag::eventsourced-entity[] service CustomerService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "customer.domain.CustomerEntity" + option (akkaserverless.codegen) = { + event_sourced_entity: { + name: "customer.domain.CustomerEntity" + entity_type: "customers" + state: "customer.domain.CustomerState" + events: [ + "customer.domain.CustomerCreated", + "customer.domain.CustomerNameChanged", + "customer.domain.CustomerAddressChanged"] + } }; - rpc Create(Customer) returns (google.protobuf.Empty) {} - rpc ChangeName(ChangeNameRequest) returns (google.protobuf.Empty) {} - rpc ChangeAddress(ChangeAddressRequest) returns (google.protobuf.Empty) {} - rpc GetCustomer(GetCustomerRequest) returns (Customer) {} } +// end::eventsourced-entity[] diff --git a/samples/java-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto b/samples/java-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto index c43908ec17..e76dbe411d 100644 --- a/samples/java-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto +++ b/samples/java-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto @@ -14,23 +14,11 @@ // tag::declarations[] syntax = "proto3"; - package customer.domain; - option java_outer_classname = "CustomerDomain"; - //end::declarations[] -// tag::domain[] -import "akkaserverless/annotations.proto"; - -option (akkaserverless.file).event_sourced_entity = { // <1> - name: "CustomerEntity" - entity_type: "customers" - state: "CustomerState" - events: ["CustomerCreated", "CustomerNameChanged", "CustomerAddressChanged"] -}; - +// tag::state[] message CustomerState { string customer_id = 1; string email = 2; @@ -42,7 +30,7 @@ message Address { string street = 1; string city = 2; } -// end::domain[] +// end::state[] // tag::events[] message CustomerCreated { diff --git a/samples/java-eventsourced-customer-registry/src/main/proto/customer/view/customer_view.proto b/samples/java-eventsourced-customer-registry/src/main/proto/customer/view/customer_view.proto index daa959a45b..36f772b3f2 100644 --- a/samples/java-eventsourced-customer-registry/src/main/proto/customer/view/customer_view.proto +++ b/samples/java-eventsourced-customer-registry/src/main/proto/customer/view/customer_view.proto @@ -32,8 +32,8 @@ message ByNameRequest { } service CustomerByName { - option (akkaserverless.service) = { // <1> - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { // <1> + view: {} }; rpc ProcessCustomerCreated(domain.CustomerCreated) returns (api.Customer) { // <2> diff --git a/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto b/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto index 17ff8d065e..204f661d28 100644 --- a/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto +++ b/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto @@ -6,19 +6,7 @@ syntax = "proto3"; package com.example.shoppingcart.domain; // <1> -import "akkaserverless/annotations.proto"; // <2> - -option java_outer_classname = "ShoppingCartDomain"; // <3> - -// tag::event_sourced_entity[] -// Describes how this domain relates to an event sourced entity -option (akkaserverless.file).event_sourced_entity = { // <4> - name: "ShoppingCart" // <5> - entity_type: "shopping-cart" // <6> - state: "Cart" // <7> - events: ["ItemAdded", "ItemRemoved"] // <8> -}; -// end::event_sourced_entity[] +option java_outer_classname = "ShoppingCartDomain"; // <2> message LineItem { string productId = 1; diff --git a/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto b/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto index c527cba607..64a4c3ec70 100644 --- a/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto +++ b/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto @@ -37,9 +37,15 @@ message Cart { // <6> } service ShoppingCartService { // <7> - option (akkaserverless.service) = { // <8> - type: SERVICE_TYPE_ENTITY - component: "com.example.shoppingcart.domain.ShoppingCart" + option (akkaserverless.codegen) = { // <8> + event_sourced_entity: { // <9> + name: "com.example.shoppingcart.domain.ShoppingCart" // <10> + entity_type: "shopping-cart" // <11> + state: "com.example.shoppingcart.domain.Cart" // <12> + events: [ + "com.example.shoppingcart.domain.ItemAdded", // <13> + "com.example.shoppingcart.domain.ItemRemoved"] + } }; rpc AddItem (AddLineItem) returns (google.protobuf.Empty) { diff --git a/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/view/shopping_cart_view_model.proto b/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/view/shopping_cart_view_model.proto index 4a5c1ecf0b..b9689e0e2d 100644 --- a/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/view/shopping_cart_view_model.proto +++ b/samples/java-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/view/shopping_cart_view_model.proto @@ -22,8 +22,8 @@ import "akkaserverless/annotations.proto"; import "com/example/shoppingcart/domain/shoppingcart_domain.proto"; service ShoppingCartViewService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} }; rpc ProcessAdded(com.example.shoppingcart.domain.ItemAdded) returns (CartViewState) { diff --git a/samples/java-fibonacci-action/src/main/proto/com/example/fibonacci/fibonacci.proto b/samples/java-fibonacci-action/src/main/proto/com/example/fibonacci/fibonacci.proto index 01a8a90aa8..2b6a818a2e 100644 --- a/samples/java-fibonacci-action/src/main/proto/com/example/fibonacci/fibonacci.proto +++ b/samples/java-fibonacci-action/src/main/proto/com/example/fibonacci/fibonacci.proto @@ -25,8 +25,8 @@ message Number { } service Fibonacci { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <4> + option (akkaserverless.codegen) = { + action: {} // <4> }; rpc NextNumber(Number) returns (Number) {} diff --git a/samples/java-first-service/src/main/proto/com/example/counter_api.proto b/samples/java-first-service/src/main/proto/com/example/counter_api.proto index b34eca1bb5..ad5180e646 100644 --- a/samples/java-first-service/src/main/proto/com/example/counter_api.proto +++ b/samples/java-first-service/src/main/proto/com/example/counter_api.proto @@ -10,35 +10,37 @@ package com.example; option java_outer_classname = "CounterApi"; message IncreaseValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; - int32 value = 2; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; + int32 value = 2; } message DecreaseValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; - int32 value = 2; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; + int32 value = 2; } message ResetValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; } message GetCounter { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; } message CurrentCounter { - int32 value = 1; + int32 value = 1; } service CounterService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ENTITY - component : "com.example.domain.Counter" - }; - - rpc Increase(IncreaseValue) returns (google.protobuf.Empty); - rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); - rpc Reset(ResetValue) returns (google.protobuf.Empty); - rpc GetCurrentCounter(GetCounter) returns (CurrentCounter); + option (akkaserverless.codegen) = { + value_entity: { + name: ".domain.Counter" + entity_type: "counter" + state: ".domain.CounterState" + } + }; + rpc Increase(IncreaseValue) returns (google.protobuf.Empty); + rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); + rpc Reset(ResetValue) returns (google.protobuf.Empty); + rpc GetCurrentCounter(GetCounter) returns (CurrentCounter); } diff --git a/samples/java-first-service/src/main/proto/com/example/domain/counter_domain.proto b/samples/java-first-service/src/main/proto/com/example/domain/counter_domain.proto index 98ff5a1cfb..2e2f1ad3b2 100644 --- a/samples/java-first-service/src/main/proto/com/example/domain/counter_domain.proto +++ b/samples/java-first-service/src/main/proto/com/example/domain/counter_domain.proto @@ -2,16 +2,8 @@ syntax = "proto3"; package com.example.domain; -import "akkaserverless/annotations.proto"; - option java_outer_classname = "CounterDomain"; -option (akkaserverless.file).value_entity = { - name: "Counter" - entity_type: "counter" - state: "CounterState" -}; - message CounterState { - int32 value = 1; + int32 value = 1; } diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto index efb1af4988..5a9242762d 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto @@ -39,13 +39,18 @@ message CurrentValue { int64 value = 1; } +// tag::replicated_entity[] service CounterService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.counter.domain.SomeCounter" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.counter.domain.SomeCounter" // <1> + entity_type: "some-counter" + replicated_counter: {} // <2> + } }; rpc Increase(IncreaseValue) returns (google.protobuf.Empty); rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); rpc Get(GetValue) returns (CurrentValue); } +// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/domain/counter_domain.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/domain/counter_domain.proto deleted file mode 100644 index e023928f00..0000000000 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/counter/domain/counter_domain.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package com.example.replicated.counter.domain; - -import "akkaserverless/annotations.proto"; - -option java_outer_classname = "SomeCounterDomain"; - -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeCounter" - entity_type: "some-counter" - replicated_counter: {} // <1> -}; -// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto index d798bbcfde..0393ef80a2 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto @@ -55,10 +55,16 @@ message CurrentValues { map values = 1; } +// tag::replicated_entity[] service CounterMapService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.countermap.domain.SomeCounterMap" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.countermap.domain.SomeCounterMap" // <1> + entity_type: "some-counter-map" + replicated_counter_map: { // <2> + key: "string" // <3> + } + } }; rpc Increase(IncreaseValue) returns (google.protobuf.Empty); @@ -67,3 +73,4 @@ service CounterMapService { rpc Get(GetValue) returns (CurrentValue); rpc GetAll(GetAllValues) returns (CurrentValues); } +// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto deleted file mode 100644 index 8ffb53f011..0000000000 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2021 Lightbend Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package com.example.replicated.countermap.domain; - -import "akkaserverless/annotations.proto"; - -option java_outer_classname = "SomeCounterMapDomain"; - -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeCounterMap" - entity_type: "some-counter-map" - replicated_counter_map: { // <1> - key: "string" // <2> - } -}; -// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto index a84df38564..b469e4b039 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto @@ -16,20 +16,8 @@ syntax = "proto3"; package com.example.replicated.map.domain; -import "akkaserverless/annotations.proto"; - option java_outer_classname = "SomeMapDomain"; -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeMap" - entity_type: "some-map" - replicated_map: { // <1> - key: "SomeKey" // <2> - } -}; - message SomeKey { string some_field = 1; } -// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto index 88060ae3a0..2559859c38 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto @@ -56,10 +56,16 @@ message CurrentValues { repeated string baz = 3; } +// tag::replicated_entity[] service MapService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.map.domain.SomeMap" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.map.domain.SomeMap" // <1> + entity_type: "some-map" + replicated_map: { // <2> + key: "com.example.replicated.map.domain.SomeKey" // <3> + } + } }; rpc IncreaseFoo(IncreaseFooValue) returns (google.protobuf.Empty); @@ -69,3 +75,4 @@ service MapService { rpc RemoveBaz(RemoveBazValue) returns (google.protobuf.Empty); rpc Get(GetValues) returns (CurrentValues); } +// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto deleted file mode 100644 index 2de56d2d44..0000000000 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2021 Lightbend Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package com.example.replicated.multimap.domain; - -import "akkaserverless/annotations.proto"; - -option java_outer_classname = "SomeMultiMapDomain"; - -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeMultiMap" - entity_type: "some-multi-map" - replicated_multi_map: { // <1> - key: "string" // <2> - value: "double" // <3> - } -}; -// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto index ffe75b7bb4..8834b02ab4 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto @@ -62,10 +62,17 @@ message AllCurrentValues { repeated CurrentValues values = 1; } +// tag::replicated_entity[] service MultiMapService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.multimap.domain.SomeMultiMap" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.multimap.domain.SomeMultiMap" // <1> + entity_type: "some-multi-map" + replicated_multi_map: { // <2> + key: "string" // <3> + value: "double" // <4> + } + } }; rpc Put(PutValue) returns (google.protobuf.Empty); @@ -75,3 +82,4 @@ service MultiMapService { rpc Get(GetValues) returns (CurrentValues); rpc GetAll(GetAllValues) returns (AllCurrentValues); } +// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto index 2b3289c46a..1d28b6e55a 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto @@ -16,19 +16,9 @@ syntax = "proto3"; package com.example.replicated.register.domain; -import "akkaserverless/annotations.proto"; - option java_outer_classname = "SomeRegisterDomain"; // tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeRegister" - entity_type: "some-register" - replicated_register: { // <1> - value: "SomeValue" // <2> - } -}; - message SomeValue { string some_field = 1; } diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto index a02823de46..bc26f9d49e 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto @@ -34,12 +34,19 @@ message CurrentValue { string value = 1; } +// tag::replicated_entity[] service RegisterService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.register.domain.SomeRegister" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.register.domain.SomeRegister" // <1> + entity_type: "some-register" + replicated_register: { // <2> + value: "com.example.replicated.register.domain.SomeValue" // <3> + } + } }; rpc Set(SetValue) returns (google.protobuf.Empty); rpc Get(GetValue) returns (CurrentValue); } +// end::replicated_entity[] \ No newline at end of file diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/domain/register_map_domain.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/domain/register_map_domain.proto index 0329cb0c92..67e80b9aeb 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/domain/register_map_domain.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/domain/register_map_domain.proto @@ -16,25 +16,12 @@ syntax = "proto3"; package com.example.replicated.registermap.domain; -import "akkaserverless/annotations.proto"; - option java_outer_classname = "SomeRegisterMapDomain"; -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeRegisterMap" - entity_type: "some-register-map" - replicated_register_map: { // <1> - key: "SomeKey" // <2> - value: "SomeValue" // <3> - } -}; - message SomeKey { string some_field = 1; } message SomeValue { string some_field = 1; -} -// end::replicated_entity[] +} \ No newline at end of file diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto index d1b27ad7c5..af63d5049d 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto @@ -58,10 +58,18 @@ message CurrentValues { repeated CurrentValue values = 1; } + +// tag::replicated_entity[] service RegisterMapService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.registermap.domain.SomeRegisterMap" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.registermap.domain.SomeRegisterMap" // <1> + entity_type: "some-register-map" + replicated_register_map: { // <2> + key: "com.example.replicated.registermap.domain.SomeKey" // <3> + value: "com.example.replicated.registermap.domain.SomeValue" // <4> + } + } }; rpc Set(SetValue) returns (google.protobuf.Empty); @@ -69,3 +77,4 @@ service RegisterMapService { rpc Get(GetValue) returns (CurrentValue); rpc GetAll(GetAllValues) returns (CurrentValues); } +// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto deleted file mode 100644 index aa0182aef9..0000000000 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2021 Lightbend Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package com.example.replicated.set.domain; - -import "akkaserverless/annotations.proto"; - -option java_outer_classname = "SomeSetDomain"; - -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeSet" - entity_type: "some-set" - replicated_set: { // <1> - element: "string" // <2> - } -}; -// end::replicated_entity[] diff --git a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto index c48453925e..559d29332f 100644 --- a/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto +++ b/samples/java-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto @@ -40,13 +40,20 @@ message CurrentElements { repeated string elements = 1; } +// tag::replicated_entity[] service SetService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.set.domain.SomeSet" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.set.domain.SomeSet" // <1> + entity_type: "some-set" + replicated_set: { // <2> + element: "string" // <3> + } + } }; rpc Add(AddElement) returns (google.protobuf.Empty); rpc Remove(RemoveElement) returns (google.protobuf.Empty); rpc Get(GetElements) returns (CurrentElements); } +// end::replicated_entity[] \ No newline at end of file diff --git a/samples/java-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto b/samples/java-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto index 7697fc8bcf..9b291de91b 100644 --- a/samples/java-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto +++ b/samples/java-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto @@ -4,18 +4,7 @@ syntax = "proto3"; package com.example.shoppingcart.domain; // <1> -import "akkaserverless/annotations.proto"; // <2> - -option java_outer_classname = "ShoppingCartDomain"; // <3> - -// Describes how this domain relates to a replicated entity -option (akkaserverless.file).replicated_entity = { // <4> - name: "ShoppingCart" // <5> - entity_type: "shopping-cart" // <6> - replicated_counter_map: { // <7> - key: "Product" // <8> - } -}; +option java_outer_classname = "ShoppingCartDomain"; // <2> message Product { string id = 1; diff --git a/samples/java-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto b/samples/java-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto index 7465a990be..ffe205c9ab 100644 --- a/samples/java-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto +++ b/samples/java-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto @@ -42,9 +42,14 @@ message Cart { // <6> } service ShoppingCartService { // <7> - option (akkaserverless.service) = { // <8> - type: SERVICE_TYPE_ENTITY - component: "com.example.shoppingcart.domain.ShoppingCart" + option (akkaserverless.codegen) = { // <8> + replicated_entity: { // <9> + name: "com.example.shoppingcart.domain.ShoppingCart" // <10> + entity_type: "shopping-cart" // <11> + replicated_counter_map: { // <12> + key: "com.example.shoppingcart.domain.Product" // <13> + } + } }; rpc AddItem (AddLineItem) returns (google.protobuf.Empty) { @@ -74,4 +79,3 @@ service ShoppingCartService { // <7> option (google.api.http).post = "/carts/{cart_id}/remove"; } } - diff --git a/samples/java-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto b/samples/java-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto index af014d987f..562335144f 100644 --- a/samples/java-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto +++ b/samples/java-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto @@ -23,8 +23,8 @@ import "google/protobuf/empty.proto"; option java_outer_classname = "StateSubscriptionApi"; service CounterStateSubscription { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <2> + option (akkaserverless.codegen) = { + action: {} // <2> }; rpc OnUpdateState (com.example.domain.CounterState) returns (google.protobuf.Empty) { diff --git a/samples/java-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto b/samples/java-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto index ab07ad6150..130175ae3a 100644 --- a/samples/java-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto +++ b/samples/java-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto @@ -24,8 +24,8 @@ import "google/protobuf/empty.proto"; option java_outer_classname = "DoubleCounterApi"; service DoubleCounter { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <2> + option (akkaserverless.codegen) = { + action: {} // <2> }; rpc Increase (com.example.IncreaseValue) returns (google.protobuf.Empty); // <3> diff --git a/samples/java-valueentity-counter/src/main/proto/com/example/counter_api.proto b/samples/java-valueentity-counter/src/main/proto/com/example/counter_api.proto index ed056dc209..ea98875faf 100644 --- a/samples/java-valueentity-counter/src/main/proto/com/example/counter_api.proto +++ b/samples/java-valueentity-counter/src/main/proto/com/example/counter_api.proto @@ -32,9 +32,12 @@ message CurrentCounter { // <6> } service CounterService { // <7> - option (akkaserverless.service) = { // <8> - type : SERVICE_TYPE_ENTITY - component : "com.example.domain.Counter" + option (akkaserverless.codegen) = { // <8> + value_entity: { // <9> + name: "com.example.domain.Counter" // <10> + entity_type: "counter" // <11> + state: "com.example.domain.CounterState" // <12> + } }; rpc Increase (IncreaseValue) returns (google.protobuf.Empty); diff --git a/samples/java-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto b/samples/java-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto index 9e470e15a5..4e024c39e6 100644 --- a/samples/java-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto +++ b/samples/java-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto @@ -2,16 +2,8 @@ syntax = "proto3"; package com.example.domain; // <1> -import "akkaserverless/annotations.proto"; // <2> +option java_outer_classname = "CounterDomain"; // <2> -option java_outer_classname = "CounterDomain"; // <3> - -option (akkaserverless.file).value_entity = { // <4> - name: "Counter" // <5> - entity_type: "counter" // <6> - state: "CounterState" // <7> -}; - -message CounterState { // <8> +message CounterState { // <3> int32 value = 1; } diff --git a/samples/java-valueentity-customer-registry/src/main/proto/customer/action/customer_action.proto b/samples/java-valueentity-customer-registry/src/main/proto/customer/action/customer_action.proto index f5084841e8..b1d9a128c2 100644 --- a/samples/java-valueentity-customer-registry/src/main/proto/customer/action/customer_action.proto +++ b/samples/java-valueentity-customer-registry/src/main/proto/customer/action/customer_action.proto @@ -24,8 +24,8 @@ import "customer/api/customer_api.proto"; service CustomerAction { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; rpc Create(api.Customer) returns (google.protobuf.Empty) { } diff --git a/samples/java-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto b/samples/java-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto index ce5c0e5bc4..179864cccb 100644 --- a/samples/java-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto +++ b/samples/java-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. + +// tag::declarations[] syntax = "proto3"; package customer.api; @@ -20,6 +22,7 @@ option java_outer_classname = "CustomerApi"; import "google/protobuf/empty.proto"; import "akkaserverless/annotations.proto"; +// end::declarations[] message Customer { string customer_id = 1 [(akkaserverless.field).entity_key = true]; @@ -47,17 +50,19 @@ message ChangeAddressRequest { Address new_address = 2; } +// tag::value-entity[] service CustomerService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "customer.domain.CustomerValueEntity" + option (akkaserverless.codegen) = { + value_entity: { + name: "customer.domain.CustomerValueEntity" + entity_type: "customers" + state: "customer.domain.CustomerState" + } }; rpc Create(Customer) returns (google.protobuf.Empty) {} - rpc ChangeName(ChangeNameRequest) returns (google.protobuf.Empty) {} - rpc ChangeAddress(ChangeAddressRequest) returns (google.protobuf.Empty) {} - rpc GetCustomer(GetCustomerRequest) returns (Customer) {} } +// end::value-entity[] diff --git a/samples/java-valueentity-customer-registry/src/main/proto/customer/domain/customer_domain.proto b/samples/java-valueentity-customer-registry/src/main/proto/customer/domain/customer_domain.proto index 2982f2c02c..618886d045 100644 --- a/samples/java-valueentity-customer-registry/src/main/proto/customer/domain/customer_domain.proto +++ b/samples/java-valueentity-customer-registry/src/main/proto/customer/domain/customer_domain.proto @@ -14,22 +14,11 @@ // tag::declarations[] syntax = "proto3"; - package customer.domain; - option java_outer_classname = "CustomerDomain"; - //end::declarations[] // tag::domain[] -import "akkaserverless/annotations.proto"; - -option (akkaserverless.file).value_entity = { // <1> - name: "CustomerValueEntity" - entity_type: "customers" - state: "CustomerState" -}; - message CustomerState { string customer_id = 1; string email = 2; diff --git a/samples/java-valueentity-customer-registry/src/main/proto/customer/view/customer_view.proto b/samples/java-valueentity-customer-registry/src/main/proto/customer/view/customer_view.proto index f9b1427de7..39b31ba5a9 100644 --- a/samples/java-valueentity-customer-registry/src/main/proto/customer/view/customer_view.proto +++ b/samples/java-valueentity-customer-registry/src/main/proto/customer/view/customer_view.proto @@ -27,21 +27,21 @@ import "google/protobuf/any.proto"; // tag::service[] service CustomerByName { - option (akkaserverless.service) = { - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} // <1> }; - rpc UpdateCustomer(domain.CustomerState) returns (domain.CustomerState) { // <1> - option (akkaserverless.method).eventing.in = { // <2> + rpc UpdateCustomer(domain.CustomerState) returns (domain.CustomerState) { // <2> + option (akkaserverless.method).eventing.in = { // <3> value_entity: "customers" }; - option (akkaserverless.method).view.update = { // <3> + option (akkaserverless.method).view.update = { // <4> table: "customers" }; } - rpc GetCustomers(ByNameRequest) returns (stream domain.CustomerState) { // <4> - option (akkaserverless.method).view.query = { // <5> + rpc GetCustomers(ByNameRequest) returns (stream domain.CustomerState) { // <5> + option (akkaserverless.method).view.query = { // <6> query: "SELECT * FROM customers WHERE name = :customer_name" }; } @@ -53,8 +53,8 @@ message ByNameRequest { // end::service[] service CustomerByEmail { - option (akkaserverless.service) = { - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} }; rpc UpdateCustomer(domain.CustomerState) returns (domain.CustomerState) { @@ -86,8 +86,8 @@ message CustomerSummary { } service CustomerSummaryByName { - option (akkaserverless.service) = { - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} }; rpc GetCustomers(ByNameRequest) returns (stream CustomerSummary) { @@ -113,8 +113,8 @@ message CustomersResponse { } service CustomersResponseByName { - option (akkaserverless.service) = { - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} }; rpc GetCustomers(ByNameRequest) returns (CustomersResponse) { // <2> diff --git a/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto b/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto index 87b505b071..6cc1237654 100644 --- a/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto +++ b/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto @@ -15,28 +15,12 @@ // These are the messages that get persisted - the current state (Cart). // tag::domain[] -// tag::proto_syntax[] -syntax = "proto3"; -// end::proto_syntax[] -package com.example.shoppingcart.domain; +syntax = "proto3"; // <1> +package com.example.shoppingcart.domain; // <2> option java_outer_classname = "ShoppingCartDomain"; -// tag::proto_imports[] -import "akkaserverless/annotations.proto"; -// end::proto_imports[] - -// tag::proto_state[] -// Describes how this domain relates to a value entity -option (akkaserverless.file).value_entity = { - name: "ShoppingCart" - entity_type: "shopping-cart" - state: "Cart" -}; -// end::proto_state[] - -// tag::proto_messages[] message LineItem { string product_id = 1; string name = 2; @@ -44,9 +28,8 @@ message LineItem { } // The shopping cart state. -message Cart { +message Cart { // <3> repeated LineItem items = 1; int64 creation_timestamp = 2; } -// end::proto_messages[] // end::domain[] diff --git a/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto b/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto index 46f3209b16..fb00454c1c 100644 --- a/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto +++ b/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto @@ -70,43 +70,59 @@ message Cart { // tag::proto_service[] service ShoppingCartService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.shoppingcart.domain.ShoppingCart" + // Describes how this domain relates to a value entity + option (akkaserverless.codegen) = { + value_entity: { // <1> + name: "com.example.shoppingcart.domain.ShoppingCart" // <2> + entity_type: "shopping-cart" // <3> + state: "com.example.shoppingcart.domain.Cart" // <4> + } }; + // tag::http-transcoding[] rpc Create (CreateCart) returns (google.protobuf.Empty) { + // end::proto_service[] option (google.api.http) = { // <1> post: "/cart/{cart_id}/create" }; + // tag::proto_service[] } rpc AddItem (AddLineItem) returns (google.protobuf.Empty) { + // end::proto_service[] option (google.api.http) = { // <1> - post: "/cart/{cart_id}/items/add" - body: "*" - }; + post: "/cart/{cart_id}/items/add" + body: "*" + }; + // tag::proto_service[] } rpc RemoveItem (RemoveLineItem) returns (google.protobuf.Empty) { + // end::proto_service[] option (google.api.http) = { // <2> - post: "/cart/{cart_id}/items/{product_id}/remove" - }; + post: "/cart/{cart_id}/items/{product_id}/remove" + }; + // tag::proto_service[] } rpc GetCart (GetShoppingCart) returns (Cart) { + // end::proto_service[] option (google.api.http) = { // <3> - get: "/carts/{cart_id}" - additional_bindings: { - get: "/carts/{cart_id}/items" - response_body: "items" - } - }; + get: "/carts/{cart_id}" + additional_bindings: { + get: "/carts/{cart_id}/items" + response_body: "items" + } + }; + // tag::proto_service[] } rpc RemoveCart (RemoveShoppingCart) returns (google.protobuf.Empty) { + // end::proto_service[] option (google.api.http).post = "/carts/{cart_id}/remove"; + // tag::proto_service[] } + // end::http-transcoding[] } // end::proto_service[] // end::api[] diff --git a/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_controller_api.proto b/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_controller_api.proto index 644e4711f7..3b27d291b9 100644 --- a/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_controller_api.proto +++ b/samples/java-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_controller_api.proto @@ -30,8 +30,8 @@ message NewCartCreated { } service ShoppingCartAction { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; rpc InitializeCart(NewCart) returns (NewCartCreated); diff --git a/samples/scala-doc-snippets/src/main/proto/com/example/delegating_service.proto b/samples/scala-doc-snippets/src/main/proto/com/example/delegating_service.proto index ef77409d38..ae2096c57b 100644 --- a/samples/scala-doc-snippets/src/main/proto/com/example/delegating_service.proto +++ b/samples/scala-doc-snippets/src/main/proto/com/example/delegating_service.proto @@ -13,8 +13,8 @@ message Result { } service DelegatingService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; rpc AddAndReturn(Request) returns (Result); diff --git a/samples/scala-doc-snippets/src/main/proto/com/example/json/json_api.proto b/samples/scala-doc-snippets/src/main/proto/com/example/json/json_api.proto index 348d21e02c..c934ab49dc 100644 --- a/samples/scala-doc-snippets/src/main/proto/com/example/json/json_api.proto +++ b/samples/scala-doc-snippets/src/main/proto/com/example/json/json_api.proto @@ -12,8 +12,8 @@ message KeyValue { } service MyService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; rpc Consume(google.protobuf.Any) returns (google.protobuf.Empty) { // <1> diff --git a/samples/scala-doc-snippets/src/main/proto/com/example/topics_action.proto b/samples/scala-doc-snippets/src/main/proto/com/example/topics_action.proto index c4c5b49b23..42023a3dac 100644 --- a/samples/scala-doc-snippets/src/main/proto/com/example/topics_action.proto +++ b/samples/scala-doc-snippets/src/main/proto/com/example/topics_action.proto @@ -19,8 +19,8 @@ message TopicOperation { // tag::text[] service MyTopicsAction { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; // end::bytes[] diff --git a/samples/scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto b/samples/scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto index e27d0e62bb..988324f705 100644 --- a/samples/scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto +++ b/samples/scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic.proto @@ -32,8 +32,8 @@ message Decreased { } service CounterJournalToTopic { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <2> + option (akkaserverless.codegen) = { + action: {} // <2> }; rpc Increase (com.example.domain.ValueIncreased) returns (Increased) { // <3> diff --git a/samples/scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto b/samples/scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto index f1baffdb33..b03a3263bc 100644 --- a/samples/scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto +++ b/samples/scala-eventsourced-counter/src/main/proto/com/example/actions/counter_topic_sub.proto @@ -21,8 +21,8 @@ import "com/example/actions/counter_topic.proto"; // <1> import "google/protobuf/empty.proto"; service CounterTopicSubscription { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <2> + option (akkaserverless.codegen) = { + action: {} // <2> }; rpc Increase (com.example.actions.Increased) returns (google.protobuf.Empty) { diff --git a/samples/scala-eventsourced-counter/src/main/proto/com/example/counter_api.proto b/samples/scala-eventsourced-counter/src/main/proto/com/example/counter_api.proto index 0322d96e37..d20d10279d 100644 --- a/samples/scala-eventsourced-counter/src/main/proto/com/example/counter_api.proto +++ b/samples/scala-eventsourced-counter/src/main/proto/com/example/counter_api.proto @@ -30,11 +30,19 @@ message CurrentCounter { } service CounterService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ENTITY - component : "com.example.domain.Counter" + option (akkaserverless.codegen) = { + event_sourced_entity: { + name: "com.example.domain.Counter" + entity_type: "counter" + state: "com.example.domain.CounterState" + events: [ + "com.example.domain.ValueIncreased", + "com.example.domain.ValueDecreased", + "com.example.domain.ValueReset"] + } }; + rpc Increase(IncreaseValue) returns (google.protobuf.Empty); rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); rpc Reset(ResetValue) returns (google.protobuf.Empty); diff --git a/samples/scala-eventsourced-counter/src/main/proto/com/example/domain/counter_domain.proto b/samples/scala-eventsourced-counter/src/main/proto/com/example/domain/counter_domain.proto index d5df314e84..c8adef2407 100644 --- a/samples/scala-eventsourced-counter/src/main/proto/com/example/domain/counter_domain.proto +++ b/samples/scala-eventsourced-counter/src/main/proto/com/example/domain/counter_domain.proto @@ -2,15 +2,6 @@ syntax = "proto3"; package com.example.domain; -import "akkaserverless/annotations.proto"; - -option (akkaserverless.file).event_sourced_entity = { - name: "Counter" - entity_type: "counter" - state: "CounterState" - events: ["ValueIncreased","ValueDecreased","ValueReset"] -}; - message CounterState { int32 value = 1; } diff --git a/samples/scala-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto b/samples/scala-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto index 1e0f11c6e8..5f4e473eba 100644 --- a/samples/scala-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto +++ b/samples/scala-eventsourced-customer-registry/src/main/proto/customer/api/customer_api.proto @@ -16,14 +16,9 @@ syntax = "proto3"; package customer.api; -// tag::declarations[] - import "google/protobuf/empty.proto"; import "akkaserverless/annotations.proto"; -// end::declarations[] - -// tag::view[] message Customer { string customer_id = 1 [(akkaserverless.field).entity_key = true]; string email = 2; @@ -35,8 +30,6 @@ message Address { string street = 1; string city = 2; } -// end::view[] - message GetCustomerRequest { string customer_id = 1 [(akkaserverless.field).entity_key = true]; } @@ -50,18 +43,23 @@ message ChangeAddressRequest { string customer_id = 1 [(akkaserverless.field).entity_key = true]; Address new_address = 2; } - +// tag::eventsourced-entity[] service CustomerService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "customer.domain.CustomerEntity" + option (akkaserverless.codegen) = { + event_sourced_entity: { + name: "customer.domain.CustomerEntity" + entity_type: "customers" + state: "customer.domain.CustomerState" + events: [ + "customer.domain.CustomerCreated", + "customer.domain.CustomerNameChanged", + "customer.domain.CustomerAddressChanged"] + } }; rpc Create(Customer) returns (google.protobuf.Empty) {} - rpc ChangeName(ChangeNameRequest) returns (google.protobuf.Empty) {} - rpc ChangeAddress(ChangeAddressRequest) returns (google.protobuf.Empty) {} - rpc GetCustomer(GetCustomerRequest) returns (Customer) {} } +// end::eventsourced-entity[] diff --git a/samples/scala-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto b/samples/scala-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto index 31d3d8f206..62b60e3f2b 100644 --- a/samples/scala-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto +++ b/samples/scala-eventsourced-customer-registry/src/main/proto/customer/domain/customer_domain.proto @@ -14,21 +14,10 @@ // tag::declarations[] syntax = "proto3"; - package customer.domain; - //end::declarations[] -// tag::domain[] -import "akkaserverless/annotations.proto"; - -option (akkaserverless.file).event_sourced_entity = { // <1> - name: "CustomerEntity" - entity_type: "customers" - state: "CustomerState" - events: ["CustomerCreated", "CustomerNameChanged", "CustomerAddressChanged"] -}; - +// tag::state[] message CustomerState { string customer_id = 1; string email = 2; @@ -40,7 +29,7 @@ message Address { string street = 1; string city = 2; } -// end::domain[] +// end::state[] // tag::events[] message CustomerCreated { diff --git a/samples/scala-eventsourced-customer-registry/src/main/proto/customer/view/customer_view.proto b/samples/scala-eventsourced-customer-registry/src/main/proto/customer/view/customer_view.proto index 59407a47d0..34fd8ed7d4 100644 --- a/samples/scala-eventsourced-customer-registry/src/main/proto/customer/view/customer_view.proto +++ b/samples/scala-eventsourced-customer-registry/src/main/proto/customer/view/customer_view.proto @@ -30,8 +30,8 @@ message ByNameRequest { } service CustomerByName { - option (akkaserverless.service) = { // <1> - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { // <1> + view: {} }; rpc ProcessCustomerCreated(domain.CustomerCreated) returns (api.Customer) { // <2> diff --git a/samples/scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto b/samples/scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto index 65bf9981a4..0ef168c070 100644 --- a/samples/scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto +++ b/samples/scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto @@ -6,18 +6,6 @@ syntax = "proto3"; package com.example.shoppingcart.domain; // <1> -import "akkaserverless/annotations.proto"; // <2> - -// tag::event_sourced_entity[] -// Describes how this domain relates to an event sourced entity -option (akkaserverless.file).event_sourced_entity = { // <3> - name: "ShoppingCart" // <4> - entity_type: "shopping-cart" // <5> - state: "Cart" // <6> - events: ["ItemAdded", "ItemRemoved"] // <7> -}; -// end::event_sourced_entity[] - message LineItem { string productId = 1; string name = 2; diff --git a/samples/scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto b/samples/scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto index 4d34ffcbee..bb460c0be9 100644 --- a/samples/scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto +++ b/samples/scala-eventsourced-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto @@ -35,9 +35,15 @@ message Cart { // <5> } service ShoppingCartService { // <6> - option (akkaserverless.service) = { // <7> - type: SERVICE_TYPE_ENTITY - component: "com.example.shoppingcart.domain.ShoppingCart" + option (akkaserverless.codegen) = { // <7> + event_sourced_entity: { // <8> + name: "com.example.shoppingcart.domain.ShoppingCart" // <9> + entity_type: "shopping-cart" // <10> + state: "com.example.shoppingcart.domain.Cart" // <11> + events: [ + "com.example.shoppingcart.domain.ItemAdded", // <12> + "com.example.shoppingcart.domain.ItemRemoved"] + } }; rpc AddItem (AddLineItem) returns (google.protobuf.Empty) { diff --git a/samples/scala-fibonacci-action/src/main/proto/com/example/fibonacci/fibonacci.proto b/samples/scala-fibonacci-action/src/main/proto/com/example/fibonacci/fibonacci.proto index ff68d6e841..9cc8a48681 100644 --- a/samples/scala-fibonacci-action/src/main/proto/com/example/fibonacci/fibonacci.proto +++ b/samples/scala-fibonacci-action/src/main/proto/com/example/fibonacci/fibonacci.proto @@ -23,8 +23,8 @@ message Number { } service Fibonacci { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <3> + option (akkaserverless.codegen) = { + action: {} // <3> }; rpc NextNumber(Number) returns (Number) {} diff --git a/samples/scala-first-service/src/main/proto/com/example/counter_api.proto b/samples/scala-first-service/src/main/proto/com/example/counter_api.proto index 8c04b1bf6c..bd7e5afff4 100644 --- a/samples/scala-first-service/src/main/proto/com/example/counter_api.proto +++ b/samples/scala-first-service/src/main/proto/com/example/counter_api.proto @@ -8,35 +8,38 @@ import "google/api/annotations.proto"; package com.example; message IncreaseValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; - int32 value = 2; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; + int32 value = 2; } message DecreaseValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; - int32 value = 2; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; + int32 value = 2; } message ResetValue { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; } message GetCounter { - string counter_id = 1 [(akkaserverless.field).entity_key = true]; + string counter_id = 1 [(akkaserverless.field).entity_key = true]; } message CurrentCounter { - int32 value = 1; + int32 value = 1; } service CounterService { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ENTITY - component : ".domain.Counter" - }; - - rpc Increase(IncreaseValue) returns (google.protobuf.Empty); - rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); - rpc Reset(ResetValue) returns (google.protobuf.Empty); - rpc GetCurrentCounter(GetCounter) returns (CurrentCounter); + option (akkaserverless.codegen) = { + value_entity: { + name: ".domain.Counter" + entity_type: "counter" + state: ".domain.CounterState" + } + }; + + rpc Increase(IncreaseValue) returns (google.protobuf.Empty); + rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); + rpc Reset(ResetValue) returns (google.protobuf.Empty); + rpc GetCurrentCounter(GetCounter) returns (CurrentCounter); } diff --git a/samples/scala-first-service/src/main/proto/com/example/counter_domain.proto b/samples/scala-first-service/src/main/proto/com/example/counter_domain.proto index a243a77f08..aeaf977abc 100644 --- a/samples/scala-first-service/src/main/proto/com/example/counter_domain.proto +++ b/samples/scala-first-service/src/main/proto/com/example/counter_domain.proto @@ -2,14 +2,6 @@ syntax = "proto3"; package com.example.domain; -import "akkaserverless/annotations.proto"; - -option (akkaserverless.file).value_entity = { - name: "Counter" - entity_type: "counter" - state: "CounterState" -}; - message CounterState { - int32 value = 1; + int32 value = 1; } diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto index a0b74e1c21..688e4705df 100644 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto +++ b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/counter/counter_api.proto @@ -37,13 +37,18 @@ message CurrentValue { int64 value = 1; } +// tag::replicated_entity[] service CounterService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.counter.domain.SomeCounter" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.counter.domain.SomeCounter" // <1> + entity_type: "some-counter" + replicated_counter: {} // <2> + } }; rpc Increase(IncreaseValue) returns (google.protobuf.Empty); rpc Decrease(DecreaseValue) returns (google.protobuf.Empty); rpc Get(GetValue) returns (CurrentValue); } +// end::replicated_entity[] diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto index eba997e2c2..99c7422fe6 100644 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto +++ b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/counter_map_api.proto @@ -53,10 +53,17 @@ message CurrentValues { map values = 1; } + +// tag::replicated_entity[] service CounterMapService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.countermap.domain.SomeCounterMap" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.countermap.domain.SomeCounterMap" // <1> + entity_type: "some-counter-map" + replicated_counter_map: { // <2> + key: "string" // <3> + } + } }; rpc Increase(IncreaseValue) returns (google.protobuf.Empty); @@ -65,3 +72,4 @@ service CounterMapService { rpc Get(GetValue) returns (CurrentValue); rpc GetAll(GetAllValues) returns (CurrentValues); } +// end::replicated_entity[] \ No newline at end of file diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto deleted file mode 100644 index d8e063ecb7..0000000000 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/countermap/domain/counter_map_domain.proto +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2021 Lightbend Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package com.example.replicated.countermap.domain; - -import "akkaserverless/annotations.proto"; - -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeCounterMap" - entity_type: "some-counter-map" - replicated_counter_map: { // <1> - key: "string" // <2> - } -}; -// end::replicated_entity[] diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto index d47fc8210a..4a7af59ac5 100644 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto +++ b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/domain/map_domain.proto @@ -16,18 +16,6 @@ syntax = "proto3"; package com.example.replicated.map.domain; -import "akkaserverless/annotations.proto"; - -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeMap" - entity_type: "some-map" - replicated_map: { // <1> - key: "SomeKey" // <2> - } -}; - message SomeKey { string some_field = 1; -} -// end::replicated_entity[] +} \ No newline at end of file diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto index 6332404de7..b278a97950 100644 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto +++ b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/map/map_api.proto @@ -54,10 +54,16 @@ message CurrentValues { repeated string baz = 3; } +// tag::replicated_entity[] service MapService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.map.domain.SomeMap" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.map.domain.SomeMap" // <1> + entity_type: "some-map" + replicated_map: { // <2> + key: "com.example.replicated.map.domain.SomeKey" // <3> + } + } }; rpc IncreaseFoo(IncreaseFooValue) returns (google.protobuf.Empty); @@ -67,3 +73,4 @@ service MapService { rpc RemoveBaz(RemoveBazValue) returns (google.protobuf.Empty); rpc Get(GetValues) returns (CurrentValues); } +// end::replicated_entity[] diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto deleted file mode 100644 index d39d80e007..0000000000 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/domain/multi_map_domain.proto +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2021 Lightbend Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package com.example.replicated.multimap.domain; - -import "akkaserverless/annotations.proto"; - -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeMultiMap" - entity_type: "some-multi-map" - replicated_multi_map: { // <1> - key: "string" // <2> - value: "double" // <3> - } -}; -// end::replicated_entity[] diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto index 53c3ba688c..17ab00fa6d 100644 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto +++ b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/multimap/multi_map_api.proto @@ -60,10 +60,18 @@ message AllCurrentValues { repeated CurrentValues values = 1; } + +// tag::replicated_entity[] service MultiMapService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.multimap.domain.SomeMultiMap" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.multimap.domain.SomeMultiMap" // <1> + entity_type: "some-multi-map" + replicated_multi_map: { // <2> + key: "string" // <3> + value: "double" // <4> + } + } }; rpc Put(PutValue) returns (google.protobuf.Empty); @@ -73,3 +81,4 @@ service MultiMapService { rpc Get(GetValues) returns (CurrentValues); rpc GetAll(GetAllValues) returns (AllCurrentValues); } +// end::replicated_entity[] diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto index 21dbed526c..79c35fdba6 100644 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto +++ b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/domain/register_domain.proto @@ -16,17 +16,7 @@ syntax = "proto3"; package com.example.replicated.register.domain; -import "akkaserverless/annotations.proto"; - // tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeRegister" - entity_type: "some-register" - replicated_register: { // <1> - value: "SomeValue" // <2> - } -}; - message SomeValue { string some_field = 1; } diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto index 00edc9a2ee..f9b68a5fd7 100644 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto +++ b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/register/register_api.proto @@ -32,12 +32,19 @@ message CurrentValue { string value = 1; } +// tag::replicated_entity[] service RegisterService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.register.domain.SomeRegister" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.register.domain.SomeRegister" // <1> + entity_type: "some-register" + replicated_register: { // <2> + value: "com.example.replicated.register.domain.SomeValue" // <3> + } + } }; rpc Set(SetValue) returns (google.protobuf.Empty); rpc Get(GetValue) returns (CurrentValue); } +// end::replicated_entity[] \ No newline at end of file diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto index 94e1276b1a..0cfbd38d5f 100644 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto +++ b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/registermap/register_map_api.proto @@ -56,10 +56,17 @@ message CurrentValues { repeated CurrentValue values = 1; } +// tag::replicated_entity[] service RegisterMapService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.registermap.domain.SomeRegisterMap" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.registermap.domain.SomeRegisterMap" // <1> + entity_type: "some-register-map" + replicated_register_map: { // <2> + key: "com.example.replicated.registermap.domain.SomeKey" // <3> + value: "com.example.replicated.registermap.domain.SomeValue" // <4> + } + } }; rpc Set(SetValue) returns (google.protobuf.Empty); @@ -67,3 +74,4 @@ service RegisterMapService { rpc Get(GetValue) returns (CurrentValue); rpc GetAll(GetAllValues) returns (CurrentValues); } +// end::replicated_entity[] diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto deleted file mode 100644 index 4b430f2287..0000000000 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/domain/set_domain.proto +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2021 Lightbend Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package com.example.replicated.set.domain; - -import "akkaserverless/annotations.proto"; - -// tag::replicated_entity[] -option (akkaserverless.file).replicated_entity = { - name: "SomeSet" - entity_type: "some-set" - replicated_set: { // <1> - element: "string" // <2> - } -}; -// end::replicated_entity[] diff --git a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto index 5d3974463d..9d4d30fcde 100644 --- a/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto +++ b/samples/scala-replicatedentity-examples/src/main/proto/com/example/replicated/set/set_api.proto @@ -38,13 +38,20 @@ message CurrentElements { repeated string elements = 1; } +// tag::replicated_entity[] service SetService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.replicated.set.domain.SomeSet" + option (akkaserverless.codegen) = { + replicated_entity: { + name: "com.example.replicated.set.domain.SomeSet" // <1> + entity_type: "some-set" + replicated_set: { // <2> + element: "string" // <3> + } + } }; rpc Add(AddElement) returns (google.protobuf.Empty); rpc Remove(RemoveElement) returns (google.protobuf.Empty); rpc Get(GetElements) returns (CurrentElements); } +// end::replicated_entity[] \ No newline at end of file diff --git a/samples/scala-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto b/samples/scala-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto index a7581b197f..2c106faa59 100644 --- a/samples/scala-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto +++ b/samples/scala-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto @@ -4,17 +4,6 @@ syntax = "proto3"; package com.example.shoppingcart.domain; // <1> -import "akkaserverless/annotations.proto"; // <2> - -// Describes how this domain relates to a replicated entity -option (akkaserverless.file).replicated_entity = { // <3> - name: "ShoppingCart" // <4> - entity_type: "shopping-cart" // <5> - replicated_counter_map: { // <6> - key: "Product" // <7> - } -}; - message Product { string id = 1; string name = 2; diff --git a/samples/scala-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto b/samples/scala-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto index d92294070b..3ac90fcd3a 100644 --- a/samples/scala-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto +++ b/samples/scala-replicatedentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto @@ -40,9 +40,14 @@ message Cart { // <5> } service ShoppingCartService { // <6> - option (akkaserverless.service) = { // <7> - type: SERVICE_TYPE_ENTITY - component: "com.example.shoppingcart.domain.ShoppingCart" + option (akkaserverless.codegen) = { // <7> + replicated_entity: { // <8> + name: "com.example.shoppingcart.domain.ShoppingCart" // <9> + entity_type: "shopping-cart" // <10> + replicated_counter_map: { // <11> + key: "com.example.shoppingcart.domain.Product" // <12> + } + } }; rpc AddItem (AddLineItem) returns (google.protobuf.Empty) { diff --git a/samples/scala-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto b/samples/scala-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto index ee94dc6287..5e0594f4e9 100644 --- a/samples/scala-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto +++ b/samples/scala-valueentity-counter/src/main/proto/com/example/actions/counter_states_sub.proto @@ -21,8 +21,8 @@ import "com/example/domain/counter_domain.proto"; // <1> import "google/protobuf/empty.proto"; service CounterStateSubscription { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <2> + option (akkaserverless.codegen) = { + action: {} // <2> }; rpc OnUpdateState (com.example.domain.CounterState) returns (google.protobuf.Empty) { diff --git a/samples/scala-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto b/samples/scala-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto index 7cc137b48b..9cc4a539f8 100644 --- a/samples/scala-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto +++ b/samples/scala-valueentity-counter/src/main/proto/com/example/actions/double-counter.proto @@ -22,8 +22,8 @@ import "com/example/counter_api.proto"; // <1> import "google/protobuf/empty.proto"; service DoubleCounter { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION // <2> + option (akkaserverless.codegen) = { + action: {} // <2> }; rpc Increase (com.example.IncreaseValue) returns (google.protobuf.Empty); // <3> diff --git a/samples/scala-valueentity-counter/src/main/proto/com/example/counter_api.proto b/samples/scala-valueentity-counter/src/main/proto/com/example/counter_api.proto index 546f1abf46..aacc9c268a 100644 --- a/samples/scala-valueentity-counter/src/main/proto/com/example/counter_api.proto +++ b/samples/scala-valueentity-counter/src/main/proto/com/example/counter_api.proto @@ -30,9 +30,12 @@ message CurrentCounter { // <5> } service CounterService { // <6> - option (akkaserverless.service) = { // <7> - type : SERVICE_TYPE_ENTITY - component : "com.example.domain.Counter" + option (akkaserverless.codegen) = { // <7> + value_entity: { // <8> + name: "com.example.domain.Counter" // <9> + entity_type: "counter" // <10> + state: "com.example.domain.CounterState" // <11> + } }; rpc Increase (IncreaseValue) returns (google.protobuf.Empty); diff --git a/samples/scala-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto b/samples/scala-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto index c0c717da90..1ea27ae81b 100644 --- a/samples/scala-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto +++ b/samples/scala-valueentity-counter/src/main/proto/com/example/domain/counter_domain.proto @@ -2,14 +2,6 @@ syntax = "proto3"; package com.example.domain; // <1> -import "akkaserverless/annotations.proto"; // <2> - -option (akkaserverless.file).value_entity = { // <3> - name: "Counter" // <4> - entity_type: "counter" // <5> - state: "CounterState" // <6> -}; - -message CounterState { // <7> +message CounterState { // <2> int32 value = 1; } diff --git a/samples/scala-valueentity-customer-registry/src/main/proto/customer/action/customer_action.proto b/samples/scala-valueentity-customer-registry/src/main/proto/customer/action/customer_action.proto index ab6ae4c88d..6e3e2c493e 100644 --- a/samples/scala-valueentity-customer-registry/src/main/proto/customer/action/customer_action.proto +++ b/samples/scala-valueentity-customer-registry/src/main/proto/customer/action/customer_action.proto @@ -22,8 +22,8 @@ import "customer/api/customer_api.proto"; service CustomerAction { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; rpc Create(api.Customer) returns (google.protobuf.Empty) { } diff --git a/samples/scala-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto b/samples/scala-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto index 4f8f7177db..7f7e41193b 100644 --- a/samples/scala-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto +++ b/samples/scala-valueentity-customer-registry/src/main/proto/customer/api/customer_api.proto @@ -45,17 +45,19 @@ message ChangeAddressRequest { Address new_address = 2; } +// tag::value-entity[] service CustomerService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "customer.domain.CustomerValueEntity" + option (akkaserverless.codegen) = { + value_entity: { + name: "customer.domain.CustomerValueEntity" + entity_type: "customers" + state: "customer.domain.CustomerState" + } }; rpc Create(Customer) returns (google.protobuf.Empty) {} - rpc ChangeName(ChangeNameRequest) returns (google.protobuf.Empty) {} - rpc ChangeAddress(ChangeAddressRequest) returns (google.protobuf.Empty) {} - rpc GetCustomer(GetCustomerRequest) returns (Customer) {} } +// end::value-entity[] diff --git a/samples/scala-valueentity-customer-registry/src/main/proto/customer/domain/customer_domain.proto b/samples/scala-valueentity-customer-registry/src/main/proto/customer/domain/customer_domain.proto index c6dad6bc33..39714c209b 100644 --- a/samples/scala-valueentity-customer-registry/src/main/proto/customer/domain/customer_domain.proto +++ b/samples/scala-valueentity-customer-registry/src/main/proto/customer/domain/customer_domain.proto @@ -14,20 +14,10 @@ // tag::declarations[] syntax = "proto3"; - package customer.domain; - //end::declarations[] // tag::domain[] -import "akkaserverless/annotations.proto"; - -option (akkaserverless.file).value_entity = { // <1> - name: "CustomerValueEntity" - entity_type: "customers" - state: "CustomerState" -}; - message CustomerState { string customer_id = 1; string email = 2; diff --git a/samples/scala-valueentity-customer-registry/src/main/proto/customer/view/customer_view.proto b/samples/scala-valueentity-customer-registry/src/main/proto/customer/view/customer_view.proto index 9b75e41171..a458f8d378 100644 --- a/samples/scala-valueentity-customer-registry/src/main/proto/customer/view/customer_view.proto +++ b/samples/scala-valueentity-customer-registry/src/main/proto/customer/view/customer_view.proto @@ -25,21 +25,21 @@ import "google/protobuf/any.proto"; // tag::service[] service CustomerByName { - option (akkaserverless.service) = { - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} // <1> }; - rpc UpdateCustomer(domain.CustomerState) returns (domain.CustomerState) { // <1> - option (akkaserverless.method).eventing.in = { // <2> + rpc UpdateCustomer(domain.CustomerState) returns (domain.CustomerState) { // <2> + option (akkaserverless.method).eventing.in = { // <3> value_entity: "customers" }; - option (akkaserverless.method).view.update = { // <3> + option (akkaserverless.method).view.update = { // <4> table: "customers" }; } - rpc GetCustomers(ByNameRequest) returns (stream domain.CustomerState) { // <4> - option (akkaserverless.method).view.query = { // <5> + rpc GetCustomers(ByNameRequest) returns (stream domain.CustomerState) { // <5> + option (akkaserverless.method).view.query = { // <6> query: "SELECT * FROM customers WHERE name = :customer_name" }; } @@ -51,8 +51,8 @@ message ByNameRequest { // end::service[] service CustomerByEmail { - option (akkaserverless.service) = { - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} }; rpc UpdateCustomer(domain.CustomerState) returns (domain.CustomerState) { @@ -84,8 +84,8 @@ message CustomerSummary { } service CustomerSummaryByName { - option (akkaserverless.service) = { - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} }; rpc GetCustomers(ByNameRequest) returns (stream CustomerSummary) { @@ -111,8 +111,8 @@ message CustomersResponse { } service CustomersResponseByName { - option (akkaserverless.service) = { - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} }; rpc GetCustomers(ByNameRequest) returns (CustomersResponse) { // <2> diff --git a/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto b/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto index 8db4435152..a5fd2af3c5 100644 --- a/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto +++ b/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/domain/shoppingcart_domain.proto @@ -21,19 +21,6 @@ syntax = "proto3"; package com.example.shoppingcart.domain; -// tag::proto_imports[] -import "akkaserverless/annotations.proto"; -// end::proto_imports[] - -// tag::proto_state[] -// Describes how this domain relates to a value entity -option (akkaserverless.file).value_entity = { - name: "ShoppingCart" - entity_type: "shopping-cart" - state: "Cart" -}; -// end::proto_state[] - // tag::proto_messages[] message LineItem { string product_id = 1; diff --git a/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto b/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto index 48da21b60d..1c97f96c43 100644 --- a/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto +++ b/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_api.proto @@ -70,9 +70,12 @@ message Cart { // tag::proto_service[] service ShoppingCartService { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ENTITY - component: "com.example.shoppingcart.domain.ShoppingCart" + option (akkaserverless.codegen) = { + value_entity: { + name: "com.example.shoppingcart.domain.ShoppingCart" + entity_type: "shopping-cart" + state: "com.example.shoppingcart.domain.Cart" + } }; rpc Create (CreateCart) returns (google.protobuf.Empty) { diff --git a/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_controller_api.proto b/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_controller_api.proto index f57f97b3b1..e261313595 100644 --- a/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_controller_api.proto +++ b/samples/scala-valueentity-shopping-cart/src/main/proto/com/example/shoppingcart/shoppingcart_controller_api.proto @@ -29,8 +29,8 @@ message NewCartCreated { } service ShoppingCartAction { - option (akkaserverless.service) = { - type : SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; rpc InitializeCart(NewCart) returns (NewCartCreated); diff --git a/sbt-plugin/src/sbt-test/sbt-akkaserverless/compile-only/src/main/protobuf/com/example/eventing/raw_eventing_types.proto b/sbt-plugin/src/sbt-test/sbt-akkaserverless/compile-only/src/main/protobuf/com/example/eventing/raw_eventing_types.proto index 334047d4f6..0c45299d13 100644 --- a/sbt-plugin/src/sbt-test/sbt-akkaserverless/compile-only/src/main/protobuf/com/example/eventing/raw_eventing_types.proto +++ b/sbt-plugin/src/sbt-test/sbt-akkaserverless/compile-only/src/main/protobuf/com/example/eventing/raw_eventing_types.proto @@ -24,8 +24,8 @@ import "google/protobuf/empty.proto"; import "google/protobuf/wrappers.proto"; service RawEventingTypesAction { - option (akkaserverless.service) = { - type: SERVICE_TYPE_ACTION + option (akkaserverless.codegen) = { + action: {} }; rpc ConsumeStringTopic(google.protobuf.StringValue) returns (google.protobuf.Empty) { diff --git a/sbt-plugin/src/sbt-test/sbt-akkaserverless/compile-only/src/main/protobuf/com/example/view/user_view.proto b/sbt-plugin/src/sbt-test/sbt-akkaserverless/compile-only/src/main/protobuf/com/example/view/user_view.proto index 37af047ea2..6534dc2ca9 100644 --- a/sbt-plugin/src/sbt-test/sbt-akkaserverless/compile-only/src/main/protobuf/com/example/view/user_view.proto +++ b/sbt-plugin/src/sbt-test/sbt-akkaserverless/compile-only/src/main/protobuf/com/example/view/user_view.proto @@ -60,8 +60,8 @@ message UserProjection { // test coverage for a view with no transformations service AdditionalView { - option (akkaserverless.service) = { - type: SERVICE_TYPE_VIEW + option (akkaserverless.codegen) = { + view: {} }; rpc UpdateCustomer(valueentity.domain.UserState) returns (valueentity.domain.UserState) {