.getTenantDomain() == null) {
String serverURL = serverConfiguration.getFirstProperty(
ServiceStatisticsPublisherConstants.BAM_SERVER_URL);
if (serverURL != null) {
EventBroker broker = eventBroker;
Subscription subscription = new Subscription();
subscription.setEventSinkURL(serverURL +
ServiceStatisticsPublisherConstants.
BAM_SERVICE_STAT_RECEIVER_SERVICE);
subscription.setTopicName(ServiceStatisticsPublisherConstants.BAM_REG_PATH);
subscription.setOwner(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
subscription.setEventDispatcherName(EventBrokerConstants.WS_EVENT_DISPATCHER_NAME);
try {
SuperTenantCarbonContext.startTenantFlow();
int tenantId = SuperTenantCarbonContext.getCurrentContext(StatisticsServiceComponent.getConfigurationContext()).getTenantId();
SuperTenantCarbonContext.getCurrentContext().setTenantId(tenantId);
SuperTenantCarbonContext.getCurrentContext().getTenantDomain(true);
SuperTenantCarbonContext.getCurrentContext().setUsername(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
SuperTenantCarbonContext.getCurrentContext().setUserRealm(realmService.getBootstrapRealm());
broker.subscribe(subscription);
} catch (EventBrokerException e) {
log.error("Can not publish the message ", e);
} finally {
SuperTenantCarbonContext.endTenantFlow();