Search in sources :

Example 6 with EventBusException

use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.

the class DefaultBroadcastApi method broadcast.

@Override
public void broadcast(final String serviceName, final String type, final String event, final DateTime createdDate, final String createdBy, final boolean localNodeOnly) {
    // If localNodeOnly, this is not really a broadcast api anymore, but we still rely on that broadcast bus event to notify the local node
    if (localNodeOnly) {
        final BroadcastInternalEvent busEvent = new DefaultBroadcastInternalEvent(serviceName, type, event);
        try {
            eventBus.post(busEvent);
        } catch (final EventBusException e) {
            logger.warn("Failed to post event {}", event, e);
        }
    } else {
        final BroadcastModelDao modelDao = new BroadcastModelDao(serviceName, type, event, createdDate, createdBy);
        dao.create(modelDao);
    }
}
Also used : BroadcastModelDao(org.killbill.billing.util.broadcast.dao.BroadcastModelDao) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) BroadcastInternalEvent(org.killbill.billing.events.BroadcastInternalEvent)

Example 7 with EventBusException

use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.

the class DefaultAccountDao method postBusEventFromTransaction.

@Override
protected void postBusEventFromTransaction(final AccountModelDao account, final AccountModelDao savedAccount, final ChangeType changeType, final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final InternalCallContext context) throws BillingExceptionBase {
    // This is only called for the create call (see update below)
    switch(changeType) {
        case INSERT:
            break;
        default:
            return;
    }
    final Long recordId = entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getRecordId(savedAccount.getId().toString(), context);
    // We need to re-hydrate the callcontext with the account record id
    final InternalCallContext rehydratedContext = internalCallContextFactory.createInternalCallContext(recordId, context);
    final AccountCreationInternalEvent creationEvent = new DefaultAccountCreationEvent(new DefaultAccountData(savedAccount), savedAccount.getId(), rehydratedContext.getAccountRecordId(), rehydratedContext.getTenantRecordId(), rehydratedContext.getUserToken());
    try {
        eventBus.postFromTransaction(creationEvent, entitySqlDaoWrapperFactory.getHandle().getConnection());
    } catch (final EventBusException e) {
        log.warn("Failed to post account creation event for accountId='{}'", savedAccount.getId(), e);
    }
}
Also used : DefaultAccountCreationEvent(org.killbill.billing.account.api.user.DefaultAccountCreationEvent) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) DefaultAccountData(org.killbill.billing.account.api.user.DefaultAccountCreationEvent.DefaultAccountData) AccountCreationInternalEvent(org.killbill.billing.events.AccountCreationInternalEvent)

Example 8 with EventBusException

use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.

the class MockAccountDao method create.

@Override
public void create(final AccountModelDao account, final InternalCallContext context) throws AccountApiException {
    super.create(account, context);
    try {
        final Long accountRecordId = getRecordId(account.getId(), context);
        final long tenantRecordId = context == null ? InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID : context.getTenantRecordId();
        eventBus.post(new DefaultAccountCreationEvent(new DefaultAccountData(account), account.getId(), accountRecordId, tenantRecordId, UUID.randomUUID()));
    } catch (final EventBusException ex) {
        Assert.fail(ex.toString());
    }
}
Also used : DefaultAccountCreationEvent(org.killbill.billing.account.api.user.DefaultAccountCreationEvent) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) DefaultAccountData(org.killbill.billing.account.api.user.DefaultAccountCreationEvent.DefaultAccountData)

Example 9 with EventBusException

use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.

the class DefaultSubscriptionDao method notifyBusOfEffectiveImmediateChange.

private void notifyBusOfEffectiveImmediateChange(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent immediateEvent, final int seqId, final InternalCallContext context) {
    try {
        final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(immediateEvent, seqId);
        if (transition != null) {
            final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
            eventBus.postFromTransaction(busEvent, entitySqlDaoWrapperFactory.getHandle().getConnection());
        }
    } catch (final EventBusException e) {
        log.warn("Failed to post effective event for subscriptionId='{}'", subscription.getId(), e);
    }
}
Also used : SubscriptionBaseTransitionData(org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData) DefaultEffectiveSubscriptionEvent(org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) BusEvent(org.killbill.bus.api.BusEvent)

Aggregations

EventBusException (org.killbill.bus.api.PersistentBus.EventBusException)9 DefaultEffectiveSubscriptionEvent (org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent)3 SubscriptionBaseTransitionData (org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData)3 BusEvent (org.killbill.bus.api.BusEvent)3 DefaultAccountCreationEvent (org.killbill.billing.account.api.user.DefaultAccountCreationEvent)2 DefaultAccountData (org.killbill.billing.account.api.user.DefaultAccountCreationEvent.DefaultAccountData)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 BigDecimal (java.math.BigDecimal)1 DefaultAccountChangeEvent (org.killbill.billing.account.api.user.DefaultAccountChangeEvent)1 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)1 AccountChangeInternalEvent (org.killbill.billing.events.AccountChangeInternalEvent)1 AccountCreationInternalEvent (org.killbill.billing.events.AccountCreationInternalEvent)1 BroadcastInternalEvent (org.killbill.billing.events.BroadcastInternalEvent)1 BusInternalEvent (org.killbill.billing.events.BusInternalEvent)1 DefaultInvoiceCreationEvent (org.killbill.billing.invoice.api.user.DefaultInvoiceCreationEvent)1 DefaultPaymentErrorEvent (org.killbill.billing.payment.api.DefaultPaymentErrorEvent)1 TransactionStatus (org.killbill.billing.payment.api.TransactionStatus)1 PaymentTransactionInfoPlugin (org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)1 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)1 BroadcastModelDao (org.killbill.billing.util.broadcast.dao.BroadcastModelDao)1