Tars http服務


http服務 發布到平台后可以直接使用 http 請求來調用,注意發布服務時選擇 非 tars 協議!

1,創建一個 springboot 項目,並在啟動類添加 @EnableTarsServer 注解

@SpringBootApplication
@EnableTarsServer
public class TarsSpringbootHttpServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(TarsSpringbootHttpServerApplication.class, args);
    }
}

2,POM 依賴, 和非 http 依賴一致

3,編寫 controller

@TarsHttpService("HttpObj") : 表示是一個 http 服務並指明 obj 名稱
也可以調用別的 tars 服務(可以注解自動注入也可以構建通信器)
@TarsHttpService("HttpObj")
@RestController
public class TestController {
    @RequestMapping("/test")
    public String test() {
        return "success";
    }
    
    @RequestMapping("/test1")
    public String test1() {
        CommunicatorConfig cfg = new CommunicatorConfig();
        Communicator communicator = CommunicatorFactory.getInstance().getCommunicator(cfg);
        GlobalIdPrx proxy = communicator.stringToProxy(GlobalIdPrx.class,
                "ICTPAAS.GlobalId.GlobalIdObj@tcp -h 203.195.235.113 -p 30001");
        
        String globalId = proxy.getGlobalId("qqqqq");
        return globalId;
    }
}

4,測試

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM