Java Code Examples for org.apache.dubbo.config.ReferenceConfig#setUrl()

The following examples show how to use org.apache.dubbo.config.ReferenceConfig#setUrl() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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;
}