use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.
the class ProviderPubTest method testPubLookout.
@Test
public void testPubLookout() {
Registry registry = new DefaultRegistry();
if (Lookout.registry() == NoopRegistry.INSTANCE) {
Lookout.setRegistry(registry);
}
LookoutModule lookoutModule = new LookoutModule();
Assert.assertEquals(true, lookoutModule.needLoad());
lookoutModule.install();
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setInterfaceId("a");
EventBus.post(new ProviderPubEvent(providerConfig));
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
RpcLookoutId rpcLookoutId = new RpcLookoutId();
InfoWrapper result = Lookout.registry().get(rpcLookoutId.fetchProviderPubId());
final Object value = result.value();
Assert.assertTrue(value instanceof ProviderConfig);
providerConfig = (ProviderConfig) value;
Assert.assertEquals("a", providerConfig.getInterfaceId());
}
use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.
the class PolarisRegistry method register.
@Override
public void register(ProviderConfig config) {
String appName = config.getAppName();
if (!registryConfig.isRegister()) {
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
}
return;
}
if (!config.isRegister()) {
return;
}
try {
List<InstanceRegisterRequest> services = buildPolarisRegister(config);
if (CommonUtils.isNotEmpty(services)) {
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, config.getInterfaceId()));
}
for (InstanceRegisterRequest service : services) {
registerPolarisService(config, service);
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB, config.getInterfaceId()));
}
}
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, config.getInterfaceId()));
}
}
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REG_PROVIDER, "polarisRegistry", config.buildKey()), e);
}
if (EventBus.isEnable(ProviderPubEvent.class)) {
ProviderPubEvent event = new ProviderPubEvent(config);
EventBus.post(event);
}
}
use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.
the class LocalRegistry method register.
@Override
public void register(ProviderConfig config) {
String appName = config.getAppName();
if (!registryConfig.isRegister()) {
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
}
return;
}
if (!config.isRegister()) {
// 注册中心不注册或者服务不注册
return;
}
List<ServerConfig> serverConfigs = config.getServer();
if (CommonUtils.isNotEmpty(serverConfigs)) {
for (ServerConfig server : serverConfigs) {
String serviceName = LocalRegistryHelper.buildListDataId(config, server.getProtocol());
ProviderInfo providerInfo = LocalRegistryHelper.convertProviderToProviderInfo(config, server);
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, serviceName));
}
doRegister(appName, serviceName, providerInfo);
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, serviceName));
}
}
if (EventBus.isEnable(ProviderPubEvent.class)) {
ProviderPubEvent event = new ProviderPubEvent(config);
EventBus.post(event);
}
}
}
use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.
the class ConsulRegistry method register.
@Override
public void register(ProviderConfig config) {
String appName = config.getAppName();
if (!registryConfig.isRegister()) {
// 只订阅不注册
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
}
return;
}
if (!config.isRegister()) {
return;
}
// 注册服务端节点
try {
List<NewService> services = buildNewServices(config);
if (CommonUtils.isNotEmpty(services)) {
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, config.getInterfaceId()));
}
for (NewService service : services) {
registerConsulService(service);
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB, config.getInterfaceId()));
}
}
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, config.getInterfaceId()));
}
}
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REG_PROVIDER, "consulRegistry", config.buildKey()), e);
}
if (EventBus.isEnable(ProviderPubEvent.class)) {
ProviderPubEvent event = new ProviderPubEvent(config);
EventBus.post(event);
}
}
use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.
the class MulticastRegistry method register.
@Override
public void register(ProviderConfig config) {
String appName = config.getAppName();
if (!registryConfig.isRegister()) {
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
}
return;
}
if (config.isRegister()) {
List<ServerConfig> serverConfigs = config.getServer();
if (CommonUtils.isNotEmpty(serverConfigs)) {
for (ServerConfig server : serverConfigs) {
String serviceName = MulticastRegistryHelper.buildListDataId(config, server.getProtocol());
ProviderInfo providerInfo = MulticastRegistryHelper.convertProviderToProviderInfo(config, server);
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, serviceName));
}
doRegister(appName, serviceName, providerInfo);
if (LOGGER.isInfoEnabled(appName)) {
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, serviceName));
}
}
if (EventBus.isEnable(ProviderPubEvent.class)) {
ProviderPubEvent event = new ProviderPubEvent(config);
EventBus.post(event);
}
}
}
}
Aggregations