You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@eventmesh.apache.org by "pandaapo (via GitHub)" <gi...@apache.org> on 2023/08/09 11:33:58 UTC
Re: [PR] [ISSUE 4342] Fix build error and optimize some code. (eventmesh)
pandaapo commented on code in PR #4343:
URL: https://github.com/apache/eventmesh/pull/4343#discussion_r1288343745
##########
eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/RemoteSubscribeInstance.java:
##########
@@ -31,25 +35,48 @@
import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
import org.apache.eventmesh.common.utils.IPUtils;
import org.apache.eventmesh.common.utils.JsonUtils;
+import org.apache.eventmesh.util.Utils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
+import java.io.IOException;
import java.util.Collections;
import java.util.Objects;
+import java.util.Properties;
import io.netty.handler.codec.http.HttpMethod;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
public class RemoteSubscribeInstance {
static final CloseableHttpClient httpClient = HttpClients.createDefault();
+ Properties properties;
+
+ {
+ try {
+ properties = Utils.readPropertiesFile(ExampleConstants.CONFIG_FILE_NAME);
+ } catch (IOException e) {
+ log.error("Failed to read the file.", e);
+ }
+ }
+
+ final String localPort = properties.getProperty(SERVER_PORT);
+ final String httServerPort = properties.getProperty(EVENTMESH_HTTP_PORT);
+ final String testURL = getURL(localPort, "/sub/test");
+ final String localURL = getURL(httServerPort, "/eventmesh/subscribe/local");
+ final String remoteURL = getURL(httServerPort, "/eventmesh/subscribe/remote");
Review Comment:
Considering this is a demo aimed at providing a convenient user experience, How about assigning default values to `localPort` and `httpServerPort` so that even if the corresponding configurations are accidentally missing, users can still successfully run the demo?
##########
eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/RemoteSubscribeInstance.java:
##########
@@ -58,38 +85,37 @@ private static void subscribeRemote() {
final RequestParam subscribeParam = buildCommonRequestParam()
.addBody(SubscribeRequestBody.TOPIC, JsonUtils.toJSONString(Collections.singletonList(subscriptionItem)))
.addBody(SubscribeRequestBody.CONSUMERGROUP, ExampleConstants.DEFAULT_EVENTMESH_TEST_CONSUMER_GROUP)
- .addBody(SubscribeRequestBody.URL, "http://127.0.0.1:8088/sub/test")
- .addBody("remoteMesh", "http://127.0.0.1:10105/eventmesh/subscribe/local");
+ .addBody(SubscribeRequestBody.URL, testURL)
+ .addBody("remoteMesh", localURL);
postMsg(subscribeParam);
}
- private static void unsubscribeRemote() {
+ private void unsubscribeRemote() {
final RequestParam subscribeParam = buildCommonRequestParam()
.addBody(SubscribeRequestBody.TOPIC, JsonUtils.toJSONString(Collections.singletonList(ExampleConstants.EVENTMESH_HTTP_ASYNC_TEST_TOPIC)))
.addBody(SubscribeRequestBody.CONSUMERGROUP, ExampleConstants.DEFAULT_EVENTMESH_TEST_CONSUMER_GROUP)
- .addBody(SubscribeRequestBody.URL, "http://127.0.0.1:8088/sub/test");
+ .addBody(SubscribeRequestBody.URL, testURL);
postMsg(subscribeParam);
}
- private static void postMsg(RequestParam subscribeParam) {
+ private void postMsg(RequestParam subscribeParam) {
// cluster2 ip
- final String target = "http://127.0.0.1:11105/eventmesh/subscribe/remote";
try {
- final String res = HttpUtils.post(httpClient, target, subscribeParam);
+ final String res = HttpUtils.post(httpClient, remoteURL, subscribeParam);
final EventMeshRetObj ret = JsonUtils.parseObject(res, EventMeshRetObj.class);
if (Objects.requireNonNull(ret).getRetCode() != EventMeshRetCode.SUCCESS.getRetCode()) {
throw new EventMeshException(ret.getRetCode(), ret.getRetMsg());
}
} catch (Exception ex) {
- throw new EventMeshException(String.format("Subscribe topic error, target:%s", target), ex);
+ throw new EventMeshException(String.format("Subscribe topic error, target:%s", remoteURL), ex);
}
}
- private static RequestParam buildCommonRequestParam() {
+ private RequestParam buildCommonRequestParam() {
return new RequestParam(HttpMethod.POST)
- .addHeader(ProtocolKey.ClientInstanceKey.IP, IPUtils.getLocalAddress())
+ .addHeader(ProtocolKey.ClientInstanceKey.IP.getKey(), IPUtils.getLocalAddress())
Review Comment:
Just a tip: This issue is being fixed by #4339. So maybe a conflict will occur if #4339 is merged before.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org