minio / minio-js

MinIO Client SDK for Javascript
https://docs.min.io/docs/javascript-client-quickstart-guide.html
Apache License 2.0
920 stars 271 forks source link

listenBucketNotifications not returning any events #1317

Closed zlaw-webmaster closed 1 month ago

zlaw-webmaster commented 1 month ago

I cannot seem to get listenBucketNotification to return any events for newly created files. The MCVE was based off of https://github.com/minio/thumbnailer with accompanying docker-compose.yml

I have

I am not sure what I might have missed and would appreciate all help and guidance

docker-compose.yml

services:
  minio:
    image: quay.io/minio/minio
    container_name: minio
    ports:
      - 9000:9000
      - 9001:9001
    environment:
      MINIO_ROOT_USER: listen-accesskey
      MINIO_ROOT_PASSWORD: hunter2hunter2
      MINIO_VOLUMES: /data
    command: server --console-address ":9001"

mcve.js

const Minio = require("minio");
const ENDPOINT = "localhost";
const ACCESSKEY = "listen-accesskey";
const SECRETKEY = "hunter2hunter2";
const BUCKETNAME = "listen-test";

const mc = new Minio.Client({
  endPoint: ENDPOINT,
  port: 9000,
  useSSL: false,
  accessKey: ACCESSKEY,
  secretKey: SECRETKEY,
});

async function main() {
  // create a bucket if it doesn't exist
  await mc
    .bucketExists(BUCKETNAME)
    .then((exists) => {
      if (!exists) return mc.makeBucket(BUCKETNAME);
    })
    .then(() => console.log(`Created bucket ${BUCKETNAME}`));

  // bucketname, suffix, prefix, events
  const poller = mc.listenBucketNotification(BUCKETNAME, "", "", [
    "*",
    "s3:ObjectCreated:*",
  ]);
  console.log(`Listening for events on bucket ${BUCKETNAME}`);

  const files = mc.listObjects(BUCKETNAME, "", true);
  files.on("data", (obj) => {
    console.log("verifying files are intact and connection works");
    console.log(obj);
  });

  // poller and process stdin from https://github.com/minio/thumbnailer
  poller.on("notification", (event) => {
    console.log("Received notification", event);
  });

  if (process.platform === "win32") {
    var rl = require("readline").createInterface({
      input: process.stdin,
      output: process.stdout,
    });

    rl.on("SIGINT", function () {
      process.emit("SIGINT");
    });
  }

  process.on("SIGINT", function () {
    // graceful shutdown
    poller.stop();
    process.exit();
  });

  // upload random files to trigger events
  console.log("start uploading random files");
  setInterval(async () => {
    const key = `file-${Date.now()}.txt`;
    await mc
      .putObject(BUCKETNAME, key, `lorem-ipsum-${Date.now()}`)
      .then(() => console.log(`Uploaded ${key}`))
      .catch((err) => console.error(err));
  }, 1000);
}
main();
prakashsvmx commented 1 month ago

https://github.com/minio/minio-js/blob/master/examples/minio/listen-bucket-notification.js

The repo was archived and request to Please refer to the example in the repo