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

1.1.30 版本中非Spring环境手动pull时 空指针异常 #138

Open
Aboysky opened this issue Jul 6, 2021 · 1 comment
Open

1.1.30 版本中非Spring环境手动pull时 空指针异常 #138

Aboysky opened this issue Jul 6, 2021 · 1 comment
Assignees

Comments

@Aboysky
Copy link

Aboysky commented Jul 6, 2021

问题描述
在手动pull模式下,MetaInfoService 中的 request方法中的setRequestType方法空指针异常。原因由于第一次获取ClusterFuture时MetaInfoRequestParam对象中的reqestType为null,未被设置值。
版本关系
查阅过1.1.20和1.1.28的源码,不会导致此问题

环境配置
pom文件(部分,环境就是qmq的master分支启动的服务)

    <groupId>com.qunar.qmq</groupId>
    <artifactId>qmq-parent</artifactId>
    <version>1.1.30</version>
    <packaging>pom</packaging>

代码

public class ConsumerTest {
    private static final Logger LOG = LoggerFactory.getLogger(ConsumerTest.class);

    private static final ExecutorService executor = Executors.newFixedThreadPool(3);

    public static void main(String[] args) throws Exception {

//推荐一个应用里只创建一个实例
        MessageConsumerProvider consumer = new MessageConsumerProvider();
        consumer.setAppCode("consumer_app");
        consumer.setMetaServer("http://localhost:8080/meta/address");
        consumer.init();


        PullConsumer pullConsumer = consumer.getOrCreatePullConsumer("test.demo.qmq", "testdemo", false);
        List<Message> messages = pullConsumer.pull(10, 30);
        for(Message message : messages){

            message.ack(1000, null);
            System.out.println(message.getMessageId());

            //处理失败,则ack的第二个参数传入Throwable对象
            //message.ack(1000, new Exception("消费失败"));
        }

        System.in.read();

    }
}

出错代码
package qunar.tc.qmq.metainfoclient;
class:MetaInfoService
image
image
复现步骤

  1. 拉取master指定版本的master分支
  2. 执行测试代码

实际输出结果

java.lang.NullPointerException: null
	at qunar.tc.qmq.protocol.consumer.MetaInfoRequest.setRequestType(MetaInfoRequest.java:96)
	at qunar.tc.qmq.metainfoclient.MetaInfoService.request(MetaInfoService.java:128)
	at qunar.tc.qmq.metainfoclient.MetaInfoService.requestWrapper(MetaInfoService.java:114)
	at qunar.tc.qmq.broker.impl.BrokerServiceImpl.request(BrokerServiceImpl.java:180)
	at qunar.tc.qmq.broker.impl.BrokerServiceImpl.getClusterBySubject(BrokerServiceImpl.java:145)
	at qunar.tc.qmq.consumer.pull.PlainPullEntry.pull(PlainPullEntry.java:45)
	at qunar.tc.qmq.consumer.pull.DefaultPullConsumer.doPull(DefaultPullConsumer.java:126)
	at qunar.tc.qmq.consumer.pull.DefaultPullConsumer.run(DefaultPullConsumer.java:114)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at qunar.tc.qmq.concurrent.NamedThreadFactory$1.run(NamedThreadFactory.java:52)
	at java.lang.Thread.run(Thread.java:748)

简单解决方案
request.setRequestType(param.getRequestType());一行注释掉

keliwang added a commit that referenced this issue Jul 11, 2021
Signed-off-by: Keli <[email protected]>
@keliwang
Copy link
Contributor

这个问题应该已经修复了。

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