org.apache.dubbo.config.ReferenceConfig Java Examples

The following examples show how to use org.apache.dubbo.config.ReferenceConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricsServiceIT.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    for (int i = 0; i < 10; i++) {
        System.out.println("result: " + demoService.sayHello("dubbo"));
    }

    ReferenceConfig<MetricsService> reference = new ReferenceConfig<>();
    reference.setApplication(new ApplicationConfig("metrics-demo-consumer"));
    reference.setUrl("dubbo://" + providerHost + ":" + providerPort + "/" + MetricsService.class.getName());
    reference.setInterface(MetricsService.class);
    MetricsService service = reference.get();
    String result = service.getMetricsByGroup("dubbo");
    JSONArray metrics = (JSONArray) JSON.parse(result);
    Assert.assertFalse(metrics.isEmpty());
    for (int i = 0; i < metrics.size(); i++) {
        String metric = (String) ((JSONObject) metrics.get(1)).get("metric");
        Assert.assertTrue(metric.startsWith("dubbo.provider") || metric.startsWith("threadPool"));
    }
}
 
Example #2
Source File: DubboConfigsMetadata.java    From dubbo-spring-boot-project with Apache License 2.0 6 votes vote down vote up
public Map<String, Map<String, Map<String, Object>>> configs() {

        Map<String, Map<String, Map<String, Object>>> configsMap = new LinkedHashMap<>();

        addDubboConfigBeans(ApplicationConfig.class, configsMap);
        addDubboConfigBeans(ConsumerConfig.class, configsMap);
        addDubboConfigBeans(MethodConfig.class, configsMap);
        addDubboConfigBeans(ModuleConfig.class, configsMap);
        addDubboConfigBeans(MonitorConfig.class, configsMap);
        addDubboConfigBeans(ProtocolConfig.class, configsMap);
        addDubboConfigBeans(ProviderConfig.class, configsMap);
        addDubboConfigBeans(ReferenceConfig.class, configsMap);
        addDubboConfigBeans(RegistryConfig.class, configsMap);
        addDubboConfigBeans(ServiceConfig.class, configsMap);

        return configsMap;

    }
 
Example #3
Source File: JbootDubborpc.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public <T> T onServiceCreate(Class<T> interfaceClass, JbootrpcReferenceConfig config) {
    ReferenceConfig<T> reference = DubboUtil.toReferenceConfig(config);
    reference.setInterface(interfaceClass);

    String directUrl = rpcConfig.getUrl(interfaceClass.getName());
    if (StrUtil.isNotBlank(directUrl)) {
        reference.setUrl(directUrl);
    }

    String consumer = rpcConfig.getConsumer(interfaceClass.getName());
    if (consumer != null) {
        reference.setConsumer(DubboUtil.getConsumer(consumer));
    }

    if (reference.getGroup() == null) {
        reference.setGroup(rpcConfig.getGroup(interfaceClass.getName()));
    }

    if (reference.getVersion() == null) {
        reference.setVersion(rpcConfig.getVersion(interfaceClass.getName()));
    }

    return reference.get();
}
 
Example #4
Source File: GenericCallConsumer.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("generic-call-consumer");
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("zookeeper://127.0.0.1:2181");
        ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<>();
        referenceConfig.setInterface("org.apache.dubbo.samples.generic.call.api.HelloService");
        applicationConfig.setRegistry(registryConfig);
        referenceConfig.setApplication(applicationConfig);
        referenceConfig.setGeneric(true);
        referenceConfig.setAsync(true);
        referenceConfig.setTimeout(7000);

        genericService = referenceConfig.get();
        invokeSayHello();
        invokeSayHelloAsync();
        invokeAsyncSayHelloAsync();
        invokeAsyncSayHello();
//        invokeSayHelloAsyncComplex();
        asyncInvokeSayHelloAsyncComplex();
//        invokeSayHelloAsyncGenericComplex();
        asyncInvokeSayHelloAsyncGenericComplex();
    }
 
