Search in sources :

Example 1 with SubscribeServiceResult

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

the class MeshApiClient method subscribeService.

public SubscribeServiceResult subscribeService(SubscribeServiceRequest subscribeServiceRequest) {
    final String json = JSON.toJSONString(subscribeServiceRequest);
    String result = httpPost(MeshEndpoint.SUBCRIBE, json);
    SubscribeServiceResult subscribeServiceResult;
    if (!StringUtils.equals(result, errorMessage)) {
        subscribeServiceResult = JSON.parseObject(result, SubscribeServiceResult.class);
        return subscribeServiceResult;
    } else {
        subscribeServiceResult = new SubscribeServiceResult();
        return subscribeServiceResult;
    }
}
Also used : UnSubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceResult) SubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceResult)

Example 2 with SubscribeServiceResult

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

the class MeshRegistryTest method setUp.

@Before
public void setUp() {
    httpMockServer = new HttpMockServer();
    httpMockServer.initSever(7654);
    ApplicationInfoResult applicationInfoResult = new ApplicationInfoResult();
    applicationInfoResult.setSuccess(true);
    httpMockServer.addMockPath(MeshEndpoint.CONFIGS, JSON.toJSONString(applicationInfoResult));
    PublishServiceResult publishServiceResult = new PublishServiceResult();
    publishServiceResult.setSuccess(true);
    httpMockServer.addMockPath(MeshEndpoint.PUBLISH, JSON.toJSONString(publishServiceResult));
    SubscribeServiceResult subscribeServiceResult = new SubscribeServiceResult();
    subscribeServiceResult.setSuccess(true);
    List<String> datas = new ArrayList<String>();
    datas.add("127.0.0.1:12200?v=4.0&p=1");
    datas.add("127.0.0.1:12201?v=4.0&p=1");
    subscribeServiceResult.setDatas(datas);
    httpMockServer.addMockPath(MeshEndpoint.SUBCRIBE, JSON.toJSONString(subscribeServiceResult));
    UnPublishServiceResult unPublishServiceResult = new UnPublishServiceResult();
    unPublishServiceResult.setSuccess(true);
    httpMockServer.addMockPath(MeshEndpoint.UN_PUBLISH, JSON.toJSONString(unPublishServiceResult));
    UnSubscribeServiceResult unSubscribeServiceResult = new UnSubscribeServiceResult();
    unSubscribeServiceResult.setSuccess(true);
    httpMockServer.addMockPath(MeshEndpoint.UN_SUBCRIBE, JSON.toJSONString(unSubscribeServiceResult));
    httpMockServer.start();
    registryConfig = new RegistryConfig().setProtocol("mesh").setSubscribe(true).setRegister(true).setAddress("http://localhost:7654");
    registry = (MeshRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.init();
    registry.start();
}
Also used : UnPublishServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnPublishServiceResult) PublishServiceResult(com.alipay.sofa.rpc.registry.mesh.model.PublishServiceResult) RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) HttpMockServer(com.alipay.sofa.rpc.registry.mesh.mock.HttpMockServer) ArrayList(java.util.ArrayList) UnPublishServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnPublishServiceResult) UnSubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceResult) ApplicationInfoResult(com.alipay.sofa.rpc.registry.mesh.model.ApplicationInfoResult) UnSubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceResult) SubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceResult) Before(org.junit.Before)

Example 3 with SubscribeServiceResult

use of com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceResult 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 4 with SubscribeServiceResult

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

the class MeshApiClientTest method before.

@Before
public void before() {
    httpMockServer = new HttpMockServer();
    meshApiClient = new MeshApiClient("http://localhost:7654");
    httpMockServer.initSever(7654);
    ApplicationInfoResult applicationInfoResult = new ApplicationInfoResult();
    applicationInfoResult.setSuccess(true);
    httpMockServer.addMockPath(MeshEndpoint.CONFIGS, JSON.toJSONString(applicationInfoResult));
    PublishServiceResult publishServiceResult = new PublishServiceResult();
    publishServiceResult.setSuccess(true);
    httpMockServer.addMockPath(MeshEndpoint.PUBLISH, JSON.toJSONString(publishServiceResult));
    SubscribeServiceResult subscribeServiceResult = new SubscribeServiceResult();
    subscribeServiceResult.setSuccess(true);
    httpMockServer.addMockPath(MeshEndpoint.SUBCRIBE, JSON.toJSONString(subscribeServiceResult));
    UnPublishServiceResult unPublishServiceResult = new UnPublishServiceResult();
    unPublishServiceResult.setSuccess(true);
    httpMockServer.addMockPath(MeshEndpoint.UN_PUBLISH, JSON.toJSONString(unPublishServiceResult));
    UnSubscribeServiceResult unSubscribeServiceResult = new UnSubscribeServiceResult();
    unSubscribeServiceResult.setSuccess(true);
    httpMockServer.addMockPath(MeshEndpoint.UN_SUBCRIBE, JSON.toJSONString(unSubscribeServiceResult));
    httpMockServer.start();
}
Also used : UnPublishServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnPublishServiceResult) PublishServiceResult(com.alipay.sofa.rpc.registry.mesh.model.PublishServiceResult) HttpMockServer(com.alipay.sofa.rpc.registry.mesh.mock.HttpMockServer) MeshApiClient(com.alipay.sofa.rpc.registry.mesh.client.MeshApiClient) UnPublishServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnPublishServiceResult) UnSubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceResult) ApplicationInfoResult(com.alipay.sofa.rpc.registry.mesh.model.ApplicationInfoResult) UnSubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceResult) SubscribeServiceResult(com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceResult) Before(org.junit.Before)

Example 5 with SubscribeServiceResult

use of com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceResult 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

SubscribeServiceResult (com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceResult)5 UnSubscribeServiceResult (com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceResult)4 HttpMockServer (com.alipay.sofa.rpc.registry.mesh.mock.HttpMockServer)2 ApplicationInfoResult (com.alipay.sofa.rpc.registry.mesh.model.ApplicationInfoResult)2 PublishServiceResult (com.alipay.sofa.rpc.registry.mesh.model.PublishServiceResult)2 SubscribeServiceRequest (com.alipay.sofa.rpc.registry.mesh.model.SubscribeServiceRequest)2 UnPublishServiceResult (com.alipay.sofa.rpc.registry.mesh.model.UnPublishServiceResult)2 UnSubscribeServiceRequest (com.alipay.sofa.rpc.registry.mesh.model.UnSubscribeServiceRequest)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)1 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)1 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)1 ConsumerSubEvent (com.alipay.sofa.rpc.event.ConsumerSubEvent)1 ProviderInfoListener (com.alipay.sofa.rpc.listener.ProviderInfoListener)1 MeshApiClient (com.alipay.sofa.rpc.registry.mesh.client.MeshApiClient)1 List (java.util.List)1 Test (org.junit.Test)1