Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix topic not shown correctly in the consumer string #329

Merged

Conversation

BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented Oct 15, 2023

Motivation

ConsumerImpl::getName() returns a string that is used in logs to represent the consumer. However, the topic part does not show correctly:

ConsumerImpl:283 | [0x6000001c88b8, consumer-1, 0] Created consumer on broker [127.0.0.1:60399 -> 127.0.0.1:6650]

It's because after #218, the ConsumerImpl::topic_ field becomes std::shared_ptr rather than a std::string but it is still used to construct the consumerStr_.

Modifications

Construct the consumerStr_ using the topic argument in the constructor and make consumerStr_ const because it is never changed.

Now the logs will be like:

ConsumerImpl:280 | [persistent://public/default/my-topic, consumer-1, 0] Created consumer on broker [127.0.0.1:60647 -> 127.0.0.1:6650]

### Motivation

`ConsumerImpl::getName()` returns a string that is used in logs to
represent the consumer. However, the topic part does not show correctly:

```
ConsumerImpl:283 | [0x6000001c88b8, consumer-1, 0] Created consumer on broker [127.0.0.1:60399 -> 127.0.0.1:6650]
```

It's because after apache#218,
the `ConsumerImpl::topic_` field becomes `std::shared_ptr` rather than a
`std::string` but it is still used to construct the `consumerStr_`.

### Modifications

Construct the `consumerStr_` using the `topic` argument in the
constructor and make `consumerStr_` const because it is never changed.

Now the logs will be like:

```
ConsumerImpl:280 | [persistent://public/default/my-topic, consumer-1, 0] Created consumer on broker [127.0.0.1:60647 -> 127.0.0.1:6650]
```
@BewareMyPower BewareMyPower added the bug Something isn't working label Oct 15, 2023
@BewareMyPower BewareMyPower added this to the 3.4.0 milestone Oct 15, 2023
@BewareMyPower BewareMyPower self-assigned this Oct 15, 2023
@BewareMyPower BewareMyPower merged commit 33085eb into apache:main Oct 16, 2023
11 checks passed
@BewareMyPower BewareMyPower deleted the bewaremypower/fix-consumer-str branch October 16, 2023 01:31
BewareMyPower added a commit to BewareMyPower/pulsar-client-cpp that referenced this pull request Oct 20, 2023
### Motivation

This is an additional fix to apache#329 because I still observed logs like:

```
Closing consumer for topic 0x6000028e0648
Closing producer for topic 0x600001210b88
```

It's because `HandlerBase::topic_` field is protected and could be
accessed directly from the derived classes.

### Motivation

In `HandlerBase`, make `topic_` private and add two methods `topic()`
and `getTopicPtr()` to get the reference to the string and the shared
pointer. `getTopicPtr()` should only be called when being passed to
`MessageImpl::setTopicName`.
BewareMyPower added a commit to streamnative/pulsar-client-cpp that referenced this pull request Oct 20, 2023
### Motivation

`ConsumerImpl::getName()` returns a string that is used in logs to
represent the consumer. However, the topic part does not show correctly:

```
ConsumerImpl:283 | [0x6000001c88b8, consumer-1, 0] Created consumer on broker [127.0.0.1:60399 -> 127.0.0.1:6650]
```

It's because after apache#218,
the `ConsumerImpl::topic_` field becomes `std::shared_ptr` rather than a
`std::string` but it is still used to construct the `consumerStr_`.

### Modifications

Construct the `consumerStr_` using the `topic` argument in the
constructor and make `consumerStr_` const because it is never changed.

Now the logs will be like:

```
ConsumerImpl:280 | [persistent://public/default/my-topic, consumer-1, 0] Created consumer on broker [127.0.0.1:60647 -> 127.0.0.1:6650]
```

(cherry picked from commit 33085eb)
BewareMyPower added a commit that referenced this pull request Oct 20, 2023
### Motivation

This is an additional fix to #329 because I still observed logs like:

```
Closing consumer for topic 0x6000028e0648
Closing producer for topic 0x600001210b88
```

It's because `HandlerBase::topic_` field is protected and could be
accessed directly from the derived classes.

### Motivation

In `HandlerBase`, make `topic_` private and add two methods `topic()`
and `getTopicPtr()` to get the reference to the string and the shared
pointer. `getTopicPtr()` should only be called when being passed to
`MessageImpl::setTopicName`.
BewareMyPower added a commit to streamnative/pulsar-client-cpp that referenced this pull request Oct 20, 2023
### Motivation

This is an additional fix to apache#329 because I still observed logs like:

```
Closing consumer for topic 0x6000028e0648
Closing producer for topic 0x600001210b88
```

It's because `HandlerBase::topic_` field is protected and could be
accessed directly from the derived classes.

### Motivation

In `HandlerBase`, make `topic_` private and add two methods `topic()`
and `getTopicPtr()` to get the reference to the string and the shared
pointer. `getTopicPtr()` should only be called when being passed to
`MessageImpl::setTopicName`.

(cherry picked from commit 7cefe0e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants