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


Java MessageQueue类代码示例

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


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

示例1: unlock

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public void unlock(final MessageQueue mq, final boolean oneway) {
    FindBrokerResult findBrokerResult =
            this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), MixAll.MASTER_ID, true);
    if (findBrokerResult != null) {
        UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
        requestBody.setConsumerGroup(this.consumerGroup);
        requestBody.setClientId(this.mQClientFactory.getClientId());
        requestBody.getMqSet().add(mq);

        try {
            this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(),
                    requestBody, 1000, oneway);
            log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}",//
                    this.consumerGroup, //
                    this.mQClientFactory.getClientId(), //
                    mq);
        } catch (Exception e) {
            log.error("unlockBatchMQ exception, " + mq, e);
        }
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:22,代码来源:RebalanceImpl.java

示例2: testAllocateByCircle

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Test
public void testAllocateByCircle() {
    AllocateMessageQueueAveragelyByCircle circle = new AllocateMessageQueueAveragelyByCircle();
    String topic = "topic_test";
    String currentCID = "CID";
    int consumerSize = 3;
    int queueSize = 13;
    List<MessageQueue> mqAll = new ArrayList<MessageQueue>();
    for (int i = 0; i < queueSize; i++) {
        MessageQueue mq = new MessageQueue(topic, "brokerName", i);
        mqAll.add(mq);
    }

    List<String> cidAll = new ArrayList<String>();
    for (int j = 0; j < consumerSize; j++) {
        cidAll.add("CID" + j);
    }
    System.out.println(mqAll.toString());
    System.out.println(cidAll.toString());
    for (int i = 0; i < consumerSize; i++) {
        List<MessageQueue> rs = circle.allocate("", currentCID + i, mqAll, cidAll);
        System.out.println("rs[" + currentCID + i + "]:" + rs.toString());
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:25,代码来源:AllocateMessageQueueAveragelyTest.java

示例3: isLocked

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
private boolean isLocked(final String group, final MessageQueue mq, final String clientId) {
    ConcurrentHashMap<MessageQueue, LockEntry> groupValue = this.mqLockTable.get(group);
    if (groupValue != null) {
        LockEntry lockEntry = groupValue.get(mq);
        if (lockEntry != null) {
            boolean locked = lockEntry.isLocked(clientId);
            if (locked) {
                lockEntry.setLastUpdateTimestamp(System.currentTimeMillis());
            }

            return locked;
        }
    }

    return false;
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:17,代码来源:RebalanceLockManager.java

示例4: lockBatchMQ

import com.alibaba.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(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:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:21,代码来源:MQClientAPIImpl.java

示例5: updateOffset

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Override
public void updateOffset(MessageQueue mq, long offset, boolean increaseOnly) {
    if (mq != null) {
        AtomicLong offsetOld = this.offsetTable.get(mq);
        if (null == offsetOld) {
            offsetOld = this.offsetTable.putIfAbsent(mq, new AtomicLong(offset));
        }

        if (null != offsetOld) {
            if (increaseOnly) {
                MixAll.compareAndIncreaseOnly(offsetOld, offset);
            } else {
                offsetOld.set(offset);
            }
        }
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:18,代码来源:LocalFileOffsetStore.java

示例6: persistAll

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Override
public void persistAll(Set<MessageQueue> mqs) {
    if (null == mqs || mqs.isEmpty())
        return;

    OffsetSerializeWrapper offsetSerializeWrapper = new OffsetSerializeWrapper();
    for (MessageQueue mq : this.offsetTable.keySet()) {
        if (mqs.contains(mq)) {
            AtomicLong offset = this.offsetTable.get(mq);
            offsetSerializeWrapper.getOffsetTable().put(mq, offset);
        }
    }

    String jsonString = offsetSerializeWrapper.toJson(true);
    if (jsonString != null) {
        try {
            MixAll.string2File(jsonString, this.storePath);
        } catch (IOException e) {
            log.error("persistAll consumer offset Exception, " + this.storePath, e);
        }
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:23,代码来源:LocalFileOffsetStore.java

示例7: putTask

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public void putTask(String topic, Set<MessageQueue> mqNewSet) {
    Iterator<Entry<MessageQueue, PullTaskImpl>> it = this.taskTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, PullTaskImpl> next = it.next();
        if (next.getKey().getTopic().equals(topic)) {
            if (!mqNewSet.contains(next.getKey())) {
                next.getValue().setCancelled(true);
                it.remove();
            }
        }
    }

    for (MessageQueue mq : mqNewSet) {
        if (!this.taskTable.containsKey(mq)) {
            PullTaskImpl command = new PullTaskImpl(mq);
            this.taskTable.put(mq, command);
            this.scheduledThreadPoolExecutor.schedule(command, 0, TimeUnit.MILLISECONDS);
        }
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:21,代码来源:MQPullConsumerScheduleService.java

示例8: invokeBrokerToGetConsumerStatus

import com.alibaba.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(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:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:25,代码来源:MQClientAPIImpl.java

示例9: lockBatchMQ

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    LockBatchRequestBody requestBody = LockBatchRequestBody.decode(request.getBody(), LockBatchRequestBody.class);

    Set<MessageQueue> lockOKMQSet = this.brokerController.getRebalanceLockManager().tryLockBatch(//
        requestBody.getConsumerGroup(),//
        requestBody.getMqSet(),//
        requestBody.getClientId());

    LockBatchResponseBody responseBody = new LockBatchResponseBody();
    responseBody.setLockOKMQSet(lockOKMQSet);

    response.setBody(responseBody.encode());
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:18,代码来源:AdminBrokerProcessor.java

示例10: printMessageQueue

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public void printMessageQueue(List<MessageQueue> messageQueueList, String name) {
    if (messageQueueList == null || messageQueueList.size() < 1)
        return;
    System.out.println(name + ".......................................start");
    for (MessageQueue messageQueue : messageQueueList) {
        System.out.println(messageQueue);
    }
    System.out.println(name + ".......................................end");
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:10,代码来源:AllocateMessageQueueAveragelyTest.java

示例11: select

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Override
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
    int value = random.nextInt();
    if (value < 0) {
        value = Math.abs(value);
    }

    value = value % mqs.size();
    return mqs.get(value);
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:11,代码来源:SelectMessageQueueByRandoom.java

示例12: convertOffsetTable2OffsetList

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
private List<MessageQueueForC> convertOffsetTable2OffsetList(Map<MessageQueue, Long> table) {
    List<MessageQueueForC> list = new ArrayList<MessageQueueForC>();
    for (Entry<MessageQueue, Long> entry : table.entrySet()) {
        MessageQueue mq = entry.getKey();
        MessageQueueForC tmp =
                new MessageQueueForC(mq.getTopic(), mq.getBrokerName(), mq.getQueueId(), entry.getValue());
        list.add(tmp);
    }

    return list;
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:12,代码来源:Broker2Client.java

示例13: putMessages

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
public void putMessages(final MessageQueue mq, final List<MessageExt> msgs) {
    CachedQueue cachedQueue = this.mqCachedTable.get(mq);
    if (null == cachedQueue) {
        cachedQueue = new CachedQueue();
        this.mqCachedTable.put(mq, cachedQueue);
    }
    for (MessageExt msg : msgs) {
        cachedQueue.getMsgCachedTable().put(msg.getQueueOffset(), msg);
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:11,代码来源:RandomAsyncCommit.java

示例14: messageQueueChanged

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Override
public void messageQueueChanged(String topic, Set<MessageQueue> mqAll, Set<MessageQueue> mqDivided) {
    MessageQueueListener messageQueueListener =
            this.defaultMQPullConsumerImpl.getDefaultMQPullConsumer().getMessageQueueListener();
    if (messageQueueListener != null) {
        try {
            messageQueueListener.messageQueueChanged(topic, mqAll, mqDivided);
        }
        catch (Throwable e) {
            log.error("messageQueueChanged exception", e);
        }
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:14,代码来源:RebalancePullImpl.java

示例15: testConsumer3CurrentCID1

import com.alibaba.rocketmq.common.message.MessageQueue; //导入依赖的package包/类
@Test
public void testConsumer3CurrentCID1() {
    currentCID = "1";
    createConsumerIdList(3);
    createMessageQueueList(5);
    List<MessageQueue> result =
            allocateMessageQueueAveragely.allocate("", currentCID, messageQueueList, consumerIdList);
    printMessageQueue(result, "testConsumer3CurrentCID1");
    Assert.assertEquals(result.size(), 1);
    Assert.assertEquals(result.containsAll(getMessageQueueList().subList(1, 2)), true);
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:12,代码来源:AllocateMessageQueueAveragelyTest.java


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