Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing a service from angular controller not working #107

Open
ghost opened this issue Dec 14, 2015 · 0 comments
Open

Accessing a service from angular controller not working #107

ghost opened this issue Dec 14, 2015 · 0 comments

Comments

@ghost
Copy link

ghost commented Dec 14, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants