@@ -48,48 +48,62 @@ public void stop() {
4848
4949 @ Override
5050 public void registerService (ServiceMeta service , InstanceMeta instance ) throws Exception {
51- String reqJson = "{\n " +
52- " \" scheme\" : \" http\" ,\n " +
53- " \" ip\" : \" " + instance .getIp () + "\" ,\n " +
54- " \" port\" : \" " + instance .getPort () + "\" ,\n " +
55- " \" context\" : \" \" ,\n " +
56- " \" status\" : \" online\" ,\n " +
57- " \" metadata\" : {\n " +
58- " \" env\" : \" dev\" ,\n " +
59- " \" tag\" : \" RED\" \n " +
60- " }\n " +
61- "}" ;
51+ instance .setStatus (true );
52+ String reqJson = JSON .toJSONString (instance );
53+ String url = "http://localhost:8484/reg?service=" + service ;
54+ System .out .println (" ====> reg service: " + url );
6255 final Request request = new Request .Builder ()
63- .url ("http://localhost:8484/reg?service=" + service )
56+ .url (url )
6457 .post (RequestBody .create (JSONTYPE , reqJson ))
6558 .build ();
6659 String respJson = client .newCall (request ).execute ().body ().string ();
67- System .out .println (respJson );
60+ System .out .println (" ====> reg response: " + respJson );
61+ // String reqJson = "{\n" +
62+ // " \"scheme\": \"http\",\n" +
63+ // " \"ip\": \"" + instance.getIp() + "\",\n" +
64+ // " \"port\": \"" + instance.getPort() + "\",\n" +
65+ // " \"context\": \"\",\n" +
66+ // " \"status\": \"online\",\n" +
67+ // " \"metadata\": {\n" +
68+ // " \"env\": \"dev\",\n" +
69+ // " \"tag\": \"RED\"\n" +
70+ // " }\n" +
71+ // "}";
72+ // final Request request = new Request.Builder()
73+ // .url("http://localhost:8484/reg?service=" + service)
74+ // .post(RequestBody.create(JSONTYPE, reqJson))
75+ // .build();
76+ // String respJson = client.newCall(request).execute().body().string();
77+ // System.out.println(respJson);
6878 }
6979
7080 @ Override
7181 public void unregisterService (ServiceMeta service , InstanceMeta instance ) throws Exception {
7282 String reqJson = "{\n " +
7383 " \" scheme\" : \" http\" ,\n " +
74- " \" ip \" : \" " + instance .getIp () + "\" ,\n " +
84+ " \" host \" : \" " + instance .getHost () + "\" ,\n " +
7585 " \" port\" : \" " + instance .getPort () + "\" ,\n " +
7686 " \" context\" : \" \" \n " +
7787 "}" ;
88+ String url = "http://localhost:8484/unreg?service=" + service ;
89+ System .out .println (" ====> unreg service: " + url );
7890 final Request request = new Request .Builder ()
79- .url ("http://localhost:8484/unreg?service=" + service )
91+ .url (url )
8092 .post (RequestBody .create (JSONTYPE , reqJson ))
8193 .build ();
8294 String respJson = client .newCall (request ).execute ().body ().string ();
83- System .out .println (respJson );
95+ System .out .println (" ====> unreg response: " + respJson );
8496 }
8597
8698 public List <InstanceMeta > fetchInstances (ServiceMeta service ) throws Exception {
99+ String url = "http://localhost:8484/findAll?service=" + service ;
100+ System .out .println (" ====> fetchInstances: " + url );
87101 final Request request = new Request .Builder ()
88- .url ("http://localhost:8484/list?service=" + service )
102+ .url (url )
89103 .get ()
90104 .build ();
91105 String respJson = client .newCall (request ).execute ().body ().string ();
92- System .out .println (respJson );
106+ System .out .println (" ====> fetchInstances response: " + respJson );
93107 List <InstanceMeta > instances = JSON .parseObject (respJson , new TypeReference <List <InstanceMeta >>() {
94108 });
95109 return instances ;
@@ -115,12 +129,14 @@ public void subscribe(ServiceMeta service, final ChangedListener listener) {
115129
116130 private boolean hb (ServiceMeta service , ChangedListener listener ) throws Exception {
117131 String svc = service .toString ();
132+ String url = "http://localhost:8484/version?service=" + svc ;
133+ System .out .println (" ====> consumer version: " + url );
118134 final Request request = new Request .Builder ()
119- .url ("http://localhost:8484/hb?service=" + svc )
135+ .url (url )
120136 .get ()
121137 .build ();
122138 String respJson = client .newCall (request ).execute ().body ().string ();
123- System .out .println ("hb: " +respJson );
139+ System .out .println (" ====> consumer version: " +respJson );
124140 Long v = Long .valueOf (respJson );
125141 Long o = TV .getOrDefault (svc , -1L );
126142 if ( v > o ) {
@@ -141,17 +157,19 @@ public void heartbeat(ServiceMeta service, InstanceMeta instance) {
141157 Long heart (ServiceMeta service , InstanceMeta instance ) throws Exception {
142158 String reqJson = "{\n " +
143159 " \" scheme\" : \" http\" ,\n " +
144- " \" ip \" : \" " + instance .getIp () + "\" ,\n " +
160+ " \" host \" : \" " + instance .getHost () + "\" ,\n " +
145161 " \" port\" : \" " + instance .getPort () + "\" ,\n " +
146162 " \" context\" : \" \" ,\n " +
147- " \" status\" : \" online \" \n " +
163+ " \" status\" : true \n " +
148164 "}" ;
165+ String url = "http://localhost:8484/renew?service=" + service ;
166+ System .out .println (" ====> provider renew: " + url );
149167 final Request request = new Request .Builder ()
150- .url ("http://localhost:8484/heart?service=" + service )
168+ .url (url )
151169 .post (RequestBody .create (JSONTYPE , reqJson ))
152170 .build ();
153171 String respJson = client .newCall (request ).execute ().body ().string ();
154- System .out .println ("heart: " +respJson );
172+ System .out .println (" ====> provider renew: " +respJson );
155173 return Long .valueOf (respJson );
156174 }
157175
0 commit comments