DDP Publications

I have managed to get 2 apps connect via DDP, but I am a little unsure on how to publish data from the origin server.

Here is what I am trying on the client:

Template.Dashboard.onCreated(function(){
  Meteor.remoteConnection = DDP.connect('http://localhost:3030');
  this.subscribe('templatePublication', {connection:Meteor.remoteConnection});
});

That is supposedly calling a publication on the origin server. It is not throwing any errors, but at the same time it is not producing any documents, which it should as the publication is a simple Collection.find({});

Just curious if there is something I am missing…

1 Like

Check out the documentation for DDP.connect. Long story short it returns an object which has subscribe method which you can use to subscribe to remote publication. So in your case you can write your code as follows:

Template.Dashboard.onCreated(function(){
  Meteor.remoteConnection = DDP.connect('http://localhost:3030');
  Meteor.remoteConnection.subscribe('templatePublication');
});

However it’s better to assign remote connection to a new variable, not Meteor.remoteConnection.

1 Like

For me at least this approach still didnt seem to want to work; however, I did find a solution that worked for me:

import { DDP } from 'meteor/ddp-client'

var remote = DDP.connect('http://localhost:3030/');
Templates = new Meteor.Collection('templates', remote);

Template.Dashboard.onCreated(function(){ 
  remote.subscribe('templatePublication');
});

Template.Dashboard.helpers({
  listTemplates: ()=>{
    return Templates.find();
  }
});
1 Like