本文整理汇总了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);
}
}
}
示例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;
}
示例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());
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
示例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