@Override
public void initialize() throws NotificationQueueAlreadyExists {
final NotificationQueueHandler notificationQueueHandler = new NotificationQueueHandler() {
@Override
public void handleReadyNotification(final NotificationEvent notificationKey, final DateTime eventDate, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) {
if (!(notificationKey instanceof NextBillingDateNotificationKey)) {
log.error("Invoice service received an unexpected event className='{}", notificationKey.getClass());
return;
}
final NextBillingDateNotificationKey key = (NextBillingDateNotificationKey) notificationKey;
final DateTime targetDate = key.getTargetDate() != null ? key.getTargetDate() : eventDate;
final UUID firstSubscriptionId = key.getUuidKeys().iterator().next();
if (key.isDryRunForInvoiceNotification() != null &&
key.isDryRunForInvoiceNotification()) {
processEventForInvoiceNotification(firstSubscriptionId, targetDate, userToken, accountRecordId, tenantRecordId);
} else {
final boolean isRescheduled = key.isRescheduled() == Boolean.TRUE;
processEventForInvoiceGeneration(firstSubscriptionId, targetDate, isRescheduled, userToken, accountRecordId, tenantRecordId);
}
}
};
final NotificationQueueHandler retryableHandler = new RetryableHandler(clock, this, notificationQueueHandler);
nextBillingQueue = notificationQueueService.createNotificationQueue(KILLBILL_SERVICES.INVOICE_SERVICE.getServiceName(),
NEXT_BILLING_DATE_NOTIFIER_QUEUE,
retryableHandler);
super.initialize(nextBillingQueue, notificationQueueHandler);
}