Example #5
Source File: GenericServiceTest.java    From jmeter-plugins-for-apache-dubbo with Apache License 2.0 6 votes vote down vote up
@Test
public void testAttachment() {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("api-generic-consumer");
    ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
    reference.setUrl("dubbo://192.168.56.1:20880/org.apache.dubbo.samples.basic.api.DemoService");
    reference.setVersion("1.0.0");
    reference.setTimeout(2000);
    reference.setGeneric(true);
    reference.setApplication(application);
    reference.setInterface("com.jiuyescm.account.api.IUserService");
    GenericService genericService = reference.get();
    RpcContext.getContext().setAttachment("test.ningyu","this is attachmentValue");
    Object obj = genericService.$invoke("sayHello", new String[]{String.class.getName()}, new String[]{"ningyu"});
    String json = JsonUtils.toJson(obj);
    System.out.println(json);
}
 
Example #6
Source File: DirectServiceIT.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Test
public void testGeneric() throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("direct-consumer");
    ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
    reference.setUrl("dubbo://" + providerAddress + ":20880/" + DirectService.class.getName());
    reference.setVersion("1.0.0-daily");
    reference.setGroup("test");
    reference.setGeneric(true);
    reference.setApplication(application);
    reference.setInterface(DirectService.class.getName());
    GenericService genericService = reference.get();
    Object obj = genericService.$invoke("sayHello", new String[]{String.class.getName()}, new Object[]{ "generic" });
    String str = (String) obj;
    TestCase.assertTrue(str.startsWith("Hello generic"));
}
 
Example #7
Source File: GenericServiceTest.java    From jmeter-plugins-for-apache-dubbo with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("api-generic-consumer");
    ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
    reference.setUrl("dubbo://192.168.56.1:20880/org.apache.dubbo.samples.basic.api.DemoService");
    reference.setVersion("1.0.0");
    reference.setTimeout(2000);
    reference.setGeneric(true);
    reference.setApplication(application);
    reference.setInterface("com.jiuyescm.account.api.IUserService");
    GenericService genericService = reference.get();
    Object obj = genericService.$invoke("getUserById", new String[]{Long.class.getName()}, new Long[]{1L});
    String json = JsonUtils.toJson(obj);
    System.out.println(json);
}
 
Example #8
Source File: Consumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
    reference.setApplication(applicationConfig);
    reference.setConfigCenter(configCenter);
    reference.setInterface(GreetingsService.class);
    GreetingsService greetingsService = reference.get();
    String message = greetingsService.sayHi("dubbo");
    System.out.println(message);
}
 
Example #9
Source File: GreetingServiceIT.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
    reference.setApplication(new ApplicationConfig("first-dubbo-consumer"));
    reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
    reference.setInterface(GreetingsService.class);
    GreetingsService service = reference.get();
    String message = service.sayHi("dubbo");
    TestCase.assertEquals(message, "hi, dubbo");
}
 
Example #10
Source File: GreetingsServiceIT.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    ConfigCenterConfig configCenter = new ConfigCenterConfig();
    ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-consumer");
    configCenter.setAddress("zookeeper://" + zookeeperHost + ":2181");
    ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
    reference.setApplication(applicationConfig);
    reference.setConfigCenter(configCenter);
    reference.setInterface(GreetingsService.class);
    GreetingsService greetingsService = reference.get();
    String message = greetingsService.sayHi("dubbo");
    Assert.assertEquals("hi, dubbo", message);
}
 
Example #11
Source File: DemoServiceIT.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    ConfigCenterConfig configCenter = new ConfigCenterConfig();
    ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-consumer");
    configCenter.setAddress("zookeeper://" + zookeeperHost + ":2181");
    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setApplication(applicationConfig);
    reference.setConfigCenter(configCenter);
    reference.setInterface(DemoService.class);
    DemoService demoService = reference.get();
    Assert.assertEquals("Hello, you!", demoService.sayHello());
}
 
Example #12
Source File: HelloServiceIT.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    ApplicationConfig applicationConfig = new ApplicationConfig();
    applicationConfig.setName("generic-call-consumer");
    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress("zookeeper://" + zookeeperHost + ":2181");
    ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<>();
    referenceConfig.setInterface("org.apache.dubbo.samples.generic.call.api.HelloService");
    applicationConfig.setRegistry(registryConfig);
    referenceConfig.setApplication(applicationConfig);
    referenceConfig.setGeneric(true);
    referenceConfig.setAsync(true);
    referenceConfig.setTimeout(7000);
    genericService = referenceConfig.get();
}
 
