|
Hi Pulsar Community! I hope you're doing well. 😊 Any help or pointers would be greatly appreciated. Thank you! |
Answered by
lhotari
Oct 30, 2024
Replies: 1 comment
|
Here's an example of using the REST API: this is the way curl can be used to create functions from a jar/nar file: cat >/tmp/functionconfig.json <<EOF
{
"tenant": "public",
"namespace": "default",
"name": "myfunction",
"className": "MyFunction",
"runtime": "JAVA",
"inputs": [
"public/default/input-topic"
],
"output": "public/default/output-topic",
"autoAck": true,
"parallelism": 1
}
EOF
curl -H "Authorization: Bearer $(cat token)" -v -X POST \
-F "functionConfig=@/tmp/functionconfig.json;type=application/json" \
-F "data=@function.jar;type=application/octet-stream" \
http://pulsar-function-worker:6750/admin/v3/functions/public/default/myfunctionYou can adapt that to Python with ChatGPT or Claude. import json
import requests
import os
def deploy_pulsar_function(token_path, function_jar_path):
# Create function config
function_config = {
"tenant": "public",
"namespace": "default",
"name": "myfunction",
"className": "MyFunction",
"runtime": "JAVA",
"inputs": ["public/default/input-topic"],
"output": "public/default/output-topic",
"autoAck": True,
"parallelism": 1
}
# Save config to temp file
config_path = "/tmp/functionconfig.json"
with open(config_path, "w") as f:
json.dump(function_config, f)
# Read token
with open(token_path) as f:
token = f.read().strip()
# Prepare request
headers = {"Authorization": f"Bearer {token}"}
files = {
"functionConfig": ("functionconfig.json", open(config_path, "rb"), "application/json"),
"data": ("function.jar", open(function_jar_path, "rb"), "application/octet-stream")
}
# Make request
url = "http://pulsar-function-worker:6750/admin/v3/functions/public/default/myfunction"
response = requests.post(url, headers=headers, files=files)
# Cleanup
os.remove(config_path)
return response.status_code, response.text
if __name__ == "__main__":
status, text = deploy_pulsar_function("token", "function.jar")
print(f"Status: {status}")
print(f"Response: {text}") |
0 replies
Answer selected by
lhotari
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an example of using the REST API:
#22266 (comment)
this is the way curl can be used to create functions from a jar/nar file: