Search in sources :

Example 1 with GreetingService

use of org.apache.dubbo.demo.GreetingService 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)1 GreetingService (org.apache.dubbo.demo.GreetingService)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1