Closed notedit closed 8 years ago
Use Redis events - or something else - and rely the events through the Broker process.
I am not a python expert, but this should work.
Just remember, this is pseudo-code. o.o
script.py
import redis
redisCon = redis.connect()
channel = redisCon.subscribe("SCBridge")
channel.publish({ "toChannel": "foo", "data": "My Message" })
broker.js
module.exports.run = function(broker) {
var redis = require("redis");
var conn = redis.createClient();
conn.on("message", function(channel, data){
if(channel == "SCBridge") {
// Assuming that the sent data is JSON
try {
var o = JSON.parse(data);
broker.publish(o.toChannel, o.data);
} catch(e) {
// Nope, not a JSON.
console.error("Data has been sent to SCBridge that is no JSON.");
console.error(data);
}
}
});
}
I did not see a way to do actual eventing... But I bet you could utilize a Worker for this. Although it is not entirely their task, you could theoretically create a similar setup like above, except that instead of using broker.publish
, you'd use something like worker.scServer.global.emit(evName, evData)
...
Docs: Broker http://socketcluster.io/#!/docs/api-broker SCSocket on Worker http://socketcluster.io/#!/docs/api-scsocket-server
can socketcluster communicate with other language process(like python)?