Skip to content

Accessing a service from angular controller not working #107

Open
@ghost

Description

I have an UI app on port 8001 and an app named contract on port 7001. I have 'cluster' installed and working. I have a subscription and insert method defined in 'contract' app.

'contract' server/app.js

Cluster.connect("mongodb://<username>:<passwd>@URL");
var options = {
    endpoint: "http://localhost:7001",
    balancer: "http://localhost:7001", // optional
    uiService: "web" // (optional) read to the end for more info
};
Cluster.register("contracts", options);

var Contracts = new Meteor.Collection('contracts');

Meteor.methods({
    addContract: addContract,
    findContracts: findContracts
});

Meteor.publish("getContracts", function () {
    return Contracts.find({});
});

function addContract(c){
    var data = {
        id: c.id,
        type: c.type
    };
    Contracts.insert(data);
}

function findContracts(){
    var contracts = Contracts.find().fetch();
    return contracts;
}

I am accessing the methods from an angular controller in my UI app.

UI app server/app.js

Cluster.connect(mongodb://<username>:<passwd>@URL");
var options = {
    endpoint: "http://localhost:8001",
    balancer: "http://localhost:8001" // optional
    //uiService: "web" // (optional) read to the end for more info
};
Cluster.register("web", options);
Cluster.allowPublicAccess("contracts");

UI app controller code

var contractConn = Cluster.discoverConnection('contracts');
            contractConn.subscribe('getContracts');
            var SubscribedContracts = new Mongo.Collection('SubscribedContracts', {connection: contractConn});
            console.log('status', contractConn.status());
            vm.contracts = SubscribedContracts.find({}).count();
            contractConn.call("findContracts", function(err, result) {
                if(err) {
                    throw err ;
                }
                else {
                    console.log(result);
                }
            });

This is what is happening:

  • I can access methods on the contract server
  • I can insert or find contracts using these methods
  • My subscription is not working. fetch on the cursor shows 0 and count shows 0
  • Status on the connection shows 'connecting'

What am I doing wrong with my subscription?

Sudi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions