Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff between meteor method and meteor pub/sub

Tags:

meteor

I working with meteor to create an app. In meteor Meteor.methods and Meteor.publish are used to perform database operation.I know use of Meteor methods and pub/sub

My question is there any criteria when to use Meteor.methods and when Meteor.publish?.

like image 915
I am Avatar asked Nov 24 '15 06:11

I am


2 Answers

Meteor.publish is the pub part of pub-sub obviously. As data gets added or changed that is being published the server will automatically send it over to any client that has subscribed to that publication.

Meteor.call is request-response. You make a request, you get a response. Party's over. If data changes on the server that the method uses your client won't know about it until you make another call.

like image 117
Michel Floyd Avatar answered Nov 13 '22 22:11

Michel Floyd


Meteor Publish Subscribe is a way to allow access (read and write) to clients, and to keep all clients and server updated with the latest data. Meteor Publish/Subscribe has only to do with meteor database.

Meteor methods is much more, it can be used for various uses, such as making calls to API's (HTTP calls to your REST API's), etc. (P.S. It is recommended to make these calls from server side for security reasons).

Also, when fetching data by calling Meteor Method (using Meteor.call), you can do some kind of verification or validation on server side before fetching or returning the data.

And yes, Michel Floyd's answer is another great point.

like image 3
Piyush Mahensaria Avatar answered Nov 13 '22 21:11

Piyush Mahensaria