kontotto opened a new pull request, #348:
URL: https://github.com/apache/pulsar-client-node/pull/348
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
### Contribution Checklist
- PR title format should be *[type][component] summary*. For details, see
*[Guideline - Pulsar PR Naming
Convention](https://docs.google.com/document/d/1d8Pw6ZbWk-_pCKdOmdvx9rnhPiyuxwq60_TrD68d7BA/edit#heading=h.trs9rsex3xom)*.
- Fill out the template below to describe the changes contributed by the
pull request. That will give reviewers the context they need to do the review.
- Each pull request should address only one issue, not mix up code from
multiple issues.
- Each commit in the pull request has a meaningful commit message
- Once all items of the checklist are addressed, remove the above text and
this checklist, leaving only the filled out template below.
-->
This PR fixes an issue where client connections could be unintentionally
disconnected.
### Motivation
In the code below, which is a modified version of
examples/consumer_listener.js, the connection is disconnected after a few
seconds. I want to fix it.
```
const Pulsar = require('../');
(async () => {
// Create a client
const client = new Pulsar.Client({
serviceUrl: 'pulsar://localhost:6650',
});
Pulsar.Client.setLogHandler((level, file, line, message) => {
console.log('[%s][%s:%d] %s', level, file, line, message);
});
// Create a consumer with listener
const consumer = await client.subscribe({
topic: 'persistent://public/default/my-topic',
subscription: 'sub1',
subscriptionType: 'Shared',
listener: (msg, msgConsumer) => {
console.log(msg.getData().toString());
msgConsumer.acknowledge(msg);
},
});
})();
```
```
[1][Client:90] Subscribing on Topic :persistent://public/default/my-topic
[1][ClientConnection:184] [<none> -> pulsar://localhost:6650] Create
ClientConnection, timeout=10000
[1][ConnectionPool:106] Created connection for pulsar://localhost:6650
[1][ClientConnection:382] [127.0.0.1:52044 -> 127.0.0.1:6650] Connected to
broker
[1][HandlerBase:72] [0x600000be2f88, sub1, 0] Getting connection from pool
[1][ConsumerImpl:282] [0x600000be2f88, sub1, 0] Created consumer on broker
[127.0.0.1:52044 -> 127.0.0.1:6650]
[1][ClientConnection:1236] [127.0.0.1:52044 -> 127.0.0.1:6650] Connection
disconnected
```
<!-- Explain here the context, and why you're making that change. What is
the problem you're trying to solve. -->
### Modifications
<!-- Describe the modifications you've done. -->
Extend cClient lifetime prevents it from being released
### Verifying this change
- [x] Make sure that the change passes the CI checks.
*(Please pick either of the following options)*
This change is a trivial rework / code cleanup without any test coverage.
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc-required`
(Your PR needs to update docs and you will update later)
- [x] `doc-not-needed`
(Please explain why)
- [ ] `doc`
(Your PR contains doc changes)
- [ ] `doc-complete`
(Docs have been already added)
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]