public interface EventNotifier
Custom code to trigger event for success or fail order: Say, we want to write a post processor which will trigger event when order is successful or failed.
import com.konylabs.middleware.api.events.EventData;
import com.konylabs.middleware.common.DataPostProcessor2;
import com.konylabs.middleware.controller.DataControllerRequest;
import com.konylabs.middleware.controller.DataControllerResponse;
import com.konylabs.middleware.dataobject.Result;
public class PostProcessorToTriggerEvents implements DataPostProcessor2 {
@Override
public Object execute(Result result, DataControllerRequest request,
DataControllerResponse response) throws Exception {
EventData eventData;
if (response.getStatusCode() == 200) {
eventData = new EventData("apps/order/success", response.getResponse());
eventData.addAdditionalMetadata("orderId", result.getParamValueByName("orderId"));
} else {
eventData = new EventData("apps/order/fail", response.getResponse());
eventData.addAdditionalMetadata("trackingId", result.getParamValueByName("trackingId"));
}
eventData.addAdditionalMetadata("userId", result.getParamValueByName("userId"));
eventData.addAdditionalMetadata("product", result.getParamValueByName("product"));
request.getServicesManager().getEventNotifier().notify(eventData);
return result;
}
}
EventData
,
EventManager
,
EventSubscriber
Modifier and Type | Method and Description |
---|---|
void |
notify(EventData eventData)
Notify all subscribers of the given event based on the event name or topic.
|
void |
notify(String eventNameOrTopic,
Object data)
Notify all subscribers of the given event based on the event name or topic.
|
void notify(EventData eventData)
eventData
- The event data.notify(String, Object)
void notify(String eventNameOrTopic, Object data)
eventNameOrTopic
- The name or topic of the event.data
- The data of the event.notify(EventData)
Copyright © 2019. All rights reserved.