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

Connection error when using mysql-events #46

Open
McLotos opened this issue Dec 15, 2022 · 2 comments
Open

Connection error when using mysql-events #46

McLotos opened this issue Dec 15, 2022 · 2 comments

Comments

@McLotos
Copy link

McLotos commented Dec 15, 2022

try using example from readme.

const mysql = require('mysql');
const MySQLEvents = require('@rodrigogs/mysql-events');

const program = async () => {
  const connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'root',
  });

  const instance = new MySQLEvents(connection, {
    startAtEnd: true,
    excludedSchemas: {
      mysql: true,
    },
  });

  await instance.start();

  instance.addTrigger({
    name: 'TEST',
    expression: '*',
    statement: MySQLEvents.STATEMENTS.ALL,
    onEvent: (event) => { // You will receive the events here
      console.log(event);
    },
  });
  
  instance.on(MySQLEvents.EVENTS.CONNECTION_ERROR, console.error);
  instance.on(MySQLEvents.EVENTS.ZONGJI_ERROR, console.error);
};

program()
  .then(() => console.log('Waiting for database events...'))
  .catch(console.error);

so get error

 Error: connect ETIMEDOUT
     at Connection._handleConnectTimeout (/var/www/html/node_modules/mysql/lib/Connection.js:409:13)
     at Object.onceWrapper (node:events:627:28)
     at Socket.emit (node:events:513:28)
     at Socket._onTimeout (node:net:553:8)
     at listOnTimeout (node:internal/timers:564:17)
     at process.processTimers (node:internal/timers:507:7)
     --------------------
     at Protocol._enqueue (/var/www/html/node_modules/mysql/lib/protocol/Protocol.js:144:48)
     at Protocol.handshake (/var/www/html/node_modules/mysql/lib/protocol/Protocol.js:51:23)
     at Connection.connect (/var/www/html/node_modules/mysql/lib/Connection.js:116:18)
     at /var/www/html/node_modules/@rodrigogs/mysql-events/lib/connectionHandler.js:6:75
     at new Promise (<anonymous>)
     at connect (/var/www/html/node_modules/@rodrigogs/mysql-events/lib/connectionHandler.js:6:31)
     at connectionHandler (/var/www/html/node_modules/@rodrigogs/mysql-events/lib/connectionHandler.js:42:11)
     at MySQLEvents.start (/var/www/html/node_modules/@rodrigogs/mysql-events/lib/MySQLEvents.js:88:29)
     at program (/var/www/html/index.js:12:18)
     at Object.<anonymous> (/var/www/html/index.js:27:1) {
   errorno: 'ETIMEDOUT',
   code: 'ETIMEDOUT',
   syscall: 'connect',
   fatal: true
 }

t

@McLotos
Copy link
Author

McLotos commented Dec 15, 2022

@rodrigogs ? Are you there? =)

@imdkbj
Copy link

imdkbj commented Dec 28, 2022

Try this, Working for me.

const instance = new MySQLEvents(
      {
        host: dbConfigs.host,
        port: dbConfigs.port,
        user: dbConfigs.username,
        password: dbConfigs.password,
      },
      {
        startAtEnd: true,
        excludedSchemas: {
          mysql: true,
        },
      }
    );

    instance
      .start()
      .then(() => {
        console.log("Running MySQLEvents!");
        instance.addTrigger({
          name: "xyz",
          expression: "*",
          statement: MySQLEvents.STATEMENTS.ALL,
          onEvent: (event) => {
            // Here you will get the events for the given expression/statement.
            // This could be an async function.
            console.log("event", event);
          },
        });
      })
      .catch((err) => console.error("Something bad happened MySQLEvents", err));

    instance.on(MySQLEvents.EVENTS.CONNECTION_ERROR, console.error);
    instance.on(MySQLEvents.EVENTS.ZONGJI_ERROR, console.error);

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

2 participants