Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Commit f5e1fcb

Browse files
Merge pull request #750 from meteor/feature/publication-strategies
Document publication strategies for 2.4
2 parents 7d83991 + 578e487 commit f5e1fcb

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

code

Submodule code updated 78 files

source/api/pubsub.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,52 @@ messages. When you change rooms by calling `Session.set('currentRoom',
262262
'newRoom')`, Meteor will subscribe to the new room's chat messages,
263263
unsubscribe from the original room's chat messages, and continue to
264264
stay subscribed to your private messages.
265+
266+
## Publication strategies
267+
268+
> The following features are available from Meteor 2.4 or `ddp-server@2.5.0`
269+
270+
Once you start scaling your application you might want to have more control on how the data from publications is being handled on the client.
271+
There are three publications strategies:
272+
273+
#### SERVER_MERGE
274+
`SERVER_MERGE` is the default strategy. When using this strategy, the server maintains a copy of all data a connection is subscribed to.
275+
This allows us to only send deltas over multiple publications.
276+
277+
#### NO_MERGE_NO_HISTORY
278+
The `NO_MERGE_NO_HISTORY` strategy results in the server sending all publication data directly to the client.
279+
It does not remember what it has previously sent to client and will not trigger removed messages when a subscription is stopped.
280+
This should only be chosen for special use cases like send-and-forget queues.
281+
282+
#### NO_MERGE
283+
`NO_MERGE` is similar to `NO_MERGE_NO_HISTORY` but the server will remember the IDs it has
284+
sent to the client so it can remove them when a subscription is stopped.
285+
This strategy can be used when a collection is only used in a single publication.
286+
287+
When `NO_MERGE` is selected the client will be handling gracefully duplicate events without throwing an exception.
288+
Specifically:
289+
290+
* When we receive an added message for a document that is already present in the client's collection, it will be changed.
291+
* When we receive a change message for a document that is not in the client's collection, it will be added.
292+
* When we receive a removed message for a document that is not in the client's collection, nothing will happen.
293+
294+
You can import the publication strategies from `DDPServer`.
295+
296+
```js
297+
import { DDPServer } from 'meteor/ddp-server'
298+
299+
const { SERVER_MERGE, NO_MERGE_NO_HISTORY, NO_MERGE } = DDPServer.publicationStrategies
300+
```
301+
302+
You can use the following methods to set or get the publication strategy for publications:
303+
304+
{% apibox "setPublicationStrategy" %}
305+
306+
For publication `foo`, you can set `NO_MERGE` strategy as shown:
307+
308+
```js
309+
import { DDPServer } from "meteor/ddp-server";
310+
Meteor.server.setPublicationStrategy('foo', DDPServer.publicationStrategies.NO_MERGE);
311+
```
312+
313+
{% apibox "getPublicationStrategy" %}

0 commit comments

Comments
 (0)