Example #13
Source File: DirectServiceIT.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void testApi() throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("direct-consumer");
    ReferenceConfig<DirectService> reference = new ReferenceConfig<>();
    reference.setUrl("dubbo://" + providerAddress + ":20880/" + DirectService.class.getName());
    reference.setVersion("1.0.0-daily");
    reference.setGroup("test");
    reference.setApplication(application);
    reference.setInterface(DirectService.class.getName());
    DirectService service = reference.get();
    String result = service.sayHello("api");
    TestCase.assertTrue(result.startsWith("Hello api"));
}
 
Example #14
Source File: SslBasicConsumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    SslConfig sslConfig = new SslConfig();
    if (args.length > 0) {
        if (args.length != 1 && args.length != 3) {
            System.out.println(
                    "USAGE: BasicConsumer [trustCertCollectionFilePath [certChainFilePath privateKeyFilePath]]\n " +
                            "Specify 'certChainFilePath' and 'privateKeyFilePath' only if you need Mutual TLS.");
            System.exit(0);
        }

        switch (args.length) {
            case 1:
                sslConfig.setClientTrustCertCollectionPath(args[0]);
                break;
            case 3:
                sslConfig.setClientTrustCertCollectionPath(args[0]);
                sslConfig.setClientKeyCertChainPath(args[1]);
                sslConfig.setClientPrivateKeyPath(args[2]);
        }
    }

    DubboBootstrap bootstrap = DubboBootstrap.getInstance()
            .application(new ApplicationConfig("first-dubbo-consumer"))
            .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
            .ssl(sslConfig);

    ReferenceConfig<IGreeter> reference = new ReferenceConfig<>();
    reference.setInterface(IGreeter.class);

    bootstrap.reference(reference);

    bootstrap.start();

    IGreeter service = bootstrap.getCache().get(reference);
    HelloReply helloReply = service.sayHello(HelloRequest.newBuilder().setName("dubbo").build());
    System.out.println(helloReply.getMessage());
}
 
Example #15
Source File: DubboProxyService.java    From bird-java with MIT License 5 votes vote down vote up
/**
 * dubbo rpc invoke.
 *
 * @param paramMap    request paramMap.
 * @param dubboHandle dubboHandle.
 * @return rpc result.
 * @throws GatewayException exception for rpc.
 */
public Object genericInvoker(ServerWebExchange exchange, final DubboHandle dubboHandle) throws GatewayException {
    ReferenceConfig<GenericService> reference = buildReferenceConfig(dubboHandle);

    ReferenceConfigCache referenceConfigCache = ReferenceConfigCache.getCache();

    GenericService genericService = null;
    try {
        genericService = referenceConfigCache.get(reference);
    } catch (Exception ex) {
        REFERENCE_CONFIG_MAP.remove(dubboHandle);
        reference.destroy();
        referenceConfigCache.destroy(reference);

        log.error(dubboHandle.getInterfaceName() + "服务连接失败");
        throw new GatewayException(ex);
    }

    final Map<String, Object> paramMap = resolveParam(exchange);
    final Pair<String[], Object[]> pair = buildParameter(paramMap, dubboHandle);

    try {
        return genericService.$invoke(dubboHandle.getMethodName(), pair.getLeft(), pair.getRight());
    } catch (GenericException e) {
        log.error(e.getExceptionMessage());
        if (StringUtils.equals(e.getExceptionClass(), UserFriendlyException.class.getName())) {
            throw new UserFriendlyException(e.getExceptionMessage());
        } else {
            throw new GatewayException(e.getMessage());
        }
    }
}
 
