How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • var open = amqp.connect();
    open
      .then(function (conn) {
        process.once("SIGINT", conn.close.bind(conn));
        return doStuffWithConnection(conn);
      })
      .then(null, console.warn);
    
    Docs
    0
  • var dom = domain.create();
    dom.on("error", gracefullyRestart);
    
    dom.run(function () {
      amqp.connect(function (err, conn) {
        // ...
      });
    });
    
    Docs
    0
  • var open = amqp.connect();
    open
      .then(function (conn) {
        var ok = doStuffWithConnection(conn);
        return ok.then(conn.close.bind(conn));
      })
      .then(null, console.warn);
    
    Docs
    0
  • amqp
      .connect()
      .then(
        function (conn) {
          // Everything ok, but ..
          throw new Error("SNAFU");
        },
        function (err) {
          console.error("Connect failed: %s", err);
        }
      )
      .then(null, function (err) {
        console.error(
          "Connect succeeded, but error thrown: %s",
          err
        );
      });
    
    Docs
    0
  • amqp.connect(function (err, conn) {
      if (err !== null) return console.warn(err);
      doStuffWithConnection(conn, function () {
        conn.close();
      });
    });
    
    Docs
    0
  • require("amqplib/callback_api").connect(function (err, c) {
      c.createConfirmChannel(function (err, ch) {
        ch.sendToQueue(
          "foo",
          new Buffer("foobar"),
          {},
          function (err, ok) {
            if (err !== null) console.warn("Message nacked!");
            else console.log("Message acked");
          }
        );
      });
    });
    
    Docs
    0
  • amqp
      .connect()
      .then(function (conn) {
        var ok = conn.createChannel();
        ok = ok.then(function (ch) {
          return when.all([
            ch.assertQueue("foo"),
            ch.assertExchange("bar"),
            ch.bindQueue("foo", "bar", "baz"),
            ch.consume("foo", handleMessage),
          ]);
        });
        return ok;
      })
      .then(null, console.warn);
    
    Docs
    0
  • var open = require("amqplib").connect();
    open.then(function (c) {
      c.createConfirmChannel().then(function (ch) {
        ch.sendToQueue(
          "foo",
          new Buffer("foobar"),
          {},
          function (err, ok) {
            if (err !== null) console.warn("Message nacked!");
            else console.log("Message acked");
          }
        );
      });
    });
    
    Docs
    0
  • var dom = domain.create();
    dom.on("error", gracefullyRestart);
    
    amqp.connect(function (err, conn) {
      dom.add(conn);
      //...
    });
    
    Docs
    0
  • await consumer.connect();
    
    await consumer.subscribe({ topic: "topic-A" });
    
    // Subscribe can be called several times
    await consumer.subscribe({ topic: "topic-B" });
    await consumer.subscribe({ topic: "topic-C" });
    
    // It's possible to start from the beginning of the topic
    await consumer.subscribe({
      topic: "topic-D",
      fromBeginning: true,
    });
    
    Docs
    0
  • const { Kafka } = require("kafkajs");
    const kafka = new Kafka({
      clientId: "my-app",
      brokers: ["kafka1:9092", "kafka2:9092"],
    });
    const producer = kafka.producer();
    const consumer = kafka.consumer({ groupId: "test-group" });
    const run = async () => {
      // Producing
      await producer.connect();
      await producer.send({
        topic: "test-topic",
        messages: [{ value: "Hello KafkaJS user!" }],
      }); // Consuming
      await consumer.connect();
      await consumer.subscribe({
        topic: "test-topic",
        fromBeginning: true,
      });
      await consumer.run({
        eachMessage: async ({ topic, partition, message }) => {
          console.log({
            partition,
            offset: message.offset,
            value: message.value.toString(),
          });
        },
      });
    };
    run().catch(console.error);
    
    Docs
    0
  • await consumer.connect();
    await consumer.subscribe({ topic: /topic-(eu|us)-.*/i });
    
    Docs
    0
  • await consumer.connect();
    await consumer.subscribe({ topic: "example" });
    
    // you don't need to await consumer#run
    consumer.run({
      eachMessage: async ({ topic, message }) => true,
    });
    consumer.seek({
      topic: "example",
      partition: 0,
      offset: 12384,
    });
    
    Docs
    0
  • await consumer.connect();
    await consumer.subscribe({ topic: "jobs" });
    
    await consumer.run({
      eachMessage: async ({ topic, message }) => {
        try {
          await sendToDependency(message);
        } catch (e) {
          if (e instanceof TooManyRequestsError) {
            consumer.pause([{ topic }]);
            setTimeout(
              () => consumer.resume([{ topic }]),
              e.retryAfter * 1000
            );
          }
    
          throw e;
        }
      },
    });
    
    Docs
    0
  • const consumer = kafka.consumer({ groupId: "test-group" });
    
    await consumer.connect();
    await consumer.subscribe({
      topic: "test-topic",
      fromBeginning: true,
    });
    
    await consumer.run({
      eachMessage: async ({ topic, partition, message }) => {
        console.log({
          value: message.value.toString(),
        });
      },
    });
    
    Docs
    0
  • const kafka = new Kafka(...)
    const admin = kafka.admin()
    
    // remember to connect and disconnect when you are done
    await admin.connect()
    await admin.disconnect()
    
    Docs
    0
  • const kafka = new Kafka(...)
    const admin = kafka.admin()
    
    // remember to connect and disconnect when you are done
    await admin.connect()
    await admin.disconnect()
    
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples