What Code Is Being Generated During the Project Build Process.

There are following code parts that are created during this process:

1. Java classes for:

  • Commands
  • Events
  • Aggregate IDs and other types the developer defines in .proto files
  • Aggregate States
  • Stream Projection States

These files are created under generated/main/java project sub-folder.

They are generated by protobuf compiler.

2. gRPC service implementations and stubs

Generated under generated/grpc path by gRPC plug-in to Protobuf compiler.

3. Mapping from Proto types to Java classes

It is the file named proto_to_java_class.properties. It is generated under generated/main/resource path by our plug-in to Protobuf compiler.

The purpose of this file is to provide mapping from Proto type to corresponding Java class. It's not currently possible to know Java class from Proto type. This isn't available in current version of Protobuf. So, we're building this map ourselves so that we can reconstruct Java class from google.protobuf.Any instance.

This feature is going to be removed once there's a similar feature provided by Protobuf.

4. Command Validators

This is not yet implemented, but we're going to do that. A command validator is a class that validates commands for an aggregate class. The validation rules are based on Protobuf field annotations.

5. Business Failures

A business failure (unlike a technical error) is a condition under which a request cannot be complete (but there are ways for solving this situation). Example would be: CreditCardValidationDeclined, InsufficientAmount, TaskInProgressCannotBeRemoved.

There are two parts of code per business failure that are generated.

Part 1: a Java class for corresponding Protobuf message. This class is a sub-class of a Failures class in the failures sub-package of the corresponding aggregate. For example, if my aggregate is in the order sub-package, the full class name of OrderIncomplete failure would be:

com.mycompany.myproject.order.failures.Failures.OrderIncomplete.

Unlike commands and events, failures are all gathered in the same enclosing class called Failures. This is done so because there's another piece of code related to a business failure.

Part 2: a Java class derived from FailureThrowable. Each such class is top level class generated under failures sub-package of the corresponding aggregate. Instances of the class would contain corresponding failure message.

So, for Failures.OrderIncomplete message there the following failure class would be generated:

com.mycompany.myproject.order.failures.OrderIncomplete

We generate these Throwable classes because Java does not support generic types for throwables. More on this read in Failures.

FailureThrowables are generated by Spine plug-in to Protobuf compiler in the generated/spine project sub-folder.

results matching ""

    No results matching ""