public interface EventSubscriber
Event for successful order: Say, we want to write a subscriber which will send mail when order is successful.
import java.util.Map;
import com.hcl.voltmx.middleware.api.events.EventData;
import com.hcl.voltmx.middleware.api.events.EventSubscriber;
import com.hcl.voltmx.middleware.api.events.IntegrationEventSubscriber;
@IntegrationEventSubscriber(topics = {"apps/order/success"})
public class OrderSuccessEvent implements EventSubscriber {
private static final String SUCCESS_MESSAGE = "Dear %s, Your order for %s is successful. "
+ "Your order id is%s. Order details:%s.";
@Override
public void onEvent(EventData eventData) {
Map<String, Object> additionalMetadata = eventData.getAdditionalMetadata();
Object userId = additionalMetadata.get("userId");
Object product = additionalMetadata.get("product");
Object orderId = additionalMetadata.get("orderId");
String message = String.format(SUCCESS_MESSAGE, userId, product, orderId, eventData.getData());
sendSuccessMail(String.valueOf(userId), message);
}
private static void sendSuccessMail(String userId, String message) {
}
}
Event for failed order: Say, we want to write a subscriber which will send mail when order is failed.
import java.util.Map;
import com.hcl.voltmx.middleware.api.events.EventData;
import com.hcl.voltmx.middleware.api.events.EventSubscriber;
import com.hcl.voltmx.middleware.api.events.IntegrationEventSubscriber;
@IntegrationEventSubscriber(topics = {"apps/order/fail"})
public class OrderFailedEvent implements EventSubscriber {
private static final String FAILURE_MESSAGE = "Dear %s, Your order for %s is failed. "
+ "Your tracking id is %s. Details: %s.";
@Override
public void onEvent(EventData eventData) {
Map<String, Object> additionalMetadata = eventData.getAdditionalMetadata();
Object userId = additionalMetadata.get("userId");
Object product = additionalMetadata.get("product");
Object trackingId = additionalMetadata.get("trackingId");
String message = String.format(FAILURE_MESSAGE, userId, product, trackingId,
eventData.getData());
sendFailureMail(String.valueOf(userId), message);
}
private static void sendFailureMail(String userId, String message) {
}
}
EventData
,
EventManager
,
EventNotifier
,
IntegrationEventSubscriber
,
IntegrationServiceEvent
Modifier and Type | Method and Description |
---|---|
void |
onEvent(EventData eventData)
Receives notification when any event of subscribed name or topic is
triggered.
|
void onEvent(EventData eventData)
eventData
- The event data.Copyright © 2019. All rights reserved.