yosiat commented on a change in pull request #83: Consumer with message 
listener dies after some time
URL: https://github.com/apache/pulsar-client-node/pull/83#discussion_r394994930
 
 

 ##########
 File path: src/Consumer.cc
 ##########
 @@ -45,6 +45,37 @@ void Consumer::Init(Napi::Env env, Napi::Object exports) {
   constructor.SuppressDestruct();
 }
 
+struct MessageListenerProxyData {
+  Consumer *consumer;
+  pulsar_message_t *cMessage;
+
+  MessageListenerProxyData(pulsar_message_t *cMessage, Consumer *consumer)
+      : cMessage(cMessage), consumer(consumer) {}
+};
+
+void MessageListenerProxy(Napi::Env env, Napi::Function jsCallback, 
MessageListenerProxyData *data) {
+  Napi::Object msg = Message::NewInstance({}, data->cMessage);
+  Consumer *consumer = data->consumer;
+  delete data;
+
+  // I haven't figured out how to pass consumer as an argument to method
+  // opened issue here - https://github.com/nodejs/node-addon-api/issues/686
 
 Review comment:
   I haven't figured out how to pass consumer as an argument to method.
   Since the consumer is `Napi::ObjectWrap` and I need `Napi::Object`.
   
   not sure how to solve this,  I solved this in my code like this:
   ```
     const consumer = await client.subscribe({
       topic: 'persistent://public/default/my-topic',
       subscription: 'sub1',
       subscriptionType: 'Shared',
       ackTimeoutMs: 10000,
       listener: function(msg) {
         console.log(msg.getData().toString());
         consumer.acknowledge(msg);
       }
     });
   ```
   
   referencing the consumer I created in the function.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to