runForTenant() & MicroserviceSubscription AddedEvent do not work together

Product/components used and version/fix level:

Microservice SDK 1018.510.0

Detailed explanation of the problem:

We’re using the SDK and observed a strange behavior. We use EventListeners to react on MicroserviceSubscriptionAddedEvents:

    @EventListener
    public void onMicroserviceSubscriptionAddedEvent(final MicroserviceSubscriptionAddedEvent event) {
        logger.info("MicroserviceSubscriptionAddedEvent: {}", event);
    }

This worked very good until we added a @PostConstruct block which runs some logic on the bootstrap tenant:

    @PostConstruct
    void init() {
        String bootstrapTenant = platformProperties.getMicroserviceBoostrapUser().getTenant();
        logger.info("bootstrapTenant: {}", bootstrapTenant);
        subscription.runForTenant(bootstrapTenant, () -> {
            logger.info("running in bootstrapTenant: {}", bootstrapTenant);
        });
    }

Independently of what is executed within the runForTenant block (even if it is empty): as a result, the MicroserviceSubscriptionAddedEvent is not received anymore and therefore the onMicroserviceSubscriptionAddedEvent method is not invoked!
As a side note: the MicroserviceSubscriptionsInitializedEvent is still received.

Now we wonder why that runForTenant block with the bootstrapTenant is a problem? Can someone explain?

Thanks a lot,
Michael

I cannot explain it but I recognized the same behavior sometime ago. I think I raised a support incident but couldn’t find it anymore. The solution was that you can only use one of them at a time. As the onMicroserviceSubscriptionAddedEvent is called on every startup and when a new tenant is added it should be where you should place your logic und you don’t need the init() anymore.

Thanks @Stefan_Witschel for the feedback. While I still dont understand why we cannot use both approaches, we now use a different workaround: we listen to the MicroserviceSubscriptionsInitializedEvent and do the initialization in there by invoking the subscription.runForTenant().

1 Like