Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between PubSub and Methods

What is the difference between PubSub and Methods in Meteor?!

Can I put Methods in Server folder like Publishs?

To me seen like the same, but Methods is more reactive.

like image 798
Jroger Avatar asked Jul 23 '15 13:07

Jroger


People also ask

When should you not use Pubsub?

Synchronous point-to-point communication between the two endpoints is the best solution for media streaming. Pub/Sub is not suitable for carrying VoIP or video telephony traffic over the Internet.

What is Pubsub used for?

Pub/Sub allows services to communicate asynchronously, with latencies on the order of 100 milliseconds. Pub/Sub is used for streaming analytics and data integration pipelines to ingest and distribute data.

What is the difference between Pub/Sub and message queue?

In a message-queue model, the publisher pushes messages to a queue where each subscriber can listen to a particular queue. In the event-stream model using Pub/Sub, the publisher pushes messages to a topic that multiple subscribers can listen to.

What is difference between Pubsub and Kafka?

For authorization, Kafka supports using access control lists (ACLs) to determine which producers and consumers have access to which topics. Pub/Sub supports authentication for Google Cloud user accounts and service accounts.


2 Answers

They are two different sides of the same coin. Here's a drawing of the data lifecycle in meteor:

Meteor Data Lifecycle

  • Publish - Which data is sent from the server
  • Subscribe - Which data the client requests publications for
  • Methods - How to manipulate data from the client on the server
    • Note - this will typically be run on both on the client and the server. The client will make a prediction as to what the server will do so it can update right away. Then latency compensation will kick in when the method is run on the server and the canonical decision is made.
like image 108
KyleMit Avatar answered Sep 19 '22 18:09

KyleMit


What is the difference between PubSub and Methods in Meteor?!

Publications are reactive and they provide a cursor. Subscription gets you the matching publication on clientside in a minimongo database. On the other hand, methods must be called instead of subscribed and they are mainly designed to execute server side tasks that you don't want to handle client side for many possible reasons.

More details here for publications: https://www.discovermeteor.com/blog/understanding-meteor-publications-and-subscriptions/

And here for methods: http://meteortips.com/first-meteor-tutorial/methods/

Can I put Methods in Server folder like Publishs?

Yes you can and you should. For example, put them into server\methods

To me seen like the same, but Methods is more reactive.

This is the exact contrary. They are not the same, even if you can achieve similar results with both. Methods are by design not reactive, and pub/sub are.

like image 42
Billybobbonnet Avatar answered Sep 20 '22 18:09

Billybobbonnet