Search in sources :

Example 1 with DemoService

use of org.apache.dubbo.demo.DemoService in project dubbo by alibaba.

the class Application method runWithRefer.

private static void runWithRefer() {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
    reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
    reference.setInterface(DemoService.class);
    DemoService service = reference.get();
    String message = service.sayHello("dubbo");
    System.out.println(message);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.demo.DemoService)

Example 2 with DemoService

use of org.apache.dubbo.demo.DemoService in project dubbo by alibaba.

the class Application method runWithBootstrap.

private static void runWithBootstrap() {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setInterface(DemoService.class);
    reference.setGeneric("true");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("dubbo-demo-api-consumer")).registry(new RegistryConfig("zookeeper://127.0.0.1:2181")).reference(reference).start();
    DemoService demoService = ReferenceConfigCache.getCache().get(reference);
    String message = demoService.sayHello("dubbo");
    System.out.println(message);
    // generic invoke
    GenericService genericService = (GenericService) demoService;
    Object genericInvokeResult = genericService.$invoke("sayHello", new String[] { String.class.getName() }, new Object[] { "dubbo generic invoke" });
    System.out.println(genericInvokeResult);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.demo.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap)

Example 3 with DemoService

use of org.apache.dubbo.demo.DemoService in project dubbo by alibaba.

the class Application method main.

/**
 * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before
 * launch the application
 */
public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml");
    context.start();
    DemoService demoService = context.getBean("demoService", DemoService.class);
    GreetingService greetingService = context.getBean("greetingService", GreetingService.class);
    new Thread(() -> {
        while (true) {
            String greetings = greetingService.hello();
            System.out.println(greetings + " from separated thread.");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();
    while (true) {
        CompletableFuture<String> hello = demoService.sayHelloAsync("world");
        System.out.println("result: " + hello.get());
        String greetings = greetingService.hello();
        System.out.println("result: " + greetings);
        Thread.sleep(500);
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DemoService(org.apache.dubbo.demo.DemoService) GreetingService(org.apache.dubbo.demo.GreetingService)

Aggregations

DemoService (org.apache.dubbo.demo.DemoService)3 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)2 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)2 RegistryConfig (org.apache.dubbo.config.RegistryConfig)2 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 GreetingService (org.apache.dubbo.demo.GreetingService)1 GenericService (org.apache.dubbo.rpc.service.GenericService)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1