Search in sources :

Example 21 with NotificationEvent

use of org.killbill.notificationq.api.NotificationEvent in project killbill by killbill.

the class DefaultSubscriptionBaseService 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) {
                if (!(inputKey instanceof SubscriptionNotificationKey)) {
                    log.error("SubscriptionBase service received an unexpected event className='{}'", inputKey.getClass().getName());
                    return;
                }
                final SubscriptionNotificationKey key = (SubscriptionNotificationKey) inputKey;
                final SubscriptionBaseEvent event = dao.getEventById(key.getEventId(), internalCallContextFactory.createInternalTenantContext(tenantRecordId, accountRecordId));
                if (event == null) {
                    // This can be expected if the event is soft deleted (is_active = 0)
                    log.debug("Failed to extract event for notification key {}", inputKey);
                    return;
                }
                final InternalCallContext context = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "SubscriptionEventQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken);
                processEventReady(event, key.getSeqId(), context);
            }
        };
        subscriptionEventQueue = notificationQueueService.createNotificationQueue(SUBSCRIPTION_SERVICE_NAME, NOTIFICATION_QUEUE_NAME, queueHandler);
    } catch (final NotificationQueueAlreadyExists e) {
        throw new RuntimeException(e);
    }
}
Also used : 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) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) DateTime(org.joda.time.DateTime) LifecycleHandlerType(org.killbill.billing.platform.api.LifecycleHandlerType)

Aggregations

NotificationEvent (org.killbill.notificationq.api.NotificationEvent)21 DateTime (org.joda.time.DateTime)16 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)9 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)7 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)6 WithEntitlementPlugin (org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin)6 EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)6 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)6 NotificationQueueHandler (org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler)6 EntitlementLoggingHelper.logCancelEntitlement (org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logCancelEntitlement)5 EntitlementLoggingHelper.logUncancelEntitlement (org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logUncancelEntitlement)5 NotificationEventWithMetadata (org.killbill.notificationq.api.NotificationEventWithMetadata)5 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)3 NotificationQueue (org.killbill.notificationq.api.NotificationQueue)3 BlockingState (org.killbill.billing.entitlement.api.BlockingState)2 BlockingTransitionNotificationKey (org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey)2 EntitlementNotificationKey (org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey)2 LifecycleHandlerType (org.killbill.billing.platform.api.LifecycleHandlerType)2