-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
broadcasting through omega-supreme only works on the same process #6
Comments
@siddo420 I wrote a very simple test case some time ago: https://gist.github.com/lpinca/dac8f2efca54518555a4 Can you try to run that and see if it works for you? It does not use |
I took the essence of your test case (rest is you creating clients that I do manually) and used it but same error. I wonder if I need to have a PUT route configured in express for omega-supreme (dont see that in omega's docs though).
Perhaps, omega examples are incorrect ... trying more now. |
In that example I didn't use the convenience method that is added by metroplex, but you can do this: primus.forward.broadcast(data, function (err, result) {
if (err) throw err;
console.log(result);
}); You don't need a route in express because primus requests are handled and answered by primus. |
thats exactly what I used before (see my first comment above). Any chance you could add a new function to return all spark IDs linked to a given server address? It shouldn't be too hard for you I guess. Redis 'smembers' call on
|
looks like something is wrong with omega-supreme because I used the following code this time (smembers included) to send messages to sparks. primus.metroplex.servers( function( err, servers ){
logger.info( 'registered servers:', servers );
for( var i=0; i < servers.length; i++ ){
redis.smembers( primusOptions.namespace + ":" + servers[i] + ":sparks", function( err, sparks ){
logger.debug( "Returning Redis members: " + JSON.stringify(sparks) + JSON.stringify(err) );
primus.forward( servers[i], { msg: data.message }, sparks, function (err, result) {
logger.debug( "In message send: " + JSON.stringify(err) + JSON.stringify(result) );
});
});
}
}); This should forward message to all sparks in all other hosts (except local).. however it instead returns:
Any ideas what might be wrong with omega-primus here? |
@siddo420 try to create a super simple test case to reproduce the issue, like the one I posted above, otherwise is too hard to debug.
Yes this can be done, and as you said it's not hard, mind to create a pull request for this? |
it is simple i think, scenario is a bit complicated so test case has to be a bit complicated as well. Dont know how to create a pull request. However, here is the function you need to get sparks from a server.
|
The code from your previous comment is wrong: primus.metroplex.servers( function( err, servers ){
logger.info( 'registered servers:', servers );
for( var i=0; i < servers.length; i++ ){
redis.smembers( primusOptions.namespace + ":" + servers[i] + ":sparks", function( err, sparks ){
logger.debug( "Returning Redis members: " + JSON.stringify(sparks) + JSON.stringify(err) );
primus.forward( servers[i], { msg: data.message }, sparks, function (err, result) {
logger.debug( "In message send: " + JSON.stringify(err) + JSON.stringify(result) );
});
});
}
});
primus.metroplex.servers(function (err, servers){
logger.info('registered servers:', servers);
servers.forEach(function (server) {
redis.smembers(primusOptions.namespace + ":" + server + ":sparks", function (err, sparks) {
logger.debug("Returning Redis members: " + JSON.stringify(sparks) + JSON.stringify(err));
primus.forward(server, { msg: data.message }, sparks, function (err, result) {
logger.debug("In message send: " + JSON.stringify(err) + JSON.stringify(result));
});
});
});
}); |
Yes, I had figured that out already and corrected it but that did not resolve the issue either. I also wrote a very simple test case but still I only see messages on the clients connected to same node process only (and not the other host+process in cluster). "mp" is the namespace I used. redis.hkeys( "mp:sparks", function( err, sparks ){
primus.forward( "http://192.168.1.9:3000", { msg: data.message }, sparks, function (err, result) {
});
primus.forward( "http://192.168.1.9:3001", { msg: data.message }, sparks, function (err, result) {
});
}); redis returns all sparks on all hosts and I manually used the two server addresses in primus.forward call. Keep getting the following messages:
|
The problem is that for some reasons, unknown to me, the request fails. Try to send the message like this:
|
it turns out that my custom authorization module was blocking the PUT requests, its been fixed now. Thanks for working with me on this issue. |
@lpinca in regards to the feature request, it seems sane and useful to me. |
Ok, given that thre is already a method called |
That is an excellent question. I have no idea. We also already have a servers to get a list of servers. So most sane API names are already taken here. Maybe just a simple On Thursday, July 9, 2015 at 7:59 AM, Luigi Pinca wrote:
|
I was thinking about something like this to get the servers: primus.metroplex.servers([self], [sparks], fn); Where Another option is to check the type of first argument of the primus.metroplex.sparks(/*array of spark ids | server string*/, fn) The first option is a big breaking change but I don't think that it is a problem, unless we revert the The problem is that I like none of the above solutions 😕. |
this could possibly be a documentation bug or perhaps am doing something wrong.
through my tests, it was revealed that the broadcast messages are only sent to clients connected to the same node process and not to the "cluster" as is mentioned in the documentation.
Here is whats written: "Broadcast a message to all sparks in the cluster."
I tested by using two node processes behind HAProxy. I fired up two browser sessions and made sure clients were connected to separate node processes. I sent messages and only received them back on the sender but the other client that was connected to the other node process did not receive anything.
I killed one of the node processes and forced the client connected to it to use the other node process (behind HAProxy). This time I could see that messages were received on both clients (because both were connected to the same process now).
The code I used to broadcast message is:
The debug line returned (after a few minutes of sending message).
Its the same error object that is returned no matter if the messages were delivered or not.
The text was updated successfully, but these errors were encountered: