Skip to content

Commit

Permalink
[INLONG-11110][SDK] Fix incorrect usage of isLocalVisit variable in c…
Browse files Browse the repository at this point in the history
…lient example of dataproxy-sdk module (#11116)
  • Loading branch information
qy-liuhuo committed Sep 17, 2024
1 parent f8757d4 commit 9d97dcb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,31 @@
public class HttpClientExample {

public static void main(String[] args) {
/*
* 1. if 'isLocalVisit' is true use local config from file in ${configBasePath} directory/${dataProxyGroupId}
* .local such as : configBasePath = /data/inlong/dataproxy/conf dataProxyGroupId = test so config file is :
* /data/inlong/dataproxy/conf/test.local and config context like this:
* {"isInterVisit":1,"clusterId":"1","size":1,"switch":1,"address":[{"host":"127.0.0
* .1","port":"46802"},{"host":"127.0.0.1","port":"46802"}]}
*
* 2. if 'isLocalVisit' is false sdk will get config from manager auto.
*/
String inlongGroupId = "test_group_id";
String inlongStreamId = "test_stream_id";
String configBasePath = "/data/inlong/dataproxy/conf";
String configBasePath = "";
String inLongManagerAddr = "127.0.0.1";
String inLongManagerPort = "8080";
String inLongManagerPort = "8083";
String localIP = "127.0.0.1";
String messageBody = "inlong message body!";

HttpProxySender sender = getMessageSender(localIP, inLongManagerAddr,
inLongManagerPort, inlongGroupId, false, false,
inLongManagerPort, inlongGroupId, true, false,
configBasePath);

sendHttpMessage(sender, inlongGroupId, inlongStreamId, messageBody);
sender.close(); // close the sender
}

public static HttpProxySender getMessageSender(String localIP, String inLongManagerAddr,
String inLongManagerPort, String inlongGroupId,
boolean isLocalVisit, boolean isReadProxyIPFromLocal,
boolean requestByHttp, boolean isReadProxyIPFromLocal,
String configBasePath) {
ProxyClientConfig proxyConfig = null;
HttpProxySender sender = null;
try {
proxyConfig = new ProxyClientConfig(localIP, isLocalVisit, inLongManagerAddr,
proxyConfig = new ProxyClientConfig(localIP, requestByHttp, inLongManagerAddr,
Integer.valueOf(inLongManagerPort),
inlongGroupId, "test", "123456");
inlongGroupId, "admin", "inlong");// user and password of manager
proxyConfig.setInlongGroupId(inlongGroupId);
proxyConfig.setConfStoreBasePath(configBasePath);
proxyConfig.setReadProxyIPFromLocal(isReadProxyIPFromLocal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,12 @@ public class TcpClientExample {
*/
public static void main(String[] args) throws InterruptedException {

String inlongGroupId = "test_test";
String inlongStreamId = "test_test";

/*
* 1. if isLocalVisit is true, will get dataproxy server info from local file in
* ${configBasePath}/${inlongGroupId}.local file
*
* for example: /data/inlong/config/test_test.local and file context like this:
* {"isInterVisit":1,"clusterId":"1","size":1,"switch":1,"address":[{"host":"127.0.0.1",
* "port":"46802"},{"host":"127.0.0.1","port":"46802"}]} 2. if isLocalVisit is false, will get dataproxy server
* info from manager so we must ensure that the manager server url is configured correctly!
*/
String configBasePath = "/data/inlong/config";
String inlongGroupId = "test_group_id";
String inlongStreamId = "test_stream_id";

String configBasePath = "";
String inLongManagerAddr = "127.0.0.1";
String inLongManagerPort = "8000";
String inLongManagerPort = "8083";

/*
* It is recommended to use type 7. For others, please refer to the official related documents
Expand All @@ -66,19 +56,20 @@ public static void main(String[] args) throws InterruptedException {
TcpClientExample tcpClientExample = new TcpClientExample();
DefaultMessageSender sender = tcpClientExample
.getMessageSender(localIP, inLongManagerAddr, inLongManagerPort,
inlongGroupId, false, false, configBasePath, msgType);
inlongGroupId, true, false, configBasePath, msgType);
tcpClientExample.sendTcpMessage(sender, inlongGroupId, inlongStreamId,
messageBody, System.currentTimeMillis());
sender.close(); // close the sender
}

public DefaultMessageSender getMessageSender(String localIP, String inLongManagerAddr, String inLongManagerPort,
String inlongGroupId, boolean isLocalVisit, boolean isReadProxyIPFromLocal,
String inlongGroupId, boolean requestByHttp, boolean isReadProxyIPFromLocal,
String configBasePath, int msgType) {
ProxyClientConfig dataProxyConfig = null;
DefaultMessageSender messageSender = null;
try {
dataProxyConfig = new ProxyClientConfig(localIP, isLocalVisit, inLongManagerAddr,
Integer.valueOf(inLongManagerPort), inlongGroupId, "test", "123456");
dataProxyConfig = new ProxyClientConfig(localIP, requestByHttp, inLongManagerAddr,
Integer.valueOf(inLongManagerPort), inlongGroupId, "admin", "inlong");
if (StringUtils.isNotEmpty(configBasePath)) {
dataProxyConfig.setConfStoreBasePath(configBasePath);
}
Expand All @@ -98,9 +89,11 @@ public void sendTcpMessage(DefaultMessageSender sender, String inlongGroupId,
try {
result = sender.sendMessage(messageBody.getBytes("utf8"), inlongGroupId, inlongStreamId,
0, String.valueOf(dt), 20, TimeUnit.SECONDS);

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println("messageSender" + result);
logger.info("messageSender {}", result);
}

Expand Down

0 comments on commit 9d97dcb

Please sign in to comment.