GitHub user JanYork edited a discussion: Function 'changeInvisibleDuration0' is 
infinitely recursive and can only end by throwing an exception. Unused method 
changeInvisibleDuration0

There is a function in 
https://github.com/apache/rocketmq-clients/blob/master/nodejs/src/consumer/SimpleConsumer.ts:
```js
async changeInvisibleDuration0(message: MessageView, invisibleDuration: number) 
{
    await this.changeInvisibleDuration0(message, invisibleDuration);
  }
```
Is this intentional? It will recurse infinitely, with no escape conditions and 
no logical processing. Why is it like this? ? ?

Then in the Java version of the client, 
https://github.com/apache/rocketmq-clients/blob/master/java/client/src/main/java/org/apache/rocketmq/client/java/impl/consumer/SimpleConsumerImpl.java
 , the following code exists:
```java
    /**
     * @see SimpleConsumer#changeInvisibleDuration(MessageView, Duration)
     */
    @Override
    public void changeInvisibleDuration(MessageView messageView, Duration 
invisibleDuration) throws ClientException {
        // 调用changeInvisibleDuration0方法
        final ListenableFuture<Void> future = 
changeInvisibleDuration0(messageView, invisibleDuration);
        handleClientFuture(future);
    }

    public ListenableFuture<Void> changeInvisibleDuration0(MessageView 
messageView, Duration invisibleDuration) {
        if (!this.isRunning()) {
            log.error("Unable to change invisible duration because simple 
consumer is not running, state={}, "
                + "clientId={}", this.state(), clientId);
            final IllegalStateException e = new IllegalStateException("Simple 
consumer is not running now");
            return Futures.immediateFailedFuture(e);
        }

        if (!(messageView instanceof MessageViewImpl)) {
            final IllegalArgumentException exception = new 
IllegalArgumentException("Failed downcasting for "
                + "messageView");
            return Futures.immediateFailedFuture(exception);
        }
        MessageViewImpl impl = (MessageViewImpl) messageView;

        final RpcFuture<ChangeInvisibleDurationRequest, 
ChangeInvisibleDurationResponse> future =
            changeInvisibleDuration(impl, invisibleDuration);
            
        return Futures.transformAsync(future, response -> {
            // Refresh receipt handle manually.
            impl.setReceiptHandle(response.getReceiptHandle());
            final Status status = response.getStatus();
            StatusChecker.check(status, future);
            return Futures.immediateVoidFuture();
        }, MoreExecutors.directExecutor());
    }
```

If the client is running normally and has the same type, we can simplify this 
code as follows:

```java
    @Override
    public void changeInvisibleDuration(MessageView messageView, Duration 
invisibleDuration) throws ClientException {
        final ListenableFuture<Void> future = 
changeInvisibleDuration0(messageView, invisibleDuration);
        // other ......
    }

    public ListenableFuture<Void> changeInvisibleDuration0(MessageView 
messageView, Duration invisibleDuration) {
        // other ......

        final RpcFuture<ChangeInvisibleDurationRequest, 
ChangeInvisibleDurationResponse> future =
            changeInvisibleDuration(impl, invisibleDuration);
            
        // other ......
    }
```

We can try to simplify:
```java
f(x,y){
    f(x,y)
}
```

Are these endless recursions intentional? Will there be no problems? Why has to 
be this way? Especially the nodejs function, I really don’t understand why it 
is like this?

GitHub link: https://github.com/apache/rocketmq-clients/discussions/743

----
This is an automatically sent email for dev@rocketmq.apache.org.
To unsubscribe, please send an email to: dev-unsubscr...@rocketmq.apache.org

Reply via email to