当前位置: 首页>>代码示例>>Java>>正文


Java MessageQueue类代码示例

本文整理汇总了Java中org.apache.rocketmq.common.message.MessageQueue的典型用法代码示例。如果您正苦于以下问题:Java MessageQueue类的具体用法?Java MessageQueue怎么用?Java MessageQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MessageQueue类属于org.apache.rocketmq.common.message包,在下文中一共展示了MessageQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPullMessage_Success

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Test
public void testPullMessage_Success() throws Exception {
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult).isNotNull();
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
    assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
    assertThat(pullResult.getMinOffset()).isEqualTo(123);
    assertThat(pullResult.getMaxOffset()).isEqualTo(2048);
    assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<>());
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:19,代码来源:DefaultMQPullConsumerTest.java

示例2: testOrderMsgWithTagSubTag

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Test
public void testOrderMsgWithTagSubTag() {
    int msgSize = 5;
    String tag = "jueyin_tag";
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, tag, new RMQOrderListener());

    List<MessageQueue> mqs = producer.getMessageQueue();
    MessageQueueMsg mqMsgs = new MessageQueueMsg(mqs, msgSize, tag);
    producer.send(mqMsgs.getMsgsWithMQ());

    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer.getListner().getAllMsgBody()))
        .containsExactlyElementsIn(mqMsgs.getMsgBodys());

    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer.getListner()).getMsgs()))
        .isEqualTo(true);
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:20,代码来源:OrderMsgWithTagIT.java

示例3: lockBatchMQ

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public Set<MessageQueue> lockBatchMQ(//
    final String addr, //
    final LockBatchRequestBody requestBody, //
    final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null);

    request.setBody(requestBody.encode());
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            LockBatchResponseBody responseBody = LockBatchResponseBody.decode(response.getBody(), LockBatchResponseBody.class);
            Set<MessageQueue> messageQueues = responseBody.getLockOKMQSet();
            return messageQueues;
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:22,代码来源:MQClientAPIImpl.java

示例4: fetchConsumeOffsetFromBroker

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
private long fetchConsumeOffsetFromBroker(MessageQueue mq) throws RemotingException, MQBrokerException,
    InterruptedException, MQClientException {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    if (null == findBrokerResult) {
        // TODO Here may be heavily overhead for Name Server,need tuning
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    }

    if (findBrokerResult != null) {
        QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());

        return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(
            findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:22,代码来源:RemoteBrokerOffsetStore.java

示例5: submitConsumeRequestLater

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
private void submitConsumeRequestLater(//
    final ProcessQueue processQueue, //
    final MessageQueue messageQueue, //
    final long suspendTimeMillis//
) {
    long timeMillis = suspendTimeMillis;
    if (timeMillis == -1) {
        timeMillis = this.defaultMQPushConsumer.getSuspendCurrentQueueTimeMillis();
    }

    if (timeMillis < 10) {
        timeMillis = 10;
    } else if (timeMillis > 30000) {
        timeMillis = 30000;
    }

    this.scheduledExecutorService.schedule(new Runnable() {

        @Override
        public void run() {
            ConsumeMessageOrderlyService.this.submitConsumeRequest(null, processQueue, messageQueue, true);
        }
    }, timeMillis, TimeUnit.MILLISECONDS);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:25,代码来源:ConsumeMessageOrderlyService.java

示例6: selectOneMessageQueue

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public MessageQueue selectOneMessageQueue(final String lastBrokerName) {
    if (lastBrokerName == null) {//第一次进入就是空的
        return selectOneMessageQueue();
    } else {
        int index = this.sendWhichQueue.getAndIncrement();
        for (int i = 0; i < this.messageQueueList.size(); i++) {
            int pos = Math.abs(index++) % this.messageQueueList.size();
            if (pos < 0)
                pos = 0;
            MessageQueue mq = this.messageQueueList.get(pos);
            if (!mq.getBrokerName().equals(lastBrokerName)) {
                return mq;
            }
        }
        return selectOneMessageQueue();
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:18,代码来源:TopicPublishInfo.java

示例7: testTwoConsumerSubTag

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Test
public void testTwoConsumerSubTag() {
    int msgSize = 10;

    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, topic, "*",
        new RMQOrderListener());
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr,
        consumer1.getConsumerGroup(), topic, "*", new RMQOrderListener());
    TestUtils.waitForSeconds(waitTime);

    List<MessageQueue> mqs = producer.getMessageQueue();
    MessageQueueMsg mqMsgs = new MessageQueueMsg(mqs, msgSize);
    producer.send(mqMsgs.getMsgsWithMQ());

    consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    consumer2.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer1.getListner()).getMsgs()))
        .isEqualTo(true);
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer2.getListner()).getMsgs()))
        .isEqualTo(true);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:23,代码来源:OrderMsgBroadCastIT.java

示例8: earliestMsgStoreTime

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public long earliestMsgStoreTime(MessageQueue mq) throws MQClientException {
    String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName());
    if (null == brokerAddr) {
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName());
    }

    if (brokerAddr != null) {
        try {
            return this.mQClientFactory.getMQClientAPIImpl().getEarliestMsgStoretime(brokerAddr, mq.getTopic(), mq.getQueueId(),
                timeoutMillis);
        } catch (Exception e) {
            throw new MQClientException("Invoke Broker[" + brokerAddr + "] exception", e);
        }
    }

    throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:19,代码来源:MQAdminImpl.java

示例9: maxOffset

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public long maxOffset(MessageQueue mq) throws MQClientException {
    String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName());
    if (null == brokerAddr) {
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName());
    }

    if (brokerAddr != null) {
        try {
            return this.mQClientFactory.getMQClientAPIImpl().getMaxOffset(brokerAddr, mq.getTopic(), mq.getQueueId(), timeoutMillis);
        } catch (Exception e) {
            throw new MQClientException("Invoke Broker[" + brokerAddr + "] exception", e);
        }
    }

    throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:18,代码来源:MQAdminImpl.java

示例10: invokeBrokerToGetConsumerStatus

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public Map<String, Map<MessageQueue, Long>> invokeBrokerToGetConsumerStatus(final String addr, final String topic, final String group,
                                                                            final String clientAddr, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
    GetConsumerStatusRequestHeader requestHeader = new GetConsumerStatusRequestHeader();
    requestHeader.setTopic(topic);
    requestHeader.setGroup(group);
    requestHeader.setClientAddr(clientAddr);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.INVOKE_BROKER_TO_GET_CONSUMER_STATUS, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            if (response.getBody() != null) {
                GetConsumerStatusBody body = GetConsumerStatusBody.decode(response.getBody(), GetConsumerStatusBody.class);
                return body.getConsumerTable();
            }
        }
        default:
            break;
    }

    throw new MQClientException(response.getCode(), response.getRemark());
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:26,代码来源:MQClientAPIImpl.java

示例11: unlockDelay

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
private boolean unlockDelay(final MessageQueue mq, final ProcessQueue pq) {

        if (pq.hasTempMessage()) {
            log.info("[{}]unlockDelay, begin {} ", mq.hashCode(), mq);
            this.defaultMQPushConsumerImpl.getmQClientFactory().getScheduledExecutorService().schedule(new Runnable() {
                @Override
                public void run() {
                    log.info("[{}]unlockDelay, execute at once {}", mq.hashCode(), mq);
                    RebalancePushImpl.this.unlock(mq, true);
                }
            }, UNLOCK_DELAY_TIME_MILLS, TimeUnit.MILLISECONDS);
        } else {
            this.unlock(mq, true);
        }
        return true;
    }
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:17,代码来源:RebalancePushImpl.java

示例12: asyncSend

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public void asyncSend(Object msg, MessageQueue mq) {
    Message metaqMsg = (Message) msg;
    try {
        producer.send(metaqMsg, mq, sendCallback);
        msgBodys.addData(new String(metaqMsg.getBody()));
        originMsgs.addData(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:11,代码来源:RMQAsyncSendProducer.java

示例13: main

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException {
    final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1");

    scheduleService.setMessageModel(MessageModel.CLUSTERING);
    scheduleService.registerPullTaskCallback("TopicTest1", new PullTaskCallback() {

        @Override
        public void doPullTask(MessageQueue mq, PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {

                long offset = consumer.fetchConsumeOffset(mq, false);
                if (offset < 0)
                    offset = 0;

                PullResult pullResult = consumer.pull(mq, "*", offset, 32);
                System.out.printf("%s%n", offset + "\t" + mq + "\t" + pullResult);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        break;
                    case NO_MATCHED_MSG:
                        break;
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                }
                consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset());

                context.setPullNextDelayTimeMillis(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    scheduleService.start();
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:40,代码来源:PullScheduleService.java

示例14: consumerRunningInfo

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Override
public ConsumerRunningInfo consumerRunningInfo() {
    ConsumerRunningInfo info = new ConsumerRunningInfo();

    Properties prop = MixAll.object2Properties(this.defaultMQPushConsumer);

    prop.put(ConsumerRunningInfo.PROP_CONSUME_ORDERLY, String.valueOf(this.consumeOrderly));
    prop.put(ConsumerRunningInfo.PROP_THREADPOOL_CORE_SIZE, String.valueOf(this.consumeMessageService.getCorePoolSize()));
    prop.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, String.valueOf(this.consumerStartTimestamp));

    info.setProperties(prop);

    Set<SubscriptionData> subSet = this.subscriptions();
    info.getSubscriptionSet().addAll(subSet);

    Iterator<Entry<MessageQueue, ProcessQueue>> it = this.rebalanceImpl.getProcessQueueTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, ProcessQueue> next = it.next();
        MessageQueue mq = next.getKey();
        ProcessQueue pq = next.getValue();

        ProcessQueueInfo pqinfo = new ProcessQueueInfo();
        pqinfo.setCommitOffset(this.offsetStore.readOffset(mq, ReadOffsetType.MEMORY_FIRST_THEN_STORE));
        pq.fillProcessQueueInfo(pqinfo);
        info.getMqTable().put(mq, pqinfo);
    }

    for (SubscriptionData sd : subSet) {
        ConsumeStatus consumeStatus = this.mQClientFactory.getConsumerStatsManager().consumeStatus(this.groupName(), sd.getTopic());
        info.getStatusTable().put(sd.getTopic(), consumeStatus);
    }

    return info;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:35,代码来源:DefaultMQPushConsumerImpl.java

示例15: messageQueueChanged

import org.apache.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Override
public void messageQueueChanged(String topic, Set<MessageQueue> mqAll, Set<MessageQueue> mqDivided) {
    MessageModel messageModel =
        MQPullConsumerScheduleService.this.defaultMQPullConsumer.getMessageModel();
    switch (messageModel) {
        case BROADCASTING:
            MQPullConsumerScheduleService.this.putTask(topic, mqAll);
            break;
        case CLUSTERING:
            MQPullConsumerScheduleService.this.putTask(topic, mqDivided);
            break;
        default:
            break;
    }
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:16,代码来源:MQPullConsumerScheduleService.java


注:本文中的org.apache.rocketmq.common.message.MessageQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。