You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/03/12 01:43:43 UTC

[GitHub] [pulsar-client-node] equanz commented on issue #78: Error: Failed to send message: AlreadyClosed

equanz commented on issue #78: Error: Failed to send message: AlreadyClosed 
URL: https://github.com/apache/pulsar-client-node/issues/78#issuecomment-597964706
 
 
   It seems that `setTimeout` callback function run after pulsar client was destructed.
   I think if use `setTimeout` in this case, should to use Promise and wait for timeout.
   
   Here is an example.
   ```javascript
   const Pulsar = require("pulsar-client");
   
   async function produceTest(timeout) {
     const client = new Pulsar.Client({
       serviceUrl: "pulsar://localhost:6650"
     });
   
     const producer = await client.createProducer({
       topic: "persistent://public/default/my-topic"
     });
   
     await new Promise((resolve, reject) => {
       setTimeout(() => {
         producer.send({
           data: Buffer.from("My Message")
         });
         resolve();
       }, timeout);
     });
   
     await client.close();
   }
   
   produceTest(1000);
   produceTest(9000);
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services