새 파일 만들기
규칙은 이미 있는 파일을 고치는 것뿐 아니라 새 종류의 파일도 만들 수 있습니다. 예제: 도메인 이벤트를 메시지 브로커로 보낼 때 이벤트마다 토픽 이름이 필요합니다. 코드 곳곳에 문자열로 흩지 않고, DSL 에 한 번 적어 상수 클래스로 생성합니다.
model/entity.yml
PurchaseOrder:
meta: entity @root @expose(20) @event(Placed(total), Shipped, Cancelled) @topic(petstore.order) @owner(customerId)
생성되는 파일 - PetstoreEventTopics.java:
package io.elasticore.sample.petstore.domain.event;
import java.util.HashMap;
import java.util.Map;
/**
* PetstoreEventTopics - where each domain event of the domain is published.
*
* Generated from @topic by the pet store rules. Change the DSL, not this file.
*/
public final class PetstoreEventTopics {
public static final String PURCHASE_ORDER_PLACED = "petstore.order.placed";
public static final String PURCHASE_ORDER_SHIPPED = "petstore.order.shipped";
public static final String PURCHASE_ORDER_CANCELLED = "petstore.order.cancelled";
private static final Map<String, String> TOPICS = new HashMap<>();
static {
TOPICS.put("io.elasticore.sample.petstore.domain.event.PurchaseOrderPlacedEvent", PURCHASE_ORDER_PLACED);
TOPICS.put("io.elasticore.sample.petstore.domain.event.PurchaseOrderShippedEvent", PURCHASE_ORDER_SHIPPED);
TOPICS.put("io.elasticore.sample.petstore.domain.event.PurchaseOrderCancelledEvent", PURCHASE_ORDER_CANCELLED);
}
private PetstoreEventTopics() {
}
/** The topic of an event, by its class name as the outbox records it; null when it has none. */
public static String topicOf(String eventType) {
return TOPICS.get(eventType);
}
}