Skip to content

Instantly share code, notes, and snippets.

@hpgrahsl
Created July 19, 2019 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpgrahsl/97ac69bda40d6f4e3a83dc00db67dbf1 to your computer and use it in GitHub Desktop.
Save hpgrahsl/97ac69bda40d6f4e3a83dc00db67dbf1 to your computer and use it in GitHub Desktop.
OrderUpsertedEvent Class
public class OrderUpsertedEvent implements Outboxable {
private static ObjectMapper MAPPER = new ObjectMapper();
private final Long id;
private final JsonNode payload;
private final Long timestamp;
static {
MAPPER.registerModule(new JavaTimeModule());
}
private OrderUpsertedEvent(Long id, JsonNode payload) {
this.id = id;
this.payload = payload;
this.timestamp = Instant.now().getEpochSecond();
}
public static OrderUpsertedEvent of(PurchaseOrder order) {
return new OrderUpsertedEvent(order.getId(), MAPPER.valueToTree(order));
}
@Override
public String getAggregateId() {
return String.valueOf(id);
}
@Override
public String getAggregateType() {
return PurchaseOrder.class.getName();
}
@Override
public String getType() {
return this.getClass().getName();
}
@Override
public Long getTimestamp() {
return timestamp;
}
@Override
public String getPayload() {
try {
return MAPPER.writeValueAsString(payload);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment