EventX is a microservice which provides event sourcing services. EventX is written using Vertx and exposes services via the Vertx eventbus. Easy integration is provided via Service Discovery and Service Proxies.
-
Publishing Permissions - Each application publishing events to EventX must be registered in the EventX configuration. This allows EventX to restrict and isolate which events authorized application can publish. This improves data integrity in the multitenancy environment by preventing multiple services from having the same name and publishing the same events.
var sd = ServiceDiscovery.create(vertx)
sd.getRecord(rec -> rec.getName().equals("com.geoideas.eventx"), hndlr -> {
if(hndlr.succeeded()) {
EventService eventx = sd.getReference(hndlr.result()).get();
}
});
EventService eventx = EventService.create(vertx, "service:com.geoideas.eventx");
var event = new EventDTO()
.setContext("tester.test")
.setEvent("add_grade")
.setEventType("insert")
.setEntity("test_1")
.setEntityId("1234456789qwertyuiplkjhgfdsazxcv") // at least 32 characters
.setData(new JsonObject())
.setVersion(1)
.setRevision(1);
eventx.publish(event.toJson(), hndlr -> {
if(hndlr.succeeded())
System.out.println(hndlr.result().encode());
});
eventx.poll(0, hndlr -> {
if(hndlr.succeeded())
hndlr.result().stream()
.map(e -> (JsonObject))
.map(EventDTO::fromJson)
.forEach(System.out::println)
});
The EventDTO object can be found at https://github.com/owengrant/eventx-shared
- context - The name of the application as defined in the permissions (below) section of the EventX configuration.
- event - The name of the event.
- eventType - The type of action the event executed (INSERT, UPDATE, READ, DELETE, ETC.)
- entity - The group name of the entity to which the event belongs.
- entityId - The id of the specific instance of the entity to which the event belongs. Must be > 32 characters and globally unique.
- data - A json containing the event data.
- version - An integer indicating the structure version of the event data.
- revision - An integer which keeps track of how many events were published to the given entityId. This helps track the changes to an instance of an entity.
{
"database": {"host": "localhost","port": 5432,"database":"eventx","username": "postgres","password": "postgres"},
"serviceName": "com.geoideas.eventx",
"address": "service:com.geoideas.eventx",
"permissions": {
"com.geoideas.eventx.tester": {
"events": ["com.geoideas.eventx.tester:TEST"]
}
}
}
- database - Postgres database configurations
- serviceName - The name of the EventX service
- address - The location of the EventX service on the eventbus
{
"database": {"host": "localhost","port": 5432,"database":"eventx","username":"postgres","password": "postgres"},
"serviceName": "com.geoideas.eventx",
"address": "service:com.geoideas.eventx",
"permissions": {
"com.geoideas.eventx.tester": {
"events": ["com.geoideas.eventx.tester:TEST"]
}
}
}
-
Keys of the "permissions" object represent the names of applications allowed to publish events.
- the "events" arrays holds the names of events which can be published by the current application.