apache / pulsar

Apache Pulsar - distributed pub-sub messaging system
https://pulsar.apache.org/
Apache License 2.0
14.25k stars 3.58k forks source link

Discuss: Make hasMessageAvailable to interface Consumer. #16358

Open horizonzy opened 2 years ago

horizonzy commented 2 years ago

Now the method hasMessageAvailable just is announced in ConsumerImpl and MultiConsumerImpl. If we want to check is there message available, we should transfer Consumer to ConsumerImpl or MultiConsumerImpl, then invoke hasMessageAvailable like below:

            if (consumer instanceof ConsumerImpl<RubbishInfo>) {
                return ((ConsumerImpl<RubbishInfo>) consumer).hasMessageAvailable();
            } else if (consumer instanceof MultiTopicsConsumerImpl<RubbishInfo>) {
                return ((MultiTopicsConsumerImpl<RubbishInfo>) consumer).hasMessageAvailable();
            }

Maybe we can make method hasMessageAvailable to Consumer.

shibd commented 2 years ago

What are the scenarios for consumers to use hasMessageAvailable?

Technoboy- commented 2 years ago

What are the scenarios for consumers to use hasMessageAvailable?

I think it's the same with adding getLastMessageId(#1066). BTW, there is a case here : https://github.com/apache/pulsar/pull/1066#discussion_r162751622

horizonzy commented 2 years ago

What are the scenarios for consumers to use hasMessageAvailable?

Sorry for delay reply. Not the method hasMessageAvailable is defined in both ConsumerImpl and MultiConsumerImpl.

https://github.com/apache/pulsar/blob/aabd5d020543210921f10648caf6720adc41d651/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L2188

https://github.com/apache/pulsar/blob/aabd5d020543210921f10648caf6720adc41d651/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MultiTopicsConsumerImpl.java#L811

The behavior is same. So I think the method should upper to parent file BaseConsumer or Consumer.

github-actions[bot] commented 2 years ago

The issue had no activity for 30 days, mark with Stale label.