I have a node process which is currently receiving POST requests at https://company/api/bats_hook/, I want to notify a python process whenever a job comes in, am using node_redis and redis-py, the implementation looks like below.
Following code works great locally when the node process is running locally ,when i push the node endpoint to a server ,I dont seem to get the events?how do I subscribe to the endpoint on the server from python client?what is missing?I do have the redis server deployed on the server
https://company/api/bats_hook/
// javascript
var redis = require("redis"),
//redisClient = redis.createClient();
redisClient = redis.createClient({url: process.env.REDIS_URL});
app.post("/api/bats_holder", (req, res, next) => {
console.log(req.query.params)
console.log(req.body)
console.log(req.body.name)
// This publishes a message to the "bats hook channel"
redisClient.publish("bats hook channel", JSON.stringify({
params: req.query.params,
body: req.body,
}));
res.status(200).json({
message: "BATS object",
posts: req.body
});
});
python
import redis
r = redis.Redis()
p = r.pubsub()
p.subscribe('bats hook channel')
# This blocks and reads any messages from the "bats hook channel" as they come in
for message in p.listen():
print(message)
from How to notify a python client from node server?
No comments:
Post a Comment