我有一个实体说
@Entity
@Table(name = "purchase_order")
public class PurchaseOrder implements Serializable, IBroadcastEntity {
private Long id;
private String sequenceNumber;
}
我的自定义拦截器是
@Component
public class CustomInterceptor extends EmptyInterceptor {
@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, org.hibernate.type.Type[] types) {
if (entity instanceof IBroadcastEntity) {
broadcastService.broadCastOrder((IBroadcastEntity) entity);
}
}
@Override
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
if (entity instanceof IBroadcastEntity) {
broadcastService.broadCastOrder((IBroadcastEntity) entity);
}
return super.onFlushDirty(entity, id, currentState, previousState, propertyNames, types);
}
当我广播时,它一次又一次地被召回。
但是我希望此功能启用超时功能。
例如,如果消息在最近10秒钟内广播,则不要再次广播。 10秒后再次播放方法。
实现此目标的最佳做法是什么。