-
Hi, This looks like exactly what I need, I just can't figure out how to make it work! I am new to python so please bear with me and I apologize in advance for stupid questions that I probably should know that answer to. Question 1: Question2: async def runquery(sqlquery):
await endpoint.publish(["query"], data=sqlquery) #this works fine
await asyncio.sleep(1)
endpoint.subscribe(["query"], callback=get_result) #this does not work???
return
async def get_result(data, topic):
print(data)
return data Question 3: async def on_connect(channel): #The channel comes from the on_connect call
# now tell the client it can start sending us queries
asyncio.create_task(channel.other.allow_queries())`
#BUT If I want to create a function like this:
class GetQueryData(RpcMethodsBase):
async def getdata(sqlquery):
result = asyncio.create_task(**DONT_KNOW_WHAT_GOES_HERE**.other.run_query_method(sqlquery))
return result
#ON THE CLIENT SIDE I HAVE CREATED
`
class WaitingClient(RpcMethodsBase):
async def run_query_method(self, sqlquery):
queryresponse = await read_all(sqlquery)
return queryresponse Question 4: Any help would be greatly appreciated and again sorry if I am asking silly questions. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi, Sorry for the delayed response.
RPC is 1x1, and Pub/Sub is meant as many-to-many. So Pub/Sub is the more natural option here.
Take a look at this example/test: https://github.com/permitio/fastapi_websocket_pubsub/blob/master/tests/server_subscriber_test.py 1 - It seems like you're trying to listen to your own event from the same PubSub client/server - the Notifier filters out the messages it sends from itself. You should run a seperate client to subscribe and receive the published event.
In your method signature you forgot
You can use the Ids generated by the RPC layer- but note this will reset for every time a client restarts. Hope these answers help :) |
Beta Was this translation helpful? Give feedback.
-
Hi, Thank you very much for taking the time to reply. Question 1/4: That's is what i thought, just wanted to be sure PUB/SUB it is. I will generate a CLIENT_ID and use that to listen on unique topics thus also solving question 4. Not sure quite how yet but I will figure something out. Question 2: Dope, that was so obvious... I was missing endpoint.subscribe([TOPIC_FOR_CLIENT_REPLY], event_callback), I had tried to endpoint.subscribe to the original topic that I had endpoint.publish(ed) to but that did not work, it has to be a different topic name. Problem solved! I had looked at your example and that test but I did not see it for some reason. Question 3 Yes of course... don't need it now (going with PUB/SUB) |
Beta Was this translation helpful? Give feedback.
Hi, Sorry for the delayed response.
And happy this might be a good fit for you :) (Does sound like it ;-) )
RPC is 1x1, and Pub/Sub is meant as many-to-many. So Pub/Sub is the more natural option here.