Example #16
Source File: DubboProxyService.java    From bird-java with MIT License 5 votes vote down vote up
private ReferenceConfig<GenericService> buildReferenceConfig(final DubboHandle dubboHandle) {
    ReferenceConfig<GenericService> reference = REFERENCE_CONFIG_MAP.get(dubboHandle);
    if (Objects.isNull(reference)) {
        reference = new ReferenceConfig<>();
        reference.setInterface(dubboHandle.getInterfaceName());
        reference.setGeneric(true);

        reference.setRegistry(cacheRegistry(dubboHandle));
        reference.setConsumer(getConsumer(dubboHandle));

        if (StringUtils.isNoneBlank(dubboHandle.getVersion())) {
            reference.setVersion(dubboHandle.getVersion());
        }
        if (StringUtils.isNoneBlank(dubboHandle.getProtocol())) {
            reference.setProtocol(dubboHandle.getProtocol());
        }
        if (StringUtils.isNoneBlank(dubboHandle.getGroup())) {
            reference.setGroup(dubboHandle.getGroup());
        }
        if (StringUtils.isNoneBlank(dubboHandle.getLoadBalance())) {
            reference.setLoadbalance(dubboHandle.getLoadBalance());
        }

        Optional.ofNullable(dubboHandle.getTimeout()).ifPresent(reference::setTimeout);
        Optional.ofNullable(dubboHandle.getRetries()).ifPresent(reference::setRetries);

        REFERENCE_CONFIG_MAP.put(dubboHandle, reference);
    }

    return reference;
}
 
Example #17
Source File: Consumer.java    From rpcx-benchmark with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
    String zk = "zookeeper://127.0.0.1:2181";
    if (args.length > 2) {
        zk = args[2];
    }
    reference.setRegistry(new RegistryConfig(zk));
    reference.setInterface(DemoService.class);
    reference.setTimeout(10000);
    DemoService service = reference.get();

    DemoAction demoAction = new DemoAction();
    demoAction.setDemoService(service);

    if (args.length > 0) {
        demoAction.threads = Integer.parseInt(args[0]);
    }
    if (args.length > 1) {
        demoAction.count = Integer.parseInt(args[1]);
    }

    demoAction.warmup();

    demoAction.start();

}
 
Example #18
Source File: Application.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "destroy")
public ReferenceConfig<GreetService> reference() {
    ReferenceConfig<GreetService> referenceConfig = new ReferenceConfig<>();
    referenceConfig.setApplication(applicationConfig);

    referenceConfig.setInterface(GreetService.class);
    referenceConfig.setUrl("dubbo://localhost:20080");

    return referenceConfig;
}
 
Example #19
Source File: ITTracingFilter_Consumer.java    From brave with Apache License 2.0 5 votes vote down vote up
@Before public void setup() {
  server.start();

  String url = "dubbo://" + server.ip() + ":" + server.port() + "?scope=remote&generic=bean";
  client = new ReferenceConfig<>();
  client.setGeneric("true");
  client.setFilter("tracing");
  client.setInterface(GreeterService.class);
  client.setUrl(url);

  wrongClient = new ReferenceConfig<>();
  wrongClient.setGeneric("true");
  wrongClient.setFilter("tracing");
  wrongClient.setInterface(GraterService.class);
  wrongClient.setUrl(url);

  DubboBootstrap.getInstance().application(application)
      .reference(client)
      .reference(wrongClient)
      .start();

  init();

  // perform a warmup request to allow CI to fail quicker
  client.get().sayHello("jorge");
  server.takeRequest();
  testSpanHandler.takeRemoteSpan(CLIENT);
}
 
Example #20
Source File: ITTracingFilter_Provider.java    From brave with Apache License 2.0 5 votes vote down vote up
@Before public void setup() {
  server.service.setFilter("tracing");
  server.service.setGeneric("true");
  server.service.setInterface(GreeterService.class);
  server.service.setRef((method, parameterTypes, args) -> {
    String arg = (String) args[0];
    if (arg.equals("bad")) throw new IllegalArgumentException("bad");
    return currentTraceContext.get() != null
        ? currentTraceContext.get().traceIdString()
        : "";
  });
  init();
  server.start();

  String url = "dubbo://" + server.ip() + ":" + server.port() + "?scope=remote&generic=bean";
  client = new ReferenceConfig<>();
  client.setGeneric("true");
  client.setInterface(GreeterService.class);
  client.setUrl(url);

  DubboBootstrap.getInstance().application(application)
      .service(server.service)
      .reference(client)
      .start();

  // perform a warmup request to allow CI to fail quicker
  client.get().sayHello("jorge");
  testSpanHandler.takeRemoteSpan(SERVER);
}
 
