Skip to content

Instantly share code, notes, and snippets.

View Romeh's full-sized avatar

MRomeh Romeh

View GitHub Profile
/**
* get order state service API
*
* @param getOrderStatusCmd get Order state command
* @return order state
*/
public CompletableFuture<OrderState> getOrderStatus(OrderCmd.GetOrderStatusCmd getOrderStatusCmd) {
return PatternsCS.ask(getOrderEntity(), getOrderStatusCmd, timeout).toCompletableFuture()
.thenApply(handleGetState);
}
spring:
jackson:
default-property-inclusion: non_null
akka:
config: eventSourcing.conf
system-name: orderManagerSystem
/**
* the main order entity required configuration for event souring toolkit
*/
@Component
public class OrderEntityProperties implements PersistentEntityProperties<OrderManager, OrderCmd, OrderEvent> {
private Map<Class<? extends OrderEvent>, String> tags;
/**
* init the event tags map
*/
@PostConstruct
/**
* Tha main Event sourcing DDD aggregate class for order domain which handle the order commands within it is boundary context
*
* @author romeh
*/
@PersistentActor
public class OrderManager extends PersistentEntity<OrderCmd, OrderEvent, OrderState> {
/**
* how to handle supervisor strategy definition for the parent actor of the entity
<dependency>
<groupId>spring-akka-event-sourcing</groupId>
<artifactId>springboot-akka-event-sourcing-starter</artifactId>
<version>1.0</version>
</dependency>
@Override
// if you want to do atomic update over cache entry
public void updateAlertEntry(String serviceId, String serviceCode, AlertEntry alertEntry) {
//get the JSR cache reference
final Cache<String, List<AlertEntry>> alertsCache = getAlertsCache();
// then invoke atomic update on the cache entry
alertsCache.invoke(serviceId, (mutableEntry, objects) -> {
if (mutableEntry.exists() && mutableEntry.getValue() != null) {
logger.debug("updating alert entry into the cache store invoke: {},{}",serviceId,serviceCode);
final List<AlertEntry> alertEntries = mutableEntry.getValue();
@Autowired
private javax.cache.CacheManager cacheManager;
// get access to your cache for further operation
private Cache<String, List<AlertEntry>> getAlertsCache() {
return cacheManager.getCache(CacheNames.Alerts.name());
}
// close the cache manager upon shutting down
@PreDestroy
<config
xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
xmlns='http://www.ehcache.org/v3'>
<service>
<jsr107:defaults enable-management="true" enable-statistics="true"/>
</service>
<!-- file persistance enabling-->
<persistence directory="./cache"></persistence>
<!-- the 2 caches we will create-->
<cache alias="AlertsConfig" uses-template="config-cache"/>
@SpringBootApplication
// enable spring boot caching
@EnableCaching
public class AlertManagerApplication {
public static void main(String[] args) {
SpringApplication.run(AlertManagerApplication.class, args);
}
<!-- ehcache and JSR dependencies-->
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache}</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>