Search in sources :

Example 1 with NotificationQueueHandler

use of org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler in project killbill by killbill.

the class BaseRetryService method initialize.

@Override
public void initialize() throws NotificationQueueAlreadyExists {
    retryQueue = notificationQueueService.createNotificationQueue(DefaultPaymentService.SERVICE_NAME, getQueueName(), new NotificationQueueHandler() {

        @Override
        public void handleReadyNotification(final NotificationEvent notificationKey, final DateTime eventDateTime, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) {
            if (!(notificationKey instanceof PaymentRetryNotificationKey)) {
                log.error("Payment service got an unexpected notification type {}", notificationKey.getClass().getName());
                return;
            }
            final PaymentRetryNotificationKey key = (PaymentRetryNotificationKey) notificationKey;
            final InternalCallContext callContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, paymentRetryService, CallOrigin.INTERNAL, UserType.SYSTEM, userToken);
            retryPaymentTransaction(key.getAttemptId(), key.getPaymentControlPluginNames(), callContext);
        }
    });
}
Also used : NotificationEvent(org.killbill.notificationq.api.NotificationEvent) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) NotificationQueueHandler(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler) DateTime(org.joda.time.DateTime)

Example 2 with NotificationQueueHandler

use of org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler in project killbill by killbill.

the class DefaultOverdueNotifierBase method initialize.

@Override
public void initialize() {
    final OverdueNotifier myself = this;
    final NotificationQueueHandler notificationQueueHandler = new NotificationQueueHandler() {

        @Override
        public void handleReadyNotification(final NotificationEvent notificationKey, final DateTime eventDate, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) {
            myself.handleReadyNotification(notificationKey, eventDate, userToken, accountRecordId, tenantRecordId);
        }
    };
    try {
        overdueQueue = notificationQueueService.createNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME, getQueueName(), notificationQueueHandler);
    } catch (NotificationQueueAlreadyExists e) {
        throw new RuntimeException(e);
    }
}
Also used : NotificationEvent(org.killbill.notificationq.api.NotificationEvent) UUID(java.util.UUID) NotificationQueueAlreadyExists(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists) NotificationQueueHandler(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler) DateTime(org.joda.time.DateTime)

Example 3 with NotificationQueueHandler

use of org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler in project killbill by killbill.

the class DefaultEntitlementService method initialize.

@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE)
public void initialize() {
    try {
        final NotificationQueueHandler queueHandler = new NotificationQueueHandler() {

            @Override
            public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) {
                final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "EntitlementQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken);
                if (inputKey instanceof EntitlementNotificationKey) {
                    final CallContext callContext = internalCallContextFactory.createCallContext(internalCallContext);
                    processEntitlementNotification((EntitlementNotificationKey) inputKey, internalCallContext, callContext);
                } else if (inputKey instanceof BlockingTransitionNotificationKey) {
                    processBlockingNotification((BlockingTransitionNotificationKey) inputKey, internalCallContext);
                } else if (inputKey != null) {
                    log.error("Entitlement service received an unexpected event className='{}", inputKey.getClass());
                } else {
                    log.error("Entitlement service received an unexpected null event");
                }
            }
        };
        entitlementEventQueue = notificationQueueService.createNotificationQueue(ENTITLEMENT_SERVICE_NAME, NOTIFICATION_QUEUE_NAME, queueHandler);
    } catch (final NotificationQueueAlreadyExists e) {
        throw new RuntimeException(e);
    }
}
Also used : EntitlementNotificationKey(org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey) BlockingTransitionNotificationKey(org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey) NotificationEvent(org.killbill.notificationq.api.NotificationEvent) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) NotificationQueueAlreadyExists(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists) NotificationQueueHandler(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) DateTime(org.joda.time.DateTime) LifecycleHandlerType(org.killbill.billing.platform.api.LifecycleHandlerType)

Example 4 with NotificationQueueHandler

use of org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler in project killbill by killbill.

the class DefaultNextBillingDateNotifier method initialize.

@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;
            // Just to ensure compatibility with json that might not have that targetDate field (old versions < 0.13.6)
            final DateTime targetDate = key.getTargetDate() != null ? key.getTargetDate() : eventDate;
            try {
                final SubscriptionBase subscription = subscriptionApi.getSubscriptionFromId(key.getUuidKey(), callContextFactory.createInternalTenantContext(tenantRecordId, accountRecordId));
                if (subscription == null) {
                    log.warn("Unable to retrieve subscriptionId='{}' for event {}", key.getUuidKey(), key);
                    return;
                }
                if (// Just to ensure compatibility with json that might not have that field (old versions < 0.13.6)
                key.isDryRunForInvoiceNotification() != null && key.isDryRunForInvoiceNotification()) {
                    processEventForInvoiceNotification(key.getUuidKey(), targetDate, userToken, accountRecordId, tenantRecordId);
                } else {
                    processEventForInvoiceGeneration(key.getUuidKey(), targetDate, userToken, accountRecordId, tenantRecordId);
                }
            } catch (SubscriptionBaseApiException e) {
                log.warn("Error retrieving subscriptionId='{}'", key.getUuidKey(), e);
            }
        }
    };
    nextBillingQueue = notificationQueueService.createNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME, NEXT_BILLING_DATE_NOTIFIER_QUEUE, notificationQueueHandler);
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) NotificationEvent(org.killbill.notificationq.api.NotificationEvent) UUID(java.util.UUID) NotificationQueueHandler(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler) DateTime(org.joda.time.DateTime) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)

Example 5 with NotificationQueueHandler

use of org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler in project killbill by killbill.

the class ParentInvoiceCommitmentNotifier method initialize.

@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) {
            try {
                if (!(notificationKey instanceof ParentInvoiceCommitmentNotificationKey)) {
                    log.error("Invoice service received an unexpected event type {}", notificationKey.getClass().getName());
                    return;
                }
                final ParentInvoiceCommitmentNotificationKey key = (ParentInvoiceCommitmentNotificationKey) notificationKey;
                listener.handleParentInvoiceCommitmentEvent(key.getUuidKey(), userToken, accountRecordId, tenantRecordId);
            } catch (IllegalArgumentException e) {
                log.error("The key returned from the ParentInvoiceCommitmentQueue is not a valid UUID", e);
            }
        }
    };
    commitInvoiceQueue = notificationQueueService.createNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME, PARENT_INVOICE_COMMITMENT_NOTIFIER_QUEUE, notificationQueueHandler);
}
Also used : NotificationEvent(org.killbill.notificationq.api.NotificationEvent) UUID(java.util.UUID) NotificationQueueHandler(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler) DateTime(org.joda.time.DateTime)

Aggregations

UUID (java.util.UUID)6 DateTime (org.joda.time.DateTime)6 NotificationEvent (org.killbill.notificationq.api.NotificationEvent)6 NotificationQueueHandler (org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler)6 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)3 NotificationQueueAlreadyExists (org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists)3 LifecycleHandlerType (org.killbill.billing.platform.api.LifecycleHandlerType)2 BlockingTransitionNotificationKey (org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey)1 EntitlementNotificationKey (org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey)1 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)1 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)1 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1