Search in sources :

Example 6 with DefaultMQPushConsumer

use of com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer in project uavstack by uavorg.

the class RocketMQConsumer method initConsumer.

private DefaultMQPushConsumer initConsumer(QueueInfo queueInfo) {
    DefaultMQPushConsumer dmpc = new DefaultMQPushConsumer(consumerConfig.getComsumerGroup());
    /**
     * 设置Consumer第一次启动是从队列头部开始消费还是队列尾部开始消费<br>
     * 如果非第一次启动,那么按照上次消费的位置继续消费
     */
    dmpc.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    dmpc.setNamesrvAddr(consumerConfig.getNamingServer());
    if (consumerConfig.getPullBatchSize() >= 0) {
        dmpc.setPullBatchSize(50);
    }
    // subscribeTopics
    subscribeTopics(dmpc, queueInfo);
    // 配置是否是单线程的consumer监听,因为在处理事务的时候,使用actor模式,需要单线程处理那些数据库写的请求
    if (consumerConfig.getConsumeThreadMax() != null && consumerConfig.getConsumeThreadMax() > 0) {
        dmpc.setConsumeThreadMax(consumerConfig.getConsumeThreadMax());
    }
    if (consumerConfig.getConsumeThreadMin() != null && consumerConfig.getConsumeThreadMin() > 0) {
        dmpc.setConsumeThreadMin(consumerConfig.getConsumeThreadMin());
    }
    // 进行空值测试,如果没有填写queue类型一律按照queue信息算
    if (MQFactory.QueueType.TOPIC.equals(queueInfo.getQueueType())) {
        dmpc.setMessageModel(MessageModel.BROADCASTING);
    }
    return dmpc;
}
Also used : DefaultMQPushConsumer(com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer)

Aggregations

DefaultMQPushConsumer (com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer)6 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)4 ConsumeConcurrentlyContext (com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)3 ConsumeConcurrentlyStatus (com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus)3 ConsumeOrderlyContext (com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyContext)3 ConsumeOrderlyStatus (com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyStatus)3 MessageListenerConcurrently (com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently)3 MessageListenerOrderly (com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly)3 MQBrokerException (com.alibaba.rocketmq.client.exception.MQBrokerException)3 DefaultMQProducer (com.alibaba.rocketmq.client.producer.DefaultMQProducer)3 Message (com.alibaba.rocketmq.common.message.Message)3 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)3 RemotingException (com.alibaba.rocketmq.remoting.exception.RemotingException)3 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 ConsoleLogger (com.creditease.monitor.log.ConsoleLogger)1 RocketmqHookProxy (com.creditease.uav.hook.rocketmq.RocketmqHookProxy)1 RocketListener (rocketDoubleWrite.listener.RocketListener)1