Comments (8)
Hi @lucaskuan ,
Thank you for opening this issue.
I understand your need to send a message to a specific connection and I recommend that you switch to the pub/sub API for this need (the API was updated in iodine 0.6.0, but Plezi still uses iodine 0.4.19 until I release the update I'm working on).
The issue is simple (and the confusion is one of the reasons that each
was deprecated in iodine 0.5.0): the each
method is process bound (it can't search across process boundaries). I should have been clearer about this in the documentation, as I probably mention this in the wrong place.
When you use iodine -w 2
you are entering cluster mode. In this mode there is more than a single process and each
will only access the connections that share the same process.
However, pub/sub is cluster wide and can be easily extended using Redis to support multi-machine horizontal scaling (which allows your messages to cross machine boundaries).
If you give each user a private channel (i.e., subscribe channel: "User.#{@user.id}"
), than you could use the pub/sub system to send messages directly to the user's WebSocket or Controller (by adding a block to the subscribe
method).
I hope tis helps.
Good Luck!
from plezi.
Thanks for your instant reply! 🥇
Is that means I could follow the redis setup here https://github.com/boazsegev/iodine/tree/v0.4.15#native-pubsub-with-optional-redis-scaling
and subscribe the user to a channel when he first connected at on_open
. So that when I need to send message to this specific user, I could use Iodine.publish 'channel', 'message'
. Right?
from plezi.
Thanks for your instant reply! 🥇
It was mostly luck... but you're welcome :-)
I could follow the redis setup here...
Yes, this is a good option if you are running multiple instances of your application (i.e., running the application on multiple machines or, on Heroku, using multiple dynos).
With Plezi, this can be automated by setting the PL_REDIS_URL
environment variable.
Also, please note: if you are running a single process cluster (one call to iodine -w 3
), you don't need Redis and you can use iodine's internal pub/sub (it includes inter-process-communication).
In fact, if your running only a single application instance (i.e., one iodine cluster), Redis will only slow the application down.
from plezi.
I'm playing around with the publish and found out the publish won't work without PL_REDIS_URL
. Is the internal pub/sub work out of the box or some configuration is needed?
I'm on plezi 0.5.0
iodine 0.4.14
.
from plezi.
It should work out of the box.
Please update to iodine 0.4.19 and try again.
from plezi.
Please let me know if you still have an issue after upgrading to iodine 0.4.19 (also, please consider upgrading to Plezi 0.5.1).
Thank you for opening this issue.
B.
from plezi.
Since I'm not ready to do upgrade and testing. Close this issue first and try later
from plezi.
Okay, thank you :-)
P.S.
Please note that iodine 0.4.19 should be 100% compatible with iodine 0.4.15, the patch version updates only include bug fixes.
It should be easy to upgrade to iodine 0.4.19 and Plezi 0.15.1 (no code changes).
Plezi 0.16.0 and Iodine 0.6.2 are the latest versions and have some significant changes to the API (mostly due to collaborations in an attempt to create a Rack standard API for WebSocket connections and pub/sub).
from plezi.
Related Issues (20)
- ERROR -- : uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable (NameError) HOT 10
- ERROR -- : incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError) HOT 11
- Documentation help needed. HOT 2
- WebSocket connection to 'ws://localhost:3000/ws' failed: Error during WebSocket handshake: Unexpected response code: 200 HOT 21
- JSON event length is limited HOT 10
- Server configs HOT 4
- download error with bundled client.js HOT 1
- rabbitmq HOT 1
- SyntaxError in generated config.ru
- Rack < 2.0 : cannot load such file -- rack/query_parser.rb HOT 1
- message_size_limit uninitialized constant Iodine::Http HOT 10
- create function is not synchronized HOT 19
- server shutdown when one or more client has a poor connection HOT 7
- Upgrade to bundler 2.0 HOT 3
- Help needed! HOT 1
- Failing at higher concurrency HOT 2
- Gap in documentation for serving static assets HOT 3
- Architectural clarification HOT 2
- There is no way to unsubscribe from Plezi::Controller.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plezi.