Java Code Examples for org.apache.dubbo.config.ApplicationConfig#setName()

The following examples show how to use org.apache.dubbo.config.ApplicationConfig#setName() . 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: GenericImplProvider.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();

    ApplicationConfig applicationConfig = new ApplicationConfig();
    applicationConfig.setName("generic-impl-provider");
    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress(zookeeperAddress);

    GenericService helloService = new GenericImplOfHelloService();
    ServiceConfig<GenericService> service = new ServiceConfig<>();
    service.setApplication(applicationConfig);
    service.setRegistry(registryConfig);
    service.setInterface("org.apache.dubbo.samples.generic.call.api.HelloService");
    service.setRef(helloService);
    service.setGeneric("true");
    service.export();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
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: 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 6
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 7
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 8
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 9
Source File: DubboRepeater.java    From jvm-sandbox-repeater with Apache License 2.0 4 votes vote down vote up
@Override
protected Object executeRepeat(RepeatContext context) throws Exception {
    Invocation invocation = context.getRecordModel().getEntranceInvocation();
    if (!(invocation instanceof DubboInvocation)) {
        throw new RepeatException("type miss match, required DubboInvocation but found " + invocation.getClass().getSimpleName());
    }
    DubboInvocation dubboInvocation = (DubboInvocation) invocation;
    ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
    ApplicationConfig applicationConfig = new ApplicationConfig();
    applicationConfig.setName("jvm-sandbox-repeater");
    // require address to initialize registry config
    RegistryConfig registryConfig = new RegistryConfig();
    String address = context.getMeta().getExtension().get("dubbo.address");
    // using special address
    if (StringUtils.isNotEmpty(address)) {
        registryConfig.setAddress(address);
    } else {
        registryConfig.setAddress(dubboInvocation.getAddress());
    }
    String group = context.getMeta().getExtension().get("dubbo.group");
    // using special group
    if (StringUtils.isNotEmpty(group)) {
        registryConfig.setGroup(group);
    } else {
        registryConfig.setGroup(dubboInvocation.getGroup());
    }
    reference.setApplication(ConfigManager.getInstance().getApplication().orElse(applicationConfig));
    reference.setRegistry(registryConfig);

    // set protocol / interface / version / timeout
    reference.setProtocol(dubboInvocation.getProtocol());
    reference.setInterface(dubboInvocation.getInterfaceName());
    if (StringUtils.isNotEmpty(dubboInvocation.getVersion())) {
        reference.setVersion(dubboInvocation.getVersion());
    }
    // timeout
    reference.setTimeout(context.getMeta().getTimeout());
    // use generic invoke
    reference.setGeneric(true);
    // fix issue #45
    ClassLoader swap = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(GenericService.class.getClassLoader());
        GenericService genericService = reference.get();
        return genericService.$invoke(dubboInvocation.getMethodName(), dubboInvocation.getParameterTypes(), invocation.getRequest());
    } finally {
        Thread.currentThread().setContextClassLoader(swap);
    }
}
 
Example 10
Source File: ApacheDubboInstrumentationTest.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Override
protected DubboTestApi buildDubboTestApi() {
    ApplicationConfig providerAppConfig = new ApplicationConfig();
    providerAppConfig.setName("dubbo-demo");

    ProtocolConfig protocolConfig = new ProtocolConfig();
    protocolConfig.setName("dubbo");
    protocolConfig.setPort(getPort());
    protocolConfig.setThreads(10);

    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress("N/A");

    serviceConfig = new ServiceConfig<>();
    serviceConfig.setApplication(providerAppConfig);
    serviceConfig.setProtocol(protocolConfig);
    serviceConfig.setInterface(DubboTestApi.class);
    serviceConfig.setRef(new DubboTestApiImpl());
    serviceConfig.setRegistry(registryConfig);
    serviceConfig.export();

    referenceConfig = new ReferenceConfig<>();
    referenceConfig.setApplication(providerAppConfig);
    referenceConfig.setInterface(DubboTestApi.class);
    referenceConfig.setUrl("dubbo://localhost:" + getPort());
    referenceConfig.setTimeout(3000);

    List<MethodConfig> methodConfigList = new LinkedList<>();
    referenceConfig.setMethods(methodConfigList);

    MethodConfig asyncConfig = new MethodConfig();
    asyncConfig.setName("async");
    asyncConfig.setAsync(true);
    methodConfigList.add(asyncConfig);

    MethodConfig asyncNoReturnConfig = new MethodConfig();
    asyncNoReturnConfig.setName("asyncNoReturn");
    asyncNoReturnConfig.setAsync(true);
    asyncNoReturnConfig.setReturn(false);
    methodConfigList.add(asyncNoReturnConfig);

    return referenceConfig.get();
}