com.github.libgraviton.workerbase.WorkerConsumer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of worker-base Show documentation
Show all versions of worker-base Show documentation
A base library to simplify the creation of Graviton queue workers.
/**
* queue consumer - here we have the main logic
*/
package com.github.libgraviton.workerbase;
import com.fasterxml.jackson.jr.ob.JSON;
import com.github.libgraviton.messaging.MessageAcknowledger;
import com.github.libgraviton.messaging.consumer.AcknowledgingConsumer;
import com.github.libgraviton.messaging.exception.CannotConsumeMessage;
import com.github.libgraviton.workerbase.model.QueueEvent;
import java.io.IOException;
/**
* WorkerConsumer class.
*
* @author List of contributors {@literal }
* @see http://swisscom.ch
* @version $Id: $Id
*/
public class WorkerConsumer implements AcknowledgingConsumer {
private WorkerAbstract worker;
private MessageAcknowledger acknowledger;
/**
* constructor
*
* @param worker worker
*/
public WorkerConsumer(WorkerAbstract worker) {
this.worker = worker;
}
@Override
public void consume(String messageId, String message) throws CannotConsumeMessage {
QueueEvent queueEvent;
try {
queueEvent = JSON.std.beanFrom(QueueEvent.class, message);
} catch (IOException e) {
throw new CannotConsumeMessage(messageId, message, e);
}
worker.handleDelivery(queueEvent, messageId, acknowledger);
}
@Override
public void setAcknowledger(MessageAcknowledger acknowledger) {
this.acknowledger = acknowledger;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy