com.github.libgraviton.workerbase.QueueManager 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.
package com.github.libgraviton.workerbase;
import com.github.libgraviton.messaging.QueueConnection;
import com.github.libgraviton.messaging.exception.CannotConnectToQueue;
import com.github.libgraviton.messaging.exception.CannotRegisterConsumer;
import com.github.libgraviton.messaging.strategy.rabbitmq.RabbitMqConnection;
import java.util.Properties;
/**
* QueueManager
*
* @author List of contributors {@literal }
* @version $Id: $Id
* @see http://swisscom.ch
*/
public class QueueManager {
private QueueConnection connection;
public QueueManager(Properties properties) {
connection = new RabbitMqConnection.Builder()
.queueName(properties.getProperty("graviton.workerId"))
.routingKey(properties.getProperty("graviton.workerId"))
.applyProperties(properties, "queue.")
.build();
}
/**
* Async connection to queue.
*
* @param worker the worker
*
* @throws CannotConnectToQueue if connection to queue cannot be established
* @throws CannotRegisterConsumer if connection was successfully established, but consumer registration failed
*/
public void connect(WorkerAbstract worker) throws CannotConnectToQueue, CannotRegisterConsumer {
connection.consume(new WorkerConsumer(worker));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy