this is probably not a bug but rather a gap in my understanding but putting it here as afraid havent been able to find a way so far. Appreciate if you can provide your inputs please.
I'm trying to connect to my Riak cluster (hosted on AWS) of 3 nodes via two options - 1) Using an ejabberd server, and 2) using a Node server.
Connecting from the ejabberd server is successful after I put the hostname and port in the ejabberd configuration, but when I use a simple Node server (code below), I get the "Error: No RiakNodes available to execute command." error. Am I missing out on something here please - I can confirm that the 3 nodes are indeed up with Riak running? Note that if I dont do the client ping on the nodes, the server doesnt throw any error, so it is probably got to do with how pings are handled. The same server (without the ping) gives an ECONNREFUSED error if one of the nodes are brought down. So clearly the connection is going through but not the ping.
Apologize if am missing out on something basic here ... even the firewall settings for the Riak nodes have been set to all inbound, so it is not a case of the ejabberd server having access but not the Node server.
var async = require('async');
var assert = require('assert');
var logger = require('winston');
var Riak = require('basho-riak-client');
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
level : 'debug',
colorize : true,
timestamp : true
});
var nodes = [
'ip-xx-xx-xx-xx:8087',
'ip-xx-xx-xx-xx:8087',
'ip-xx-xx-xx-xx:8087'
];
var client = new Riak.Client(nodes, function (err, c) {
logger.info('Now inside Riak.Client');
// NB: at this point the client is fully initialized, and
// 'client' and 'c' are the same object
});
client.ping(function (err, rslt) {
logger.info('Now entered client.ping');
if (err) {
logger.info('There is an error encountered in client.ping');
throw new Error(err);
} else {
// On success, ping returns true
logger.info('client.ping has resulted in success!');
assert(rslt === true);
}
});
Related
I am building a SOA with deepstream and I want to use a deepstream client server to perform API-KEY based look ups that the user should not know. How do I actually set up an RPC client provider? I have looked in the deepstream docs and on google, but there is not a full code example on how to do this. I have created a file like below and run it with node. The output I get is below it:
var deepstream = require('deepstream.io-client-js')
const client = deepstream('localhost:6020').login()
console.log('Starting up')
client.on('error', (error,event,topic) => {
console.log(error, event, topic);
})
client.on('connectionStateChanged', connectionState => {
console.log(connectionState);
})
client.login({username: 'USER', password: 'PASSWORD'}, (success, data) => {
if (success) {
client.rpc.provide('the-rpc', function( data, response ){
response.send(data);
});
} else {
console.log(data);
}
})
--
Starting up
AWAITING_CONNECTION
As you can see it runs the code, but does not actually connect to the deepstream server. I already have the deepstream server running, and a browser client that connects to it, so the config is correct. Please help!
I think your issue is based on the fact your trying to connect node via the webport. Try using port 6021 instead for tcp ( used by the node client ).
const client = deepstream('localhost:6021').login()
You should also only call .login() once, so the line would be:
const client = deepstream('localhost:6021')
We are working on a 2.0 release coming out very soon which will remove tcp entirely and only require a single port to make life easier in terms of deployment and performance.
I'm using Redis in my nodejs server, communicating with a browser html/js application. Under conditions I can't identify, my server gets stuck. It throws no errors, keep to be alive and responding, but can't get values from Redis. This is (the simplified version) how the connection with Redis is established.
var Stash = require('redis'),
Sockjs = require('sockjs')
stash = Stash.createClient(some_port,some_host);
sockjs = Sockjs.createServer();
var Instances = {
get: function (id, cb) {
stash.get('something_' + id, cb)
}
sockjs = Sockjs.createServer();
sockjs.on('connection', function(socket) {
socket.on('data', function(data) {
var id = somecorrectid;
Instances.get(id, function(err, instance) { /*Here the magic happens*/ }
}
}
Now, this works perfectly in normal conditions.
When the issue happens, the code between the last brackets isn't executed anymore, no matter how many times I fire again the event triggering the piece of code (that is a post data throught a socket) and from what client. Redis, in the meanwhile, is alive and rocking. Redis-cli is responding. The key searched with the 'get' exist and it is correct in its form. My server is still able to write keys to Redis correctly, but seems it can't read them anymore. This have no sense to me, and it is difficult to investigate or have more informations for I can't get how to replicate the issue. Any clue?
I have attached my code and error message on the below. Can you please help me, I could not find the reason to get the error.
Thanks,
// My Code
// Node-Firebird
var Firebird = require('node-firebird');
// Options
var options = {};
//options.host = '127.0.0.1';
//options.port = 3050;
options.database = 'mydb.FDB';
options.user = 'SYSDBA';
options.password = 'masterkey';
// Query
Firebird.attach(options, function(err, db) {
if (err)
throw err;
// db = DATABASE
db.query('SOME QUERY', function(err, result) {
// IMPORTANT: close the connection
db.detach();
});
});
// Error Message
/Users/bla/myfile.js:14 throw err; ^ Error: I/O
error during "open" operation for file "/Users/bla/mydb.FDB", Error
while trying to open file at doCallback
(/Users/bla/node_modules/node-firebird/lib/index.js:1233:18) at
/Users/bla/node_modules/node-firebird/lib/index.js:2897:21 at
/Users/bla/node_modules/node-firebird/lib/messages.js:151:25 at search
(/Users/bla/node_modules/node-firebird/lib/messages.js:117:13) at
/Users/bla/node_modules/node-firebird/lib/messages.js:54:21 at
FSReqWrap.wrapper as oncomplete
NOTE:
Actually, I can connect the same database with c++ based driver:
var fb = require("firebird");
var con = fb.createConnection();
con.connectSync('mydb.FDB', 'SYSDBA', 'masterkey', '');
var rs = con.querySync('SOME QUERY');
And when I am trying to connect via Flamerobin, it works perfectly as well. This is really weird error I guess. Any other suggestions, please?
I don't know the node-firebird driver, but given the behavior, one might be connecting locally (with the client library acting as a server), while the other connects through the server. This could potentially lead to the following problems:
Different path resolution as you are specifying a relative path (unless mydb.FDB is defined as an alias), possibly the file /Users/bla/mydb.FDB doesn't exist
Insufficient access rights, the path /Users/bla/mydb.FDB in the error suggests it is a database in a user folder which means that it is not accessible to the Firebird server process (which usually runs under the user firebird).
I have configured like below and my MongoDB don't need username or password:
mongo: {
module: 'sails-mongo',
url: "mongodb://127.0.0.1:27017/mydb",
replSet: {
servers: [
{
host: "127.0.0.1",
port : 27018
},
{
host: "127.0.0.1",
port : 27019
}
],
options: {connectWithNoPrimary:true, rs_name:"rs0"}
}
}
It's working fine, meaning I do not get a connection error and I am able to do querying. But when I brought down 127.0.0.1:27017, 127.0.0.1:27018 becomes PRIMARY as if I did a rs.status(). After this, I am no longer able to do any query and keep getting the following:
Error: no open connections
I am sure that I setup replica-set in my local machine correctly as I used MongoDB native driver to test the above mentioned scenario (bring down PRIMARY and SECONDARY take over as PRIMARY) and there is no problem.
var url = 'mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/mydb?w=0&wtimeoutMS=5000&replicaSet=sg1&readPreference=secondary';
mongodb.MongoClient.connect(url, function(err, result) {
if(err || result === undefined || result === null) {
throw err;
} else {
db = result;
}
});
ok I found the answer. This message emitted because of session.js. I commented everything in the file and now it is working. The reason I guess is in session.js, it only pointing to a single host, which is the original PRIMARY. when you bring down this mongodb PRIMARY, session.js no longer can connect so it threw exception. I also tried the mongodb URL string in sessions.js by putting in also the hosts ip in the replica set (mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/mydb) but failed to "sails lift". When put only single host then it is fine.
now if I need to store sessions info, I need to start another mongodb instance then session.js point to this new instant.
Hello I'm trying to get Node/Mongo service going on Openshift, here's what it looks like:
var db = new mongodb.Db('myServiceName',
new mongodb.Server('mongodb://$OPENSHIFT_MONGODB_DB_HOST','$OPENSHIFT_MONGODB_DB_PORT', {}));
db.open(function (err, db_p) {
if (err) { throw err; }
db.authenticate('$USER', '$PASS', function (err, replies) {
if (err) { throw err; }
// should be connected and authenticated.
// ...
The app was created using rhc:
$ rhc create-app myServiceName nodejs-0.10 mongodb-2.4
The console shows the app was started and is running, and on cURL the response is 503
My logs don't show an error, however, the dB is obviously not live. Can anyone help?
If your mongodb driver supports connection with username/password, then use OPENSHIFT_MONGODB_DB_URL instead of OPENSHIFT_MONGODB_DB_HOST
OPENSHIFT_MONGODB_DB_URL gives you this format:
mongodb://admin:password#127.4.99.1:27017/
and OPENSHIFT_MONGODB_DB_HOST gives you this format:
ip addres, ex: 127.4.99.1
So you can just use OPENSHIFT_MONGODB_DB_URL to connect and authenticate at the same time
with mongoskin, you can just do this:
var db = require('mongoskin').db(process.env.OPENSHIFT_MONGODB_DB_URL + 'dbname'+ '?auto_reconnect=true',
{safe: true, strict: false}
);
It looks like you are attempting to connect to a server named "$OPENSHIFT_MONGODB_DB_HOST", (not a valid URL).
Instead, you'll probably want to read the value of the OPENSHIFT_MONGODB_DB_HOST environment variable to find your connection information:
process.env.OPENSHIFT_MONGODB_DB_HOST
I have some additional notes up here: https://www.openshift.com/blogs/getting-started-with-mongodb-on-nodejs-on-openshift