Unable to get the messages from cloud AMQP queue - node.js

Hi i am trying to use rabbitmq in my sails app. when I try to post data in my model after giving the connections adapter I can see the data received in my rabbit queue but the database has not created.
I'm using mongo database for my models and sails-rabbitmq as my node_module
I referred this link
npm install sails-rabbitmq
The connection adapter is -
rabbitCluster: {
adapter: 'sails-rabbitmq',
//my amqp rabbitmq installation url
url: 'amqp://localhost',
},
MongoDB: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: '',
password: '',
database: 'myTest'
}
inside my model specified the connection as follow
connection : ['rabbitCluster','MongoDB']
//in my config/rabbitmq.js file
module.exports.rabbitmq = {
pkFormat: 'string'
};
as I understand we don't need to write create and update controller methods it should work with default CRUD operations provided by sails. but i get no response when i try to create a database entry.

Related

How to create a pool object in javascript that can connect to a database backend using SSL?

I followed a guide on how to create a Node JS backend on PostgreSQL and a ReactJS frontend, which is working well, see here for more.
The js pool object of the quide looks as follows:
const Pool = require('pg').Pool
const pool = new Pool({
user: 'my_user',
host: 'localhost',
database: 'my_database',
password: 'postgres',
port: 5432,
});
I tried doing the same with a PostgreSQL Webserver using SSL encryption. This question is not tagged postgresql since the pool looks the same for mysql and other databases. It is also not tagged Linux since it should work the same on other OS.
How to create a pool object from the Pool class in javascript that can connect to a PostgreSQL backend using SSL?
You need to save the certificate, call it server-certificate.pem, in a place with a static path starting with / (~ for your user's home directory does not work). Therefore, you need to move it to a static place.
I copied the file to a newly created directory certificates, but that is of course up to you. You will need super user rights for this.
/etc/certificates/server-certificate.pem
You need to load fs and use it in the SSL part, see How to establish a secure connection (SSL) from a Node.js API to an AWS RDS.
const Pool = require('pg').Pool
const fs = require('fs');
const pool = new Pool({
user: 'my_user',
host: 'my_host',
database: 'my_database',
password: 'my_password',
port: 22222,
ssl: {
ca: fs
.readFileSync("/etc/certificates/server-certificate.pem")
.toString()
}
});

Sequelize unable to connect to SQL Server through network

My setup is the following:
I have a Virtual Machine running all of my Database processes, let's call it DB-VM.
I'm currently developing at my own workstation (completely detached from DB-VM, except that we are under the same network.
I've created a valid connection string, validated by another database connection service throughout IIS and through a Data Link Properties file (.udl) and the connection.
This connection is described by the connection string as:
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=DB-VM\MY_DATABASE.
I tried to insert it into my Sequelize configuration as following:
const sequelize = new Sequelize({
dialect: 'mssql',
dialectModulePath: 'sequelize-msnodesqlv8',
dialectOptions: {
connectionString: 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=DB-VM\MY_DATABASE',
trustedConnection: true,
}
});
And then proceeded to try and authenticate through:
sequelize.authenticate().then(() => {
console.log('Connection stablished successfully!');
}).catch(err => {
console.log(err);
});
And this the error is as follows:
Notice: The database uses dynamic ports, therefore I can't specify the port through the port property.
Notice 2: The Named Pipes are disabled on my database settings, and I'm not sure if I will be able to enabled it.
Notice 3: The database is already setup to allow remote connections (it is currently used through a Webpage and works fine!
According to this line the sequelize-msnodesqlv8 library expects "Driver" to be a part of the connection string, otherwise it tries to guess. Besides that, all the examples of connection strings here1 and here2 are using either Server=myServerName\theInstanceName or just Server=myServerName. Instead of the Data Source=....
So step 1 is to fix you connection string. You could try one of the examples like:
dialectOptions: {
connectionString: 'Driver={SQL Server Native Client 10.0};Server=DB-VM;Database=MY_DATABASE;Trusted_Connection=yes;'
},
After that if you get a new error, please update the question.

Use multiple datastore connections with Sequelize

I've defined 2 connections in the /config/connections.js file:
monolithMysql: {
user: 'store_app',
database: 'store',
dialect: 'mysql',
options: {
dialect: 'mysql',
host: 'dockerhost',
port: 3306,
logging: console.log
}
},
postgres: {
user: 'user_app',
database: 'user_authentication',
dialect: 'postgres',
options: {
dialect: 'postgres',
host: 'dockerhost',
port: 8201,
logging: console.log
}
}
and in the different models I've put the property connection, so that they're distinguished, as follows:
module.exports = {
options: {
connection: 'monolithMysql', // or 'postgres' in other models.
...
In /config/models.js I set as default connection the monolithMysql one. But that should be overridden by the connection property, if specified, in the models. If I comment out or do not specify the connection property in /config/models.js then Sequelize hook fails to load.
Nevertheless, when trying to query models that have postgres as connection, it still queries them in the MySQL DB, and fails... If I set postgres as default connection, then it will always query in that DB, no matter what the local connection property of the different models says.
Any suggestions how to setup 2 connections at the same time?
Update: found out that it initializes only 1 instance of Sequelize - an instance with the default connection, specified in /config/models.js
Eventually, I ended up writing an upgrade to sails-hook-sequelize to support multiple database connection instances simultaneously.
The pull-request hasn't been reviewed at this point (13 April '16), but it has passed all tests and CI checks, so no worries. (the owner of the repo seems to be neglecting PR reviews in the last couple of months).
You can find the pull-request here.
In order to require the module, along with the multiple db connections upgrade, in your package.json file, just write:
"sails-hook-sequelize": "git#github.com:galioy/sails-hook-sequelize.git#f0c0c5d72ee97ac5504e6f3a0825e37c3587909a"
The configuration is the basic one, as you would do it normally for Sequelize:
add connections configurations to /config/connections.js (see OP)
for each model that you want to use secondary connection - just add
the name of the connection to options.connection property in the model itself (see
OP).
For detailed explanation, see the main comment of the pull-request.

Sails-Mongo connects to my database with no credentinals. How can I fix that?

I recently switched to mongodb database instead of the default disk.
My MongoDB adapter:
ArrowDB: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: '',
password: '',
database: 'ArrowDB'
},
At first the adapter has an empty username and password and it created the database "ArrowDB". Now I want to make it more secure by adding username and password But when I add user and pass to the adapter it fails to connect. Obviously because the database has no credentinals.
How can I add credentinals to my Mongodb database? I'm using Robomongo to view my database.

change database to mongo db on sails.js

I am a newbie in sails.js framework(and for node.js) and I have created myself an API from the address bar using sails.js features. my question is how do I transfer this data to mongodb so I can see it visually.
I have tried to follow this guide: https://www.npmjs.org/package/sails-mongo
but its for 0.9 sails version(current version is 0.10) so that a lot of files that I needed to change has been modified and gone/renamed. I couldn't find an updated tutorial as well so if anyone can please write down how can I implement mongoDB to my sails project that would be wonderful.
In config/connections.js you need to configure your mongoDB connection. Then go to config/models.js, uncomment the connection property and set the name of your mongoDB connection.
In config/connection.js, You can configure your MongoDb connection like this.
module.exports.connections = {
MongoConnection: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
// user: 'username',
// password: 'password',
database: 'DB_Name'
}
};
You need to install sails-mongo package using npm in your working folder.
Then in config/models.js, Add the name of your mongoDb connection like this:
module.exports.models = {
connection: 'MongoConnection',
migrate: 'alter'
};
Thats it, you are ready to go.

Resources