2017-03-14 14 views
1

交易喜欢的是通过REST春触发/通知明确一个排定方法

@Component 
@Path("txns") 
public class Transaction { 

@Path("/purchases") 
public Response postPurchaseTrnsaction(Transaction txn) { 
    // persistence takes place here 
} 

@Path("/sales") 
public Response postSalesTrnsaction(Transaction txn) { 
    // persistence takes place here 
}  
} 

有一个独立的后台库存的过程,更新的SKU被出售或从上述trnsactions购买的清单创建销售和采购。

public class InventoryProcessor { 

    @Scheduled(fixedRate = 900000,initialDelay = 3000) // 15 mins 
    @Transactional 
    public void doInventory() { 
    // open Transactions, update inventory records 
    } 

} 

此过程每15分钟运行一次。但是,每当新的交易到达时,都需要明确地触发或通知InventoryProcessordoInventory方法立即执行库存。

春天有没有选择。

回答

0

您可以将InventoryProcessor注入到事务中并以编程方式调用该方法吗?或者,如果需要异步完成,则将该调用包装在另一个标记为@Async的方法中。

@Component 
@Path("txns") 
public class Transaction { 

@Inject 
private InventoryProcessor inventoryProcessor 

@Path("/purchases") 
public Response postPurchaseTrnsaction(Transaction txn) { 
    // persistence takes place here 

    inventoryProcessor.doInventory(); 
} 

@Path("/sales") 
public Response postSalesTrnsaction(Transaction txn) { 
    // persistence takes place here 
}  
} 
+0

你能否解释有点 – vels4j

+0

编辑,包括代码 – Gee2113

+0

不能,请求的执行发布自定义事件不能等到库存处理器完成。库存处理器是一个耗时的过程 – vels4j