Search in sources :

Example 1 with DBEventManagerException

use of org.apache.airavata.db.event.manager.messaging.DBEventManagerException in project airavata by apache.

the class DBEventMessageHandler method onMessage.

@Override
public void onMessage(MessageContext messageContext) {
    log.info("Incoming DB event message. Message Id : " + messageContext.getMessageId());
    try {
        byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent());
        DBEventMessage dbEventMessage = new DBEventMessage();
        ThriftUtils.createThriftFromBytes(bytes, dbEventMessage);
        DBEventMessageContext dBEventMessageContext = dbEventMessage.getMessageContext();
        switch(dbEventMessage.getDbEventType()) {
            case SUBSCRIBER:
                log.info("Registering " + dBEventMessageContext.getSubscriber().getSubscriberService() + " subscriber for " + dbEventMessage.getPublisherService());
                DbEventManagerZkUtils.createDBEventMgrZkNode(curatorClient, dbEventMessage.getPublisherService(), dBEventMessageContext.getSubscriber().getSubscriberService());
                break;
            case PUBLISHER:
                List<String> subscribers = DbEventManagerZkUtils.getSubscribersForPublisher(curatorClient, dbEventMessage.getPublisherService());
                if (subscribers.isEmpty()) {
                    log.error("No Subscribers registered for the service");
                    throw new DBEventManagerException("No Subscribers registered for the service");
                }
                String routingKey = getRoutingKeyFromList(subscribers);
                log.info("Publishing " + dbEventMessage.getPublisherService() + " db event to " + subscribers.toString());
                MessageContext messageCtx = new MessageContext(dbEventMessage, MessageType.DB_EVENT, "", "");
                messageCtx.setUpdatedTime(AiravataUtils.getCurrentTimestamp());
                DBEventManagerMessagingFactory.getDBEventPublisher().publish(messageCtx, routingKey);
                break;
        }
        log.info("Sending ack. Message Delivery Tag : " + messageContext.getDeliveryTag());
        DBEventManagerMessagingFactory.getDBEventSubscriber().sendAck(messageContext.getDeliveryTag());
    } catch (Exception e) {
        log.error("Error processing message.", e);
    }
}
Also used : DBEventMessage(org.apache.airavata.model.dbevent.DBEventMessage) DBEventMessageContext(org.apache.airavata.model.dbevent.DBEventMessageContext) DBEventManagerException(org.apache.airavata.db.event.manager.messaging.DBEventManagerException) MessageContext(org.apache.airavata.messaging.core.MessageContext) DBEventMessageContext(org.apache.airavata.model.dbevent.DBEventMessageContext) DBEventManagerException(org.apache.airavata.db.event.manager.messaging.DBEventManagerException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Aggregations

ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 DBEventManagerException (org.apache.airavata.db.event.manager.messaging.DBEventManagerException)1 MessageContext (org.apache.airavata.messaging.core.MessageContext)1 DBEventMessage (org.apache.airavata.model.dbevent.DBEventMessage)1 DBEventMessageContext (org.apache.airavata.model.dbevent.DBEventMessageContext)1