Coder Social home page Coder Social logo

Comments (8)

boazsegev avatar boazsegev commented on May 22, 2024

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.

lucaskuan avatar lucaskuan commented on May 22, 2024

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.

boazsegev avatar boazsegev commented on May 22, 2024

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.

lucaskuan avatar lucaskuan commented on May 22, 2024

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.

boazsegev avatar boazsegev commented on May 22, 2024

It should work out of the box.

Please update to iodine 0.4.19 and try again.

from plezi.

boazsegev avatar boazsegev commented on May 22, 2024

@lucaskuan

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.

lucaskuan avatar lucaskuan commented on May 22, 2024

Since I'm not ready to do upgrade and testing. Close this issue first and try later

from plezi.

boazsegev avatar boazsegev commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.