Example #21
Source File: MonitorServiceIT.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    for (int i = 0; i < 10; i++) {
        demoService.sayHello("world");
        Thread.sleep(50);
    }

    ReferenceConfig<MonitorService> reference = new ReferenceConfig<>();
    reference.setApplication(new ApplicationConfig("demo-consumer"));
    reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
    reference.setInterface(MonitorService.class);
    reference.setFilter("-monitor");
    MonitorService service = reference.get();
    List<URL> stats = service.lookup(null);

    boolean countProvider = false;
    boolean countConsumer = false;
    for (URL stat : stats) {
        Assert.assertEquals("count", stat.getProtocol());
        Assert.assertEquals("org.apache.dubbo.samples.monitor.api.DemoService/sayHello", stat.getPath());
        if (stat.getParameter("application").equals("demo-provider")) {
            countProvider = true;
        }
        if (stat.getParameter("application").equals("demo-consumer")) {
            countConsumer = true;
        }
        System.out.println(stat);
    }
    Assert.assertTrue(countConsumer && countProvider);
}
 
Example #22
Source File: SslBasicConsumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    SslConfig sslConfig = new SslConfig();
    if (args.length > 0) {
        if (args.length != 1 && args.length != 3) {
            System.out.println(
                    "USAGE: BasicConsumer [trustCertCollectionFilePath [certChainFilePath privateKeyFilePath]]\n " +
                            "Specify 'certChainFilePath' and 'privateKeyFilePath' only if you need Mutual TLS.");
            System.exit(0);
        }

        switch (args.length) {
            case 1:
                sslConfig.setClientTrustCertCollectionPath(args[0]);
                break;
            case 3:
                sslConfig.setClientTrustCertCollectionPath(args[0]);
                sslConfig.setClientKeyCertChainPath(args[1]);
                sslConfig.setClientPrivateKeyPath(args[2]);
        }
    }

    DubboBootstrap bootstrap = DubboBootstrap.getInstance()
            .application(new ApplicationConfig("first-dubbo-consumer"))
            .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
            .ssl(sslConfig);

    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setInterface(DemoService.class);

    bootstrap.reference(reference);

    bootstrap.start();

    DemoService service = bootstrap.getCache().get(reference);
    String message = service.sayHello("dubbo");
    System.out.println(message);
}
 
Example #23
Source File: Application.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
    reference.setApplication(new ApplicationConfig("first-dubbo-consumer"));
    reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
    reference.setInterface(GreetingsService.class);
    GreetingsService service = reference.get();
    String message = service.sayHi("dubbo");
    System.out.println(message);
}
 
Example #24
Source File: GenericServiceTest.java    From jmeter-plugins-for-apache-dubbo with Apache License 2.0 5 votes vote down vote up
@Test
public void testZk() {
    for(int i=0;i<5;i++) {
        ApplicationConfig application = new ApplicationConfig();
        application.setName("api-generic-consumer");
        ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
        reference.setVersion("1.0.0");
        RegistryConfig registry = new RegistryConfig();
        registry.setProtocol(Constants.REGISTRY_ZOOKEEPER);
        registry.setAddress("192.168.0.44:2181,192.168.0.44:2182,192.168.0.44:2183");
        registry.setTimeout(10000);
        reference.setRegistry(registry);
        ConfigCenterConfig cc = new ConfigCenterConfig();
        cc.setAddress("192.168.0.58:2181,192.168.0.59:2181,192.168.0.60:2181");
        cc.setProtocol(Constants.REGISTRY_ZOOKEEPER);
        cc.setTimeout(Long.valueOf("10000"));
        cc.setGroup("");
        cc.setNamespace("");
        reference.setConfigCenter(cc);
        reference.setTimeout(2000);
        reference.setGeneric(true);
        reference.setApplication(application);
        reference.setInterface("com.jiuyescm.account.api.IUserService");
        GenericService genericService = reference.get();
        Object obj = genericService.$invoke("getUserById", new String[]{Long.class.getName()}, new Long[]{1L});
        String json = JsonUtils.toJson(obj);
        System.out.println(json);
    }
}
 
Example #25
Source File: Dubbo27ITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static ReferenceConfig<GreeterService> getClient(final String ip, final int port) {
  final ReferenceConfig<GreeterService> client = new ReferenceConfig<>();
  client.setApplication(new ApplicationConfig("test"));
  client.setInterface(GreeterService.class);
  client.setUrl("dubbo://" + ip + ":" + port);
  client.setScope("local");
  client.setInjvm(true);
  return client;
}
 
Example #26
Source File: Dubbo27ITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final CountDownLatch latch = TestUtil.initExpectedSpanLatch(2);
  final String linkLocalIp = "127.0.0.1";
  final ServiceConfig<GreeterService> service = getService();
  service.export();
  final ReferenceConfig<GreeterService> client = getClient(linkLocalIp, service.getProtocol().getPort());
  client.get().sayHello("jorge");
  TestUtil.checkSpan(latch, new ComponentSpanCount("java-dubbo", 2));
  client.destroy();
  service.unexport();
}
 
Example #27
Source File: MockClient.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public MockClient(final String ip, final int port) {
  client = new ReferenceConfig<>();
  client.setApplication(new ApplicationConfig("test"));
  client.setInterface(GreeterService.class);
  client.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
  // client.setFilter("traceFilter");
  client.setUrl("dubbo://" + ip + ":" + port);
  client.setTimeout(10000);
  client.setCheck(false);
  client.setScope("local");
  client.setInjvm(true);
}
 
Example #28
Source File: ApplicationConfigCache.java    From soul with Apache License 2.0 5 votes vote down vote up
/**
 * Get reference config.
 *
 * @param <T>         the type parameter
 * @param serviceName the service name
 * @return the reference config
 */
public <T> ReferenceConfig<T> get(final String serviceName) {
    try {
        return (ReferenceConfig<T>) cache.get(serviceName);
    } catch (ExecutionException e) {
        throw new SoulException(e.getCause());
    }
}
 
Example #29
Source File: ApplicationConfigCache.java    From soul with Apache License 2.0 5 votes vote down vote up
/**
 * Build reference config.
 *
 * @param metaData the meta data
 * @return the reference config
 */
public ReferenceConfig<GenericService> build(final MetaData metaData) {
    ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
    reference.setGeneric(true);
    reference.setApplication(applicationConfig);
    reference.setRegistry(registryConfig);
    reference.setInterface(metaData.getServiceName());
    reference.setProtocol("dubbo");
    String rpcExt = metaData.getRpcExt();
    DubboParamExtInfo dubboParamExtInfo = GsonUtils.getInstance().fromJson(rpcExt, DubboParamExtInfo.class);
    if (Objects.nonNull(dubboParamExtInfo)) {
        if (StringUtils.isNoneBlank(dubboParamExtInfo.getVersion())) {
            reference.setVersion(dubboParamExtInfo.getVersion());
        }
        if (StringUtils.isNoneBlank(dubboParamExtInfo.getGroup())) {
            reference.setGroup(dubboParamExtInfo.getGroup());
        }
        if (StringUtils.isNoneBlank(dubboParamExtInfo.getLoadbalance())) {
            final String loadBalance = dubboParamExtInfo.getLoadbalance();
            reference.setLoadbalance(buildLoadBalanceName(loadBalance));
        }
        Optional.ofNullable(dubboParamExtInfo.getTimeout()).ifPresent(reference::setTimeout);
        Optional.ofNullable(dubboParamExtInfo.getRetries()).ifPresent(reference::setRetries);
    }
    Object obj = reference.get();
    if (obj != null) {
        log.info("init apache dubbo reference success there meteData is :{}", metaData.toString());
        cache.put(metaData.getServiceName(), reference);
    }
    return reference;
}
 
Example #30
Source File: ApplicationConfigCache.java    From soul with Apache License 2.0 5 votes vote down vote up
/**
 * Init ref reference config.
 *
 * @param metaData the meta data
 * @return the reference config
 */
public ReferenceConfig<GenericService> initRef(final MetaData metaData) {
    try {
        ReferenceConfig<GenericService> referenceConfig = cache.get(metaData.getServiceName());
        if (StringUtils.isNoneBlank(referenceConfig.getInterface())) {
            return referenceConfig;
        }
    } catch (ExecutionException e) {
        log.error("init dubbo ref ex:{}", e.getMessage());
    }
    return build(metaData);
    
}