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

tag不能为* #7

Open
humingzhang opened this issue May 27, 2019 · 2 comments
Open

tag不能为* #7

humingzhang opened this issue May 27, 2019 · 2 comments

Comments

@humingzhang
Copy link

消费端和生产端必须tag,否则收不到消息

@no-today
Copy link

这个仓库有坑,消费者无法监听 Tag '*'

RocketMQListenerMethodAdapter.java

@Override
public void onMessage(E message, MessageContext context) throws ConsumeException {
    if (logger.isDebugEnabled()) {
        logger.debug("received message:{}", message);
    }
    String tag = context.getMessageExt().getTags();
    // 这边入参 Tag 为 'XXXX', 无法匹配到 '*'
    Method method = this.subscriptionGroup.getMethod(tag);
    Object delegate = this.subscriptionGroup.getTarget();
    if (method != null) {
        try {
            invoker.invoke(delegate, method, message, context);
        } catch (Exception e) {
            throw new ConsumeException(e);
        }
    } else {
        if (("*").equals(tag.trim())) {
            invoker.invoke(delegate, this.subscriptionGroup.getAllMethods(), message, context);
        } else {
            throw new ConsumeException("No way to find the corresponding tag");
        }
    }
}

@no-today
Copy link

修改为

if (("*").equals(tag.trim())) {
    invoker.invoke(delegate, this.subscriptionGroup.getAllMethods(), message, context);
} else {
    Method method_ = Optional.ofNullable(this.subscriptionGroup.getMethod("*"))
            .orElseThrow(() -> new ConsumeException("No way to find the corresponding tag: " + tag));
    try {
        invoker.invoke(delegate, method_, message, context);
    } catch (Exception e) {
        throw new ConsumeException(e);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants