I am using Cloudamqp to connect with RabbitMq when I am trying to send 10 messages its publishing data successfully to the queue but when I am trying to send 2,000 messages its showing connection failed error shown below:
Error Error: connect ECONNREFUSED 15.206.75.114:5671
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '15.206.75.114',
port: 5671
}
Error Error: Expected ConnectionOpenOk; got <ConnectionClose channel:0>
at /home/digvijay/test/test-lorien/node_modules/amqplib/lib/connection.js:167:14
at /home/digvijay/test/test-lorien/node_modules/amqplib/lib/connection.js:159:12
at TLSSocket.recv (/home/digvijay/test/test-
lorien/node_modules/amqplib/lib/connection.js:507:12)
I am reading the Excel file using XLSX library and sending those rows to the queue. Below is my code:
const express = require('express');
const XLSX = require("xlsx");
const amqp = require('amqplib/callback_api');
const app = express();
const port = process.env.PORT || 3300;
// Reading our test file
const file = XLSX.readFile('./limit9.xlsx')
app.get('/', (req, res) => {
const sheets = file.SheetNames;
for (let i = 0; i < sheets.length; i++) {
const temp = XLSX.utils.sheet_to_json(
file.Sheets[file.SheetNames[i]])
temp.forEach((res) => {
sendData(res); //Here sending data to the queue
});
}
});
function sendData(res) {
amqp.connect(`amqps://nuogafvveJoldl_RhEyfs7qJzX0BIRep6J8rFIN-0#puffin.rmq2.cloudamqp.com/xxxxxxx`, (err, connection) => {
if (err) {
console.log("Error",err);
}
else {
connection.createChannel((err, channel) => {
if (err) {
throw err;
}
else {
let queu = "review_data";
channel.assertQueue(queu, {
durable: false
});
var json = JSON.stringify(res);
channel.sendToQueue(queu, Buffer.from(json));
}
});
}
});
}
Why is it throwing connection error when I am sending large amount of messages but works fine for sending few messages?
Related
I have a simple NodeJs application that should connect to RabbitMq.
The code:
const amqp = require('amqplib/callback_api');
const amqpUri = "amqp://user:password#localhost:5672"
if (amqpUri == null)
throw Error('Missing AMQP_URI environment variable.');
amqp.connect(amqpUri, function(error0, connection) {
if (error0)
throw error0;
connection.createChannel(function(error1, channel) {
if (error1) {
throw error1;
}
const exchangeName = 'product.event';
const queueName1 = 'create';
const routingKey1 = 'create';
const queueName2 = 'delete';
const routingKey2 = 'delete';
channel.assertExchange(exchangeName, 'topic', {
durable: false,
});
// create
channel.assertQueue(queueName1, {
durable: false,
});
channel.bindQueue(queueName1, exchangeName, routingKey1);
channel.consume(queueName1, (msg) => consumeCreated(channel, msg));
// delete
channel.assertQueue(queueName2, {
durable: false,
});
channel.bindQueue(queueName2, exchangeName, routingKey2);
channel.consume(queueName2, (msg) => consumeDeleted(channel, msg));
});
});
Then run a RabbitMq image with:
docker run -d --hostname my-rabbit --name some-rabbit -p 5672:15672 -e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password rabbitmq:3-management
I can access the rabbitmq and connect with the credentials user/password at http://localhost:5672.
For some reason, I have the error:
/home/hamuto/CLO902-Group35/indexer/app.js:12
throw error0;
^
Error: Socket closed abruptly during opening handshake
at Socket.endWhileOpening (/home/hamuto/CLO902-Group35/indexer/node_modules/amqplib/lib/connection.js:260:17)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
i see this is not likely the case as your using the correct port, however I was getting the exact same error messages when I tried using HTTP port instead of tpc port.
Again I know this isnt your issue but if guess it could help you pinpoint potential failpoints.
I am trying to connect to my Amazon Neptune instance from a API GW. I am using Node.js and Lambda
My YML looks like this
NeptuneDBCluster:
Type: "AWS::Neptune::DBCluster"
Outputs:
NeptuneEndpointAddress:
Description: Neptune DB endpoint address
Value: !GetAtt NeptuneDBCluster.Endpoint
Export:
Name: !Sub ${env:STAGE}-neptune-endpoint-address
My code looks like this
const gremlin = require('gremlin');
const {
NEPTUNE_ENDPOINT
} = process.env;
const { cardinality: { single } } = gremlin.process;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const Graph = gremlin.structure.Graph;
async function createUserNode(event, context, callback) {
const url = 'wss://" + NEPTUNE_ENDPOINT + ":8182/gremlin';
const dc = new DriverRemoteConnection(url);
const parsedBody = JSON.parse(event.body);
try {
const graph = new Graph();
const g = graph.traversal().withRemote(dc);
const vertex = await g.addV(parsedBody.type)
.property(single, 'name', parsedBody.name)
.property(single, 'username', parsedBody.username)
.property('age', parsedBody.age)
.property('purpose', parsedBody.purpose)
.next();
if (vertex.value) {
return callback(null, {
statusCode: 200,
body: vertex.value
});
}
} catch (error) {
console.error(error);
}
};
I keep getting the folowing error from Cloudwatch (I also tried creating a local js file and it gives the same error)
ERROR Error: getaddrinfo ENOTFOUND my-url
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'my-url'
}
I also tried to write the endpoint without getting it from process.env and I am still facing the same issue. What am i missing?
Alright for anyone being as confused as I am when trying Neptune for first time. You need to create a database instance aswell, I thought the Serverless Framework would do this to me but now I know.
I am trying to learn Node.js and created a simple project to query the local database. But I get failed to look up an instance error message.
I have checked that the SQL Server services running in services.msc
I have verified TCP/IP is enabled
I have tried with the username and password and without it as well. I connect to localdb in SQL Server Management Studio as (localdb)\v11.0 and below is the screenshot of the properties
What am I doing incorrectly? What should be actual username and password? What should be the servername?
const sql = require('mssql');
// config for your database
const config = {
user: 'mywindows username',
password: 'my windows password',
server: '(localdb)\\v11.0',
database: 'test',
options: {
encrypt: true
}
};
console.log('starting sql');
var connection = new sql.connect(config, function(err) {
console.log(err);
var request = new sql.Request(connection);
request.query('select * from employees', function(err, recordset) {
if(err) // ... error checks
console.log('Database connection error');
console.dir("User Data: "+recordset);
});
});
sql.close();
console.log('ending sql');
});
app.listen(3002, () => {
console.log('Listening on port 3002');})
Below is the error message
{ ConnectionError: Failed to lookup instance on (localdb) -
getaddrinfo ENOTFOUND (localdb)
at Connection.tedious.once.err (C:\Users\vndbsubramaniam\Desktop\React
projects\ReactWithSql\node_modules\mssql\lib\tedious.js:244:17)
at Object.onceWrapper (events.js:285:13)
at Connection.emit (events.js:197:13)
at InstanceLookup.instanceLookup (C:\Users\vndbsubramaniam\Desktop\React
projects\ReactWithSql\node_modules\tedious\lib\connection.js:945:16)
at sender.execute (C:\Users\vndbsubramaniam\Desktop\React projects\ReactWithSql\node_modules\tedious\lib\instance-lookup.js:66:13)
at GetAddrInfoReqWrap.invokeLookupAll [as callback] (C:\Users\vndbsubramaniam\Desktop\React
projects\ReactWithSql\node_modules\tedious\lib\sender.js:43:16)
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (dns.js:70:17) code: 'EINSTLOOKUP', originalError: { ConnectionError: Failed to
lookup instance on (localdb) - getaddrinfo ENOTFOUND (localdb)
at ConnectionError (C:\Users\vndbsubramaniam\Desktop\React projects\ReactWithSql\node_modules\tedious\lib\errors.js:13:12)
at InstanceLookup.instanceLookup (C:\Users\vndbsubramaniam\Desktop\React
projects\ReactWithSql\node_modules\tedious\lib\connection.js:945:32)
at sender.execute (C:\Users\vndbsubramaniam\Desktop\React projects\ReactWithSql\node_modules\tedious\lib\instance-lookup.js:66:13)
at GetAddrInfoReqWrap.invokeLookupAll [as callback] (C:\Users\vndbsubramaniam\Desktop\React
projects\ReactWithSql\node_modules\tedious\lib\sender.js:43:16)
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (dns.js:70:17)
message:
'Failed to lookup instance on (localdb) - getaddrinfo ENOTFOUND (localdb)',
code: 'EINSTLOOKUP' }, name: 'ConnectionError' } Database connection error
After struggling for hours on this one finally found the answer here SQL to Node connection
It seems i have to add msnodesqlv8 package and use add the driver syntax to the config.
app.get('/test', (req, res) => {
const sql = require('mssql/msnodesqlv8');
// config for your database
const config = {
database: 'test',
server: '(localdb)\\v11.0',
driver: 'msnodesqlv8',
options : {
trustedConnection : true
}
};
console.log('starting sql');
const pool = new sql.ConnectionPool(config);
pool.connect().then(() => {
//simple query
pool.request().query('select * from employees', (err, result) => {
if(err) res.send(err)
else{
return res.json({
data : result.recordset
})
}
})
sql.close();
})
console.log('ending sql');
});
you will need msnodesqlv8 driver, which you have to paste it in require as
var sql = require('mssql/msnodesqlv8'),
as well as you will have to include it in driver section in config object.
var config = {
user:"*****",
password:"*****",
database:"*****",
driver: 'msnodesqlv8',
server:"*****",
options: {
trustedConnection : true
}
}
I have this code block in server.js file:
const Telegram = require('telegram-node-bot')
const tg = new Telegram.Telegram('***********token**************',{
workers:1
});
const pingController = require('./controllers/ping')
,otherwiseController = require('./controllers/otherwise')
tg.router.when(new Telegram.TextCommand('/ping','pingCommand'), new pingController())
.otherwise(new otherwiseController());
and this code block in ping.js file:
const Telegram = require('telegram-node-bot');
class pingController extends Telegram.TelegramBaseController{
pingHandler($){
$.sendMessage('pong');
}
get routes() {
return{
'pingCommand': 'pingHandler'
};
}
}
module.exports = pingController;
and finally this code block in otherwise file:
const Telegram = require('telegram-node-bot');
class otherwiseController extends Telegram.TelegramBaseController{
handler($){
$.sendMessage('Sorry!!!')
}
}
module.exports = otherwiseController;
when I run node server.js, I just got error like this:
[error]
Network error: Error: connect ETIMEDOUT 149.154.167.220:443
at Object._errnoException (util.js:1031:13)
at _exceptionWithHostPort (util.js:1052:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1195:14) request TelegramApiRequest { _method: 'setWebhook', _params: {
url: '' }, _multipart: undefined }
Also, the telegram is filtered in our country!!!, and I use the Siphon 3 proxy.
its because you have't set your proxy for your terminal/cmd
for Linux:
export http_proxy='http://proxyserveraddress:3128'
export https_proxy='https://proxyserveraddress:3128'
for Wndows:
set HTTP_PROXY=http://proxyserveraddress:3128
set HTTPS_PROXY=https://proxyserveraddress:3128
You can use SOCKS5 proxy with the socks5-https-client lib. Example:
const TelegramBot = require('node-telegram-bot-api')
const Agent = require('socks5-https-client/lib/Agent')
const bot = new TelegramBot(process.env.TELEGRAM_API_TOKEN, {
polling: true,
request: {
agentClass: Agent,
agentOptions: {
socksHost: process.env.PROXY_SOCKS5_HOST,
socksPort: parseInt(process.env.PROXY_SOCKS5_PORT),
// If authorization is needed:
// socksUsername: process.env.PROXY_SOCKS5_USERNAME,
// socksPassword: process.env.PROXY_SOCKS5_PASSWORD
}
}
})
This solution to continue developing bot on your local PC (without proxy you can not start bots from Iran and Russia) and it works.
I am getting the following error when using the twilio node module
{ Error: read ECONNRESET
at exports._errnoException (util.js:1026:11)
at TLSWrap.onread (net.js:569:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
{ status: 'ECONNRESET',
message: 'Unable to reach host: "api.twilio.com"' }
I am able to send SMS messages through Postman and their console interface but when trying it through NodeJS I get the error.
The code that I have is this:
var express = require('express');
var app = express();
var twilio = require('twilio');
var accountSid = 'ACXXXXXXXXXXXXXXX';
var apiKey = 'XXXXXXXXXXXXXXXXXXX';
var apiSecret = 'XXXXXXXXXXXXXX';
var twilioClient = new twilio.RestClient(accountSid, apiSecret);
//var account = twilioClient.accounts(accountSid);
//Send an text message
twilioClient.messages.create({
body: 'Hello from Node',
to: '+my_num', // Text this number
from: '+twilio_num' // From a valid Twilio number
}, function(err, message) {
if (err) {
console.log(err);
}
else {
console.log(message);
}
});
I found a similar problem here and followed the posted solution but that didn't work. I am guessing this is an entirely different error.