YouJiacheng edited a comment on issue #12905:
URL: https://github.com/apache/pulsar/issues/12905#issuecomment-977550822


   @nlu90
   1. However, get state API just use JSON not a stream, if developers want to 
extend to big object, they need to rewrite get state API.
   MOST IMPORTANT: ALL pulsar REST API using multipart/form-data DOES NOT 
provide ANY reference about request body! While other REST API using JSON DOES! 
For example: 
https://pulsar.apache.org/functions-rest-api/?version=2.8.1#operation/putFunctionState
 vs 
https://pulsar.apache.org/functions-rest-api/?version=2.8.1#operation/registerFunction
   
   2.  I want to know how to put function state directly using HTTP request in 
my application, not using pulsar-admin CLI.
   After check 
https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/FunctionsBase.java#L535
 , I guess the request body should be a multipart/form-data with a field with 
key 'state' and JSON string value '{"key": "kk", "stringValue": "hello"}'. Thus 
I write following code, but it does not work.
   ```
   import aiohttp
   async def put_state():
       async with aiohttp.ClientSession() as session:
           data = aiohttp.FormData(
               {'state': '{"key": "kk", "stringValue": "Hello"}'}
           )
           async with session.post('..../tn/ns/func/state/kk', data=data) as 
resp:
               print(resp.status)
   ```
   or may be it is aiohttp.FormData's problem.
   
   Now I use a workaround: add a state topic into pulsar function's input 
topic, and use `context.putstate` in pulsar function. This workaround is 
convenient and more powerful than REST API (easy to cache state), but I still 
want to know how to use REST API.
   But this workaround has a problem: when I work with parallelism > 1, how to 
make all replica be noticed?


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to