Search in sources :

Example 6 with ConsumerSubEvent

use of com.alipay.sofa.rpc.event.ConsumerSubEvent in project sofa-rpc by sofastack.

the class PolarisRegistry method subscribe.

@Override
public List<ProviderGroup> subscribe(ConsumerConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isSubscribe()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return null;
    }
    if (!config.isSubscribe()) {
        return null;
    }
    try {
        List<ProviderInfo> providers = findService(config);
        if (EventBus.isEnable(ConsumerSubEvent.class)) {
            ConsumerSubEvent event = new ConsumerSubEvent(config);
            EventBus.post(event);
        }
        return Collections.singletonList(new ProviderGroup().addAll(providers));
    } catch (SofaRpcRuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_SUB_PROVIDER, EXT_NAME), e);
    }
}
Also used : ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) ConsumerSubEvent(com.alipay.sofa.rpc.event.ConsumerSubEvent) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)

Example 7 with ConsumerSubEvent

use of com.alipay.sofa.rpc.event.ConsumerSubEvent in project sofa-rpc by sofastack.

the class ConsulRegistry method subscribe.

@Override
public List<ProviderGroup> subscribe(ConsumerConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isSubscribe()) {
        // 注册中心不订阅
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return null;
    }
    if (!config.isSubscribe()) {
        return null;
    }
    try {
        List<ProviderInfo> providers = lookupHealthService(config);
        if (EventBus.isEnable(ConsumerSubEvent.class)) {
            ConsumerSubEvent event = new ConsumerSubEvent(config);
            EventBus.post(event);
        }
        return Collections.singletonList(new ProviderGroup().addAll(providers));
    } catch (SofaRpcRuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_SUB_PROVIDER, EXT_NAME), e);
    }
}
Also used : ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) ConsumerSubEvent(com.alipay.sofa.rpc.event.ConsumerSubEvent) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)

Example 8 with ConsumerSubEvent

use of com.alipay.sofa.rpc.event.ConsumerSubEvent in project sofa-rpc by sofastack.

the class SofaRpcMetricsTest method testMicrometerMetrics.

@Test
public void testMicrometerMetrics() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    SimpleMeterRegistry registry = new SimpleMeterRegistry();
    try (SofaRpcMetrics metrics = new SofaRpcMetrics()) {
        metrics.bindTo(registry);
        Method handleEvent = EventBus.class.getDeclaredMethod("handleEvent", Subscriber.class, Event.class);
        handleEvent.setAccessible(true);
        SofaRequest request = buildRequest();
        SofaResponse response = buildResponse();
        RpcInternalContext.getContext().setAttachment(RpcConstants.INTERNAL_KEY_CLIENT_ELAPSE, 100).setAttachment(RpcConstants.INTERNAL_KEY_IMPL_ELAPSE, 10).setAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE, 3).setAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE, 4);
        handleEvent.invoke(EventBus.class, metrics, new ClientEndInvokeEvent(request, response, null));
        handleEvent.invoke(EventBus.class, metrics, new ServerSendEvent(request, response, null));
        ServerConfig serverConfig = new ServerConfig();
        handleEvent.invoke(EventBus.class, metrics, new ServerStartedEvent(serverConfig, new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>())));
        handleEvent.invoke(EventBus.class, metrics, new ServerStoppedEvent(serverConfig));
        handleEvent.invoke(EventBus.class, metrics, new ProviderPubEvent(new ProviderConfig<>()));
        handleEvent.invoke(EventBus.class, metrics, new ConsumerSubEvent(new ConsumerConfig<>()));
        Assert.assertEquals(12, registry.getMeters().size());
    }
}
Also used : ClientEndInvokeEvent(com.alipay.sofa.rpc.event.ClientEndInvokeEvent) SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) ServerSendEvent(com.alipay.sofa.rpc.event.ServerSendEvent) ConsumerSubEvent(com.alipay.sofa.rpc.event.ConsumerSubEvent) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Method(java.lang.reflect.Method) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ServerStartedEvent(com.alipay.sofa.rpc.event.ServerStartedEvent) ServerStoppedEvent(com.alipay.sofa.rpc.event.ServerStoppedEvent) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent) SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse) Test(org.junit.Test)

Aggregations

ConsumerSubEvent (com.alipay.sofa.rpc.event.ConsumerSubEvent)8 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)6 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)4 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)4 SofaRpcRuntimeException (com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)3 ProviderInfoListener (com.alipay.sofa.rpc.listener.ProviderInfoListener)2 Test (org.junit.Test)2 NoopRegistry (com.alipay.lookout.api.NoopRegistry)1 Registry (com.alipay.lookout.api.Registry)1 DefaultRegistry (com.alipay.lookout.core.DefaultRegistry)1 InfoWrapper (com.alipay.lookout.core.InfoWrapper)1 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)1 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)1 ClientEndInvokeEvent (com.alipay.sofa.rpc.event.ClientEndInvokeEvent)1 ProviderPubEvent (com.alipay.sofa.rpc.event.ProviderPubEvent)1 ServerSendEvent (com.alipay.sofa.rpc.event.ServerSendEvent)1 ServerStartedEvent (com.alipay.sofa.rpc.event.ServerStartedEvent)1 ServerStoppedEvent (com.alipay.sofa.rpc.event.ServerStoppedEvent)1