|
| 1 | +package io.kimmking.dubbo.demo.consumer; |
| 2 | + |
| 3 | +import io.kimmking.dubbo.demo.api.Order; |
| 4 | +import io.kimmking.dubbo.demo.api.OrderService; |
| 5 | +import io.kimmking.dubbo.demo.api.User; |
| 6 | +import io.kimmking.dubbo.demo.api.UserService; |
| 7 | +import org.apache.dubbo.config.annotation.DubboReference; |
| 8 | +import org.springframework.boot.ApplicationRunner; |
| 9 | +import org.springframework.boot.SpringApplication; |
| 10 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 11 | +import org.springframework.context.annotation.Bean; |
| 12 | + |
| 13 | +@SpringBootApplication |
| 14 | +public class DubboClientApplication { |
| 15 | + |
| 16 | + @DubboReference(version = "1.0.0", url = "dubbo://127.0.0.1:12345") |
| 17 | + private UserService userService; |
| 18 | + |
| 19 | + @DubboReference(version = "1.0.0", url = "dubbo://127.0.0.1:12345") |
| 20 | + private OrderService orderService; |
| 21 | + |
| 22 | + public static void main(String[] args) { |
| 23 | + |
| 24 | + SpringApplication.run(DubboClientApplication.class).close(); |
| 25 | + |
| 26 | + // UserService service = new xxx(); |
| 27 | + // service.findById |
| 28 | + |
| 29 | +// UserService userService = Rpcfx.create(UserService.class, "http://localhost:8080/"); |
| 30 | +// User user = userService.findById(1); |
| 31 | +// System.out.println("find user id=1 from server: " + user.getName()); |
| 32 | +// |
| 33 | +// OrderService orderService = Rpcfx.create(OrderService.class, "http://localhost:8080/"); |
| 34 | +// Order order = orderService.findOrderById(1992129); |
| 35 | +// System.out.println(String.format("find order name=%s, amount=%f",order.getName(),order.getAmount())); |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + @Bean |
| 40 | + public ApplicationRunner runner() { |
| 41 | + return args -> { |
| 42 | + User user = userService.findById(1); |
| 43 | + System.out.println("find user id=1 from server: " + user.getName()); |
| 44 | + Order order = orderService.findOrderById(1992129); |
| 45 | + System.out.println(String.format("find order name=%s, amount=%f",order.getName(),order.getAmount())); |
| 46 | + }; |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments