package com.perspectium;
import com.perspectium.api.Message;
import com.perspectium.logging.PerspectiumLogger;
import com.perspectium.replicator.ASubscriber;
import com.perspectium.replicator.SubscribeException;
import com.perspectium.replicator.reporting.Reporting;
import com.perspectium.replicator.reporting.Reporting.ReportingException;
public class TestSubscriber extends ASubscriber {
final static PerspectiumLogger Log = PerspectiumLogger.create(TestSubscriber.class);
private final static String TASKNAME = "test_task";
private final static String QUEUE = "psp.test.errors";
final Reporting reporter = new Reporting(TASKNAME, QUEUE);
public void postProcessMessage() {
Log.info("POST Process TestSubscriber");
}
@Override
public boolean processMessage(Message message) throws SubscribeException {
if (message.getValue() == "") {
String errorMsg = "Message value empty!";
Log.error(errorMsg);
reportError(errorMsg, message);
return false;
}
processAck(message);
return true;
}
private void reportError(String errorMessage, Message message) {
try {
reporter.reportError(errorMessage, message);
} catch (ReportingException e) {
// Reporting exceptions are thrown when reporting fails
// You can log it, try again, etc.
Log.error(e.toString());
}
}
private void processAck(Message message) {
try {
Log,Log.info("Sending acknowledgment back to ServiceNow");
reporter.processAck(message);
} catch (ReportingException e) {
Log.error(e.toString());
}
}
}
|