Search in sources :

Example 1 with SubscribeServiceRequest

use of com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceRequest in project sofa-rpc by sofastack.

the class MeshApiClientTest method testSubscribe.

@Test
public void testSubscribe() {
    // 11.166.22.163:12200?_TIMEOUT=3000&p=1&_SERIALIZETYPE=protobuf&_WARMUPTIME=0&_WARMUPWEIGHT=10&app_name=bar1&zone=GZ00A&_MAXREADIDLETIME=30&_IDLETIMEOUT=27&v=4.0&_WEIGHT=100&startTime=1524565802559
    SubscribeServiceRequest request = new SubscribeServiceRequest();
    request.setServiceName("com.alipay.rpc.common.service.facade.pb.SampleServicePb:1.0");
    SubscribeServiceResult result = meshApiClient.subscribeService(request);
    Assert.assertTrue(result.isSuccess());
}
Also used : SubscribeServiceRequest(com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceRequest) UnSubscribeServiceRequest(com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceRequest) UnSubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceResult) SubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceResult) Test(org.junit.Test)

Example 2 with SubscribeServiceRequest

use of com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceRequest in project sofa-rpc by sofastack.

the class MeshRegistry method buildSubscribeServiceRequest.

protected SubscribeServiceRequest buildSubscribeServiceRequest(ConsumerConfig consumerConfig) {
    String key = MeshRegistryHelper.buildMeshKey(consumerConfig, consumerConfig.getProtocol());
    SubscribeServiceRequest subscribeRequest = new SubscribeServiceRequest();
    subscribeRequest.setServiceName(key);
    return subscribeRequest;
}
Also used : UnSubscribeServiceRequest(com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceRequest) SubscribeServiceRequest(com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceRequest)

Example 3 with SubscribeServiceRequest

use of com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceRequest in project sofa-rpc by sofastack.

the class MeshRegistry method subscribe.

@Override
public List<ProviderGroup> subscribe(final ConsumerConfig config) {
    final ProviderInfoListener providerInfoListener = config.getProviderInfoListener();
    asyncCreateConnectionExecutor.execute(new Runnable() {

        @Override
        public void run() {
            final String appName = config.getAppName();
            registerAppInfoOnce(appName);
            SubscribeServiceRequest subscribeRequest = buildSubscribeServiceRequest(config);
            SubscribeServiceResult subscribeServiceResult = client.subscribeService(subscribeRequest);
            if (subscribeServiceResult == null || !subscribeServiceResult.isSuccess()) {
                throw new RuntimeException("regist consumer occors error," + subscribeRequest);
            }
            List<ProviderGroup> providerGroups = new ArrayList<ProviderGroup>();
            ProviderGroup providerGroup = new ProviderGroup();
            List<ProviderInfo> providerInfos = new ArrayList<ProviderInfo>();
            String url = fillProtocolAndVersion(subscribeServiceResult, client.getHost(), "", config.getProtocol());
            ProviderInfo providerInfo = SofaRegistryHelper.parseProviderInfo(url);
            providerInfos.add(providerInfo);
            providerGroup.setProviderInfos(providerInfos);
            providerGroups.add(providerGroup);
            if (EventBus.isEnable(ConsumerSubEvent.class)) {
                ConsumerSubEvent event = new ConsumerSubEvent(config);
                EventBus.post(event);
            }
            if (providerInfoListener != null) {
                providerInfoListener.updateAllProviders(providerGroups);
            }
        }
    });
    // async
    return null;
}
Also used : ProviderInfoListener(com.alipay.sofa.rpc.listener.ProviderInfoListener) ConsumerSubEvent(com.alipay.sofa.rpc.event.ConsumerSubEvent) UnSubscribeServiceRequest(com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceRequest) SubscribeServiceRequest(com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceRequest) ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) ArrayList(java.util.ArrayList) List(java.util.List) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup) SubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceResult)

Aggregations

SubscribeServiceRequest (com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceRequest)3 UnSubscribeServiceRequest (com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceRequest)3 SubscribeServiceResult (com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceResult)2 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)1 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)1 ConsumerSubEvent (com.alipay.sofa.rpc.event.ConsumerSubEvent)1 ProviderInfoListener (com.alipay.sofa.rpc.listener.ProviderInfoListener)1 UnSubscribeServiceResult (com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceResult)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1