-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-10532][SDK] Add dataproxy python SDK sample and the correspon…
…ding document (#10546) Co-authored-by: jameswyli <[email protected]>
- Loading branch information
Showing
3 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/demo/config_example.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"init-param": { | ||
"inlong_group_ids": "test_pulsar_group", | ||
"manager_url": "http://127.0.0.1:8083/inlong/manager/openapi/dataproxy/getIpList", | ||
"manager_update_interval": 2, | ||
"manager_url_timeout": 5, | ||
"msg_type": 7, | ||
"max_proxy_num": 8, | ||
"per_groupid_thread_nums": 1, | ||
"dispatch_interval_zip": 8, | ||
"dispatch_interval_send": 10, | ||
"recv_buf_size": 10240000, | ||
"send_buf_size": 10240000, | ||
"enable_pack": true, | ||
"pack_size": 409600, | ||
"pack_timeout": 3000, | ||
"ext_pack_size": 409600, | ||
"enable_zip": true, | ||
"min_zip_len": 512, | ||
"tcp_detection_interval": 60000, | ||
"tcp_idle_time": 600000, | ||
"log_num": 10, | ||
"log_size": 104857600, | ||
"log_level": 3, | ||
"log_path": "./", | ||
"need_auth": false, | ||
"auth_id": "", | ||
"auth_key": "" | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-python/demo/send_demo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
import sys | ||
|
||
import inlong_dataproxy | ||
|
||
# user defined callback function | ||
def callback_func(inlong_group_id, inlong_stream_id, msg, msg_len, report_time, ip): | ||
print("******this is call back, print info******") | ||
print("inlong_group_id:", inlong_group_id, ", inlong_stream_id:", inlong_stream_id) | ||
print("msg_len:", msg_len, ", msg content:", msg) | ||
print("report_time:", report_time, ", client ip:", ip) | ||
print("******call back end******") | ||
return 0 | ||
|
||
def main(): | ||
if len(sys.argv) < 2: | ||
print("USAGE: python send_demo.py config_example.json [inlong_group_id] [inlong_stream_id]") | ||
return | ||
|
||
inlong_api = inlong_dataproxy.InLongApi() | ||
|
||
# step1. init api | ||
init_status = inlong_api.init_api(sys.argv[1]) | ||
if init_status: | ||
print("init error, error code is: " + init_status) | ||
return | ||
|
||
print("---->start sdk successfully") | ||
|
||
count = 5 | ||
inlong_group_id = "test_pulsar_group" | ||
inlong_stream_id = "test_pulsar_stream" | ||
|
||
if (len(sys.argv) == 4): | ||
inlong_group_id = sys.argv[2] | ||
inlong_stream_id = sys.argv[3] | ||
|
||
print("inlong_group_id:", inlong_group_id, ", inlong_stream_id:", inlong_stream_id) | ||
|
||
msg = "python sdk|1234" | ||
|
||
# step2. send message | ||
print("---->start tc_api_send") | ||
for i in range(count): | ||
send_status = inlong_api.send(inlong_group_id, inlong_stream_id, msg, len(msg), callback_func) | ||
if send_status: | ||
print("tc_api_send error, error code is: " + send_status) | ||
|
||
# step3. close api | ||
close_status = inlong_api.close_api(10000) | ||
if close_status: | ||
print("close sdk error, error code is: " + close_status) | ||
else: | ||
print("---->close sdk successfully") | ||
|
||
if __name__ == "__main__": | ||
main() |