I've been thinking about if it would be possible to use Google
protocol buffers (http://code.google.com/p/protobuf/) or more
specifically protostuff (http://code.google.com/p/protostuff/) to
define, code generate and serialize / deserialize commands and events
in Axon Framework.
Scroll down for my Axon Related questions...
Here is a quick description of protobuf (read more at
http://code.google.com/apis/protocolbuffers/docs/overview.html).
Messages are defined in .proto files like this (simple) example:
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
}
The protobuf compiler then takes the message definition and generates
code in your language of choice. The official protobuf compiler from
Google supports C++, Java and Python. But there is a plugin structure
to add support for anything you want.
The generated code will give you message classes (Java POJOS in our
case) that contain the needed code to serialize and deserialize
themselves to and from the binary protobuf format. The messages are
forwards and backwards compatible through the field numbers. Let's
say we wanted to add the new field "nick" to the Person message:
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
optional string nick = 4
}
And then we don't want to handle email anymore:
message Person {
required string name = 1;
required int32 id = 2;
optional string nick = 4
}
By never reassigning field numbers the generated code can handle both
old and new messages (think no need for versioning of Events).
As I said, the default protobuf serialization format is binary (this
is what Google uses internally), but with the protostuff project comes
code generation for: json (with GWT overlay types), xml and yaml (only
serialization, but perfect for making messages human readable).
So with a single message definition you could have a C++ client that
sends binary commands over a socket to your Java CQRS server that then
gives JSON events to a JavaScript client in a browser.
END OF INTRO TO PROTOBUF
So, what would it take to use it with Axon?
Commands
For the commands there's no problem, since Axon doesn't require
anything special from a command.
Events
Here I can see even more value since they need to be both serialized
to the storage and sent across the network. But this is also the part
that needs a bit of love to make it work since Axon has requirements
on the Events. A plain vanilla protobuf POJO doesn't extend anything
but by creating our own template (they use StringTemplate for the code
generation) we could make the generated classes extend DomainEvent as
required.
So now I would like to know what extra fields need to be serialized
with the event to make it work in Axon? Things like identifier,
timestamp etc.
This might be a bit tricky to get working and I don't want to force
protobuf onto anyone who doesn't need it, so my thinking is to try to
get this working with zero change to the Axon Framework code.
So... anyone else interested?