pinojs / pino-eventhub

MIT License
0 stars 2 forks source link

Question: HTTP versus AMQP #16

Open jmealo opened 3 years ago

jmealo commented 3 years ago

@mcollina: Hello!

I'm curious (as others may be):

Did you choose HTTP because you ran into issues with AMQP? I'm wondering what the pros/cons of using HTTP versus the azure-sdk with AMQP.

Thanks, Jeff

mcollina commented 3 years ago

Historically AMQP support has been problematic in Node, I'm not sure if things have improved.

jmealo commented 3 years ago

Historically AMQP support has been problematic in Node, I'm not sure if things have improved.

@mcollina: thank you for the quick reply :) I figured as much. I can provide an update on the current quality/status:

Where I think Azure customers are getting jammed up:

If you cut and paste the batch example code from the Azure docs for producers into an async request or event handler you're going to have orphaned batches/lost messages in production under load and a subtle memory leak. I opened an issue to improve documentation or add a helper object to eliminate the foot canon. The bug is unlikely to occur during development with the batch sizes a developer is likely to test with so I can't imagine my team is the first to hit this.

Here's a minimal fix that took me longer to come up with than I'd have liked:

Safe async batch creation

const getBatch = async () => {
  // If another batch is already pending; we return the promise that will resolve to that batch.
  // You can .then() or await the same promise multiple times; you cannot resolve()/reject() multiple values
  if (nextBatch) {
    return nextBatch
  }

  try {
    nextBatch = producer.createBatch({ maxSizeInBytes })
    const batch = await nextBatch
    return batch
  } finally {
    nextBatch = undefined
  }
}

@mcollina: Do you think the foot canon with async batch creation in an event handler is worth doing a write up on to help folks understand?

mcollina commented 3 years ago

Yes, it's definitely worth it.

I'm not sure what's the goal of this issue. Would you like to help in the mantainance of this module?