org.apache.rocketmq.client.impl.consumer.DefaultMQPullConsumerImpl Java Examples

The following examples show how to use org.apache.rocketmq.client.impl.consumer.DefaultMQPullConsumerImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
/**
 * 检查消费
 *
 * @param nameSvr
 * @param address
 * @throws MQClientException
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 * @throws InterruptedException
 * @throws RemotingException
 * @throws MQBrokerException
 */
public static long checkReceive(String cluster, String nameSvr, String address)
        throws MQClientException, NoSuchFieldException, SecurityException, IllegalArgumentException,
        IllegalAccessException, InterruptedException, RemotingException, MQBrokerException {

    DefaultMQPullConsumer consumer = getReceiveCheckConsumer(nameSvr, cluster, address);
    Field f1 = DefaultMQPullConsumerImpl.class.getDeclaredField("mQClientFactory");
    f1.setAccessible(true);

    MQClientInstance instance = (MQClientInstance) f1.get(consumer.getDefaultMQPullConsumerImpl());

    Field f = MQClientInstance.class.getDeclaredField("brokerAddrTable");
    f.setAccessible(true);

    Field f2 = MQClientInstance.class.getDeclaredField("scheduledExecutorService");
    f2.setAccessible(true);

    ScheduledExecutorService service = (ScheduledExecutorService) f2.get(instance);
    service.shutdown();
    service.awaitTermination(1000, TimeUnit.SECONDS);

    ConcurrentHashMap<String, HashMap<Long, String>> map = (ConcurrentHashMap<String, HashMap<Long, String>>) f.get(instance);
    HashMap<Long, String> addresses = new HashMap<>();
    addresses.put(0L, address);
    map.put("rmqmonitor_" + address, addresses);

    MessageQueue queue = new MessageQueue("SELF_TEST_TOPIC", "rmqmonitor_" + address, 0);

    boolean pullOk = false;
    long maxOffset = -1;
    for (int i = 0; i < 2; ++i) {
        try {
            maxOffset = consumer.getDefaultMQPullConsumerImpl().maxOffset(queue);
            PullResult result = consumer.pull(queue, "*", maxOffset > 100 ? maxOffset - 10 : 0, 1);
            if (result.getPullStatus() == PullStatus.FOUND) {
                pullOk = true;
                break;
            } else if(result.getPullStatus() == PullStatus.NO_NEW_MSG) {
                checkSend(cluster, nameSvr, address);
                continue;
            }

            logger.warn("pull result failed, PullResult={}, cluster={}, namesvr={}, address={}", result, cluster, nameSvr, address);
        } catch (Throwable e) {
            logger.error("pull exception, cluster={}, namesvr={}, address={}", cluster, nameSvr, address, e);
        }
        Thread.sleep(1000);
    }
    if (!pullOk) {
        logger.error(String.format("[AlarmPullErr] cluster=%s, broker=%s", cluster, address));
    } else {
        logger.info("AlarmPullCheck cluster={}, broker={}", cluster, address);
    }
    return maxOffset;
}
 
Example #2
Source File: DefaultMQPullConsumer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
/**
 * This method will be removed in a certain version after April 5, 2020, so please do not use this method.
 */
@Deprecated
public DefaultMQPullConsumerImpl getDefaultMQPullConsumerImpl() {
    return defaultMQPullConsumerImpl;
}
 
Example #3
Source File: DefaultMQPullConsumer.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumerImpl getDefaultMQPullConsumerImpl() {
    return defaultMQPullConsumerImpl;
}
 
Example #4
Source File: DefaultMQPullConsumer.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumer(final String consumerGroup, RPCHook rpcHook) {
    this.consumerGroup = consumerGroup;
    defaultMQPullConsumerImpl = new DefaultMQPullConsumerImpl(this, rpcHook);
}
 
Example #5
Source File: DefaultMQPullConsumer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumerImpl getDefaultMQPullConsumerImpl() {
    return defaultMQPullConsumerImpl;
}
 
Example #6
Source File: DefaultMQPullConsumer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumer(final String consumerGroup, RPCHook rpcHook) {
    this.consumerGroup = consumerGroup;
    defaultMQPullConsumerImpl = new DefaultMQPullConsumerImpl(this, rpcHook);
}
 
Example #7
Source File: DefaultMQPullConsumer.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumerImpl getDefaultMQPullConsumerImpl() {
    return defaultMQPullConsumerImpl;
}
 
Example #8
Source File: DefaultMQPullConsumer.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumer(final String consumerGroup, RPCHook rpcHook) {
    this.consumerGroup = consumerGroup;
    defaultMQPullConsumerImpl = new DefaultMQPullConsumerImpl(this, rpcHook);
}
 
Example #9
Source File: Utils.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
/**
 * 检查消费
 *
 * @param nameSvr
 * @param address
 * @throws MQClientException
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 * @throws InterruptedException
 * @throws RemotingException
 * @throws MQBrokerException
 */
public static long checkReceive(String cluster, String nameSvr, String address)
        throws MQClientException, NoSuchFieldException, SecurityException, IllegalArgumentException,
        IllegalAccessException, InterruptedException, RemotingException, MQBrokerException {

    DefaultMQPullConsumer consumer = getReceiveCheckConsumer(nameSvr, cluster, address);
    Field f1 = DefaultMQPullConsumerImpl.class.getDeclaredField("mQClientFactory");
    f1.setAccessible(true);

    MQClientInstance instance = (MQClientInstance) f1.get(consumer.getDefaultMQPullConsumerImpl());

    Field f = MQClientInstance.class.getDeclaredField("brokerAddrTable");
    f.setAccessible(true);

    Field f2 = MQClientInstance.class.getDeclaredField("scheduledExecutorService");
    f2.setAccessible(true);

    ScheduledExecutorService service = (ScheduledExecutorService) f2.get(instance);
    service.shutdown();
    service.awaitTermination(1000, TimeUnit.SECONDS);

    ConcurrentHashMap<String, HashMap<Long, String>> map = (ConcurrentHashMap<String, HashMap<Long, String>>) f.get(instance);
    HashMap<Long, String> addresses = new HashMap<>();
    addresses.put(0L, address);
    map.put("rmqmonitor_" + address, addresses);

    MessageQueue queue = new MessageQueue("SELF_TEST_TOPIC", "rmqmonitor_" + address, 0);

    boolean pullOk = false;
    long maxOffset = -1;
    for (int i = 0; i < 2; ++i) {
        try {
            maxOffset = consumer.getDefaultMQPullConsumerImpl().maxOffset(queue);
            PullResult result = consumer.pull(queue, "*", maxOffset > 100 ? maxOffset - 10 : 0, 1);
            if (result.getPullStatus() == PullStatus.FOUND) {
                pullOk = true;
                break;
            } else if(result.getPullStatus() == PullStatus.NO_NEW_MSG) {
                checkSend(cluster, nameSvr, address);
                continue;
            }

            logger.warn("pull result failed, PullResult={}, cluster={}, namesvr={}, address={}", result, cluster, nameSvr, address);
        } catch (Throwable e) {
            logger.error("pull exception, cluster={}, namesvr={}, address={}", cluster, nameSvr, address, e);
        }
        Thread.sleep(1000);
    }
    if (!pullOk) {
        logger.error(String.format("[AlarmPullErr] cluster=%s, broker=%s", cluster, address));
    } else {
        logger.info("AlarmPullCheck cluster={}, broker={}", cluster, address);
    }
    return maxOffset;
}
 
Example #10
Source File: DefaultMQPullConsumer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumerImpl getDefaultMQPullConsumerImpl() {
    return defaultMQPullConsumerImpl;
}
 
Example #11
Source File: DefaultMQPullConsumer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumer(final String consumerGroup, RPCHook rpcHook) {
    this.consumerGroup = consumerGroup;
    defaultMQPullConsumerImpl = new DefaultMQPullConsumerImpl(this, rpcHook);
}
 
Example #12
Source File: DefaultMQPullConsumer.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumerImpl getDefaultMQPullConsumerImpl() {
    return defaultMQPullConsumerImpl;
}
 
Example #13
Source File: DefaultMQPullConsumer.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumerImpl getDefaultMQPullConsumerImpl() {
    return defaultMQPullConsumerImpl;
}
 
Example #14
Source File: DefaultMQPullConsumer.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumer(final String consumerGroup, RPCHook rpcHook) {
    this.consumerGroup = consumerGroup;
    defaultMQPullConsumerImpl = new DefaultMQPullConsumerImpl(this, rpcHook);
}
 
Example #15
Source File: DefaultMQPullConsumer.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumerImpl getDefaultMQPullConsumerImpl() {
    return defaultMQPullConsumerImpl;
}
 
Example #16
Source File: DefaultMQPullConsumer.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public DefaultMQPullConsumer(final String consumerGroup, RPCHook rpcHook) {
    this.consumerGroup = consumerGroup;
    defaultMQPullConsumerImpl = new DefaultMQPullConsumerImpl(this, rpcHook);
}
 
Example #17
Source File: DefaultMQPullConsumer.java    From rocketmq-read with Apache License 2.0 2 votes vote down vote up
/**
 * 底层使用的仍然是defaultMQPullConsumerImpl
 * @param consumerGroup consumerGroup
 * @param rpcHook rpcHook
 */
public DefaultMQPullConsumer(final String consumerGroup, RPCHook rpcHook) {
    this.consumerGroup = consumerGroup;
    defaultMQPullConsumerImpl = new DefaultMQPullConsumerImpl(this, rpcHook);
}
 
Example #18
Source File: DefaultMQPullConsumer.java    From rocketmq with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor specifying namespace, consumer group and RPC hook.
 *
 * @param consumerGroup Consumer group.
 * @param rpcHook RPC hook to execute before each remoting command.
 */
public DefaultMQPullConsumer(final String namespace, final String consumerGroup, RPCHook rpcHook) {
    this.namespace = namespace;
    this.consumerGroup = consumerGroup;
    defaultMQPullConsumerImpl = new DefaultMQPullConsumerImpl(this, rpcHook);
}