Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I got it working after looking closely at some code and realizing I was totally over-thinking things. The protocol is actually pretty straight forward, RPC ish stuff. </p> <p>I'm happy to report that it absolutely worked around the server-side insert delay (manual Mongo inserts were taking several seconds to poll/update the clients). </p> <p>If you go through DDP, you get all the real-time(ish) goodness that you've come to know and love with Meteor :)</p> <p>For posterity and to hopefully help drive some other folks to interesting use cases, here's the setup. </p> <p><strong><em>Use Case</em></strong></p> <p>I am spooling some custom syslog data into a node.js daemon. This daemon then parses and inserts the data into Mongo. The idea was to come up with a real-timey browser based reporting project for my first Meteor experiment. </p> <p>All of it worked well, but because I was inserting into Mongo <strong>outside</strong> of Meteor proper, the clients had to <strong>poll</strong> every ~10 seconds. In another SO post <a href="https://stackoverflow.com/questions/14637302/meteor-server-side-db-insert-delays">@TimDog suggested</a> I look at DDP for this, and his suggestion looks to have worked perfectly. </p> <p>I've tested it on my system, and I can now instantly update all Meteor clients via a node.js async application.</p> <p><strong>Setup</strong> The basic idea here is to use the DDP "call" method. It takes a list of parameters. On the Meteor server side, you export a Meteor method to consume these and do your MongoDB inserts. It's actually really simple:</p> <p>Step 1: npm install ddp</p> <p>Step 2: Go to your Meteor server code and do something like this, inside of Meteor.methods:</p> <pre><code>Meteor.methods({ 'push': function(k,v) { // k,v will be passed in from the DDP client. console.log("got a push request") var d = {}; d[k] = parseInt(v); Counts.insert(d, function(err,result){ // Now, simply use your Collection object to insert. if(!err){ return result }else{ return(err) } }); } }); </code></pre> <p>Now all we need to do is call this remote method from our node.js server, using the client library. Here's an example call, which is essentially a direct copy from the example.js calls, tweaked a bit to hook our new 'push' method that we've just exported:</p> <pre><code>ddpclient.call('push', ['hits', '1111'], function(err, result) { console.log('called function, result: ' + result); }) </code></pre> <p>Running this code inserts via the Meteor server, which in turn instantly updates the clients that are connected to us :)</p> <p>I'm sure my code above isn't perfect, so please chime in with suggestions. I'm pretty new to this whole ecosystem, so there's a lot of opportunity to learn here. But I do hope that this helps save some folks a bit of time. Now, back to focusing on making my templates shine with all this real-time data :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload