I am using MicroServiceSubscription Event in Java microservice,
I am getting the tenant using env.getCredentials.getTenant() but I want to check if the tenant has subscribe to the microservice and add it to a list.if yes then if statement should be executed.
So you’re having a MULIT_TENANT Microservice here?
If you want to detect the moment at when the Microservice has started and initialized all its subscriptions, you can use
@EventListener
public void onSubscriptionsInitialized(MicroserviceSubscriptionsInitializedEvent event) {
log.info("Subscriptions have been initialized on application startup");
...
}
you get this information already and you are already in the context of that tenant to retrieve devices etc. You can also add it to a list if desired. No additional checks needed.
Your current code is wrong because the boostrap tenant is not the currentTenant!
This is the Boostrap Tenant and has nothing to do with the tenants the microservice is subscribed to. The bootstrap credentials should also be not used to do service call but are always existing to retrieve the service user for each tenant the microservice is subscribed to.