activemq 無法消費! consumers are alive when the messages are stuck !


我的微服務中, activemq 消費 一條消息的時候, 出了錯, 結果導致了 那條消息就一直處於pending 狀態, 

queue.user.545c2ed5-fee7-482a-bb59-564bbaa593f8_c5cdc461-4e9c-48c5-8684-6a81571114b8    1    1    0    0


點擊去是這樣的:

Browse queue.user.545c2ed5-...
Message ID                                      Correlation ID      Persistence      Priority      Redelivered      Reply To      Timestamp                      Type      Operations  
ID:dce4f74976e7-34120-1531388605944-1:4:1:1:1                        Persistent      4             true                      2018-07-12  09:43:31:554 UTC                   Delete

可以看到 pending  是1 , dequeue 是0 , 而消費者是1, 明明存在1個消費者, 但是卻一直不消費, 不dequeue 是什么意思??  本想直接在那個管理界面上點擊 delete 操作的, 但是想想,  哥也好歹是程序員, . 我決定寫個程序來消費他..

    /**
     *
     * 隊列操作
     */
    public static void consume() throws JMSException {
        Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        String qu = null;
        qu = "queue.user.545c2ed5-fee7-482a-bb59-564bbaa593f8_c5cdc461-4e9c-48c5-8684-6a81571114b8";
        Queue queue = session.createQueue(qu);
        MessageConsumer consumer = session.createConsumer(queue);
        System.out.println("consumer = " + consumer);
        consumer.setMessageListener(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                System.out.println("message00 ============ " + message);
                try {
                    message.acknowledge();
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
        });
    }

程序運行沒錯, 但是, 我的 MessageListener 似乎不起作用,  message00 ============  始終不打印出來.  我也是郁悶了, 這么簡單的程序都有錯啊, 我寫過很多次的好吧,  網上瘋狂搜索一把, 好像大家都是這樣寫的啊..  坑爹了啊.. 

不同於topic, queue 是可以先生產, 后面再消費的吧,,queue 並沒有生產者消費者時間先后順序的限制, 難道哪里記錯了?  各種找資料, 發現並不是這樣的..

 

難不成activemq 已經報錯了? 看下日志吧: 

2018-04-13 05:11:03,574 CRIT Supervisor running as root (no user in config file)
2018-04-13 05:11:03,581 WARN Included extra file "/etc/supervisor/conf.d/activemq.conf" during parsing
2018-04-13 05:11:03,581 WARN Included extra file "/etc/supervisor/conf.d/cron.conf" during parsing
2018-04-13 05:11:03,744 INFO RPC interface 'supervisor' initialized
2018-04-13 05:11:03,744 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-04-13 05:11:03,749 INFO supervisord started with pid 1
2018-04-13 05:11:04,751 INFO spawned: 'cron' with pid 16
2018-04-13 05:11:04,753 INFO spawned: 'activemq' with pid 17
2018-04-13 05:11:06,102 INFO success: cron entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-04-13 05:11:06,102 INFO success: activemq entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-04-13 07:09:36,530 WARN received SIGTERM indicating exit request
2018-04-13 07:09:36,530 INFO waiting for cron, activemq to die
2018-04-13 07:09:37,533 INFO stopped: activemq (terminated by SIGTERM)
2018-04-13 07:09:37,534 INFO stopped: cron (terminated by SIGTERM)
2018-04-13 07:11:36,201 CRIT Supervisor running as root (no user in config file)
2018-04-13 07:11:36,201 WARN Included extra file "/etc/supervisor/conf.d/activemq.conf" during parsing
2018-04-13 07:11:36,201 WARN Included extra file "/etc/supervisor/conf.d/cron.conf" during parsing
2018-04-13 07:11:36,258 INFO RPC interface 'supervisor' initialized
2018-04-13 07:11:36,260 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-04-13 07:11:36,260 INFO supervisord started with pid 1
2018-04-13 07:11:37,263 INFO spawned: 'cron' with pid 16
2018-04-13 07:11:37,265 INFO spawned: 'activemq' with pid 17
2018-04-13 07:11:38,737 INFO success: cron entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-04-13 07:11:38,738 INFO success: activemq entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-05-03 03:42:11,945 WARN received SIGTERM indicating exit request
2018-05-03 03:42:11,959 INFO waiting for cron, activemq to die
2018-05-03 03:42:12,971 INFO stopped: activemq (terminated by SIGTERM)
2018-05-03 03:42:12,973 INFO stopped: cron (terminated by SIGTERM)
2018-05-03 03:44:23,724 CRIT Supervisor running as root (no user in config file)
2018-05-03 03:44:23,727 WARN Included extra file "/etc/supervisor/conf.d/activemq.conf" during parsing
2018-05-03 03:44:23,728 WARN Included extra file "/etc/supervisor/conf.d/cron.conf" during parsing
2018-05-03 03:44:23,824 INFO RPC interface 'supervisor' initialized
2018-05-03 03:44:23,824 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-05-03 03:44:23,824 INFO supervisord started with pid 1
2018-05-03 03:44:24,830 INFO spawned: 'cron' with pid 16
2018-05-03 03:44:24,831 INFO spawned: 'activemq' with pid 17
2018-05-03 03:44:26,254 INFO success: cron entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-05-03 03:44:26,254 INFO success: activemq entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-07-16 09:35:45,450 CRIT Supervisor running as root (no user in config file)
2018-07-16 09:35:45,458 WARN Included extra file "/etc/supervisor/conf.d/activemq.conf" during parsing
2018-07-16 09:35:45,458 WARN Included extra file "/etc/supervisor/conf.d/cron.conf" during parsing
2018-07-16 09:35:45,472 INFO RPC interface 'supervisor' initialized
2018-07-16 09:35:45,472 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-07-16 09:35:45,472 INFO supervisord started with pid 1
2018-07-16 09:35:46,474 INFO spawned: 'cron' with pid 16
2018-07-16 09:35:46,475 INFO spawned: 'activemq' with pid 17
2018-07-16 09:35:47,773 INFO success: cron entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-07-16 09:35:47,773 INFO success: activemq entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

似乎也並沒有上面特別的, CRIT  是什么? 好像很嚴重的樣子, 感覺還是可以忽略的吧..

http://activemq.2283324.n4.nabble.com/Messages-stuck-in-pending-state-in-queue-td4669239.html  好像是版本問題唉, 難道?

http://activemq.2283324.n4.nabble.com/Messages-are-kept-in-Pending-queue-for-durable-topic-subscribers-td4690015.html 看的暈暈的

https://stackoverflow.com/questions/7786086/difference-between-pending-messages-and-enqueue-counter-in-active-mq : 提到

pending messages = number of messages CURRENTLY waiting for delivery in the destination (the current size of the queue)

enqueued messages = number of messages that where enqueued in the destination since the last statistic reset. This number can only rise.

dequeued messages = messages delivered from the destination to consumers. this number can be higher that the number of enqueued messages if a message was delivered to multiple consumers (topics).

好像並沒什么卵用..

 

天啊, 明明兩個消費者, 但是卻一直不消費, 不dequeue 是幾個意思? 

仔細一看, 此時的消費者是2, 那就是說, 還有其他消費者? 

queue.user.545c2ed5-fee7-482a-bb59-564bbaa593f8_c5cdc461-4e9c-48c5-8684-6a81571114b8    1    2    0    0

 

突然意識到是我的微服務還在運行, 難道它阻塞了其他消費者對當前queue的消費? 趕緊把 微服務 關閉, 再次運行上面程序,  搞定了! 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM