org.apache.rocketmq.common.message.Message.getTopic()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(245)

本文整理了Java中org.apache.rocketmq.common.message.Message.getTopic()方法的一些代码示例,展示了Message.getTopic()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getTopic()方法的具体详情如下:
包路径:org.apache.rocketmq.common.message.Message
类名称:Message
方法名:getTopic

Message.getTopic介绍

暂无

代码示例

代码示例来源:origin: apache/rocketmq

for (; nextIndex < messages.size(); nextIndex++) {
  Message message = messages.get(nextIndex);
  int tmpSize = message.getTopic().length() + message.getBody().length;
  Map<String, String> properties = message.getProperties();
  for (Map.Entry<String, String> entry : properties.entrySet()) {

代码示例来源:origin: apache/rocketmq

public SendResult send(Message msg, MessageQueue mq, long timeout)
  throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
  long beginStartTime = System.currentTimeMillis();
  this.makeSureStateOK();
  Validators.checkMessage(msg, this.defaultMQProducer);
  if (!msg.getTopic().equals(mq.getTopic())) {
    throw new MQClientException("message's topic not equal mq's topic", null);
  }
  long costTime = System.currentTimeMillis() - beginStartTime;
  if (timeout < costTime) {
    throw new RemotingTooMuchRequestException("call timeout");
  }
  return this.sendKernelImpl(msg, mq, CommunicationMode.SYNC, null, null, timeout);
}

代码示例来源:origin: apache/rocketmq

@Override
public void run() {
  try {
    makeSureStateOK();
    Validators.checkMessage(msg, defaultMQProducer);
    if (!msg.getTopic().equals(mq.getTopic())) {
      throw new MQClientException("message's topic not equal mq's topic", null);
    }
    long costTime = System.currentTimeMillis() - beginStartTime;
    if (timeout > costTime) {
      try {
        sendKernelImpl(msg, mq, CommunicationMode.ASYNC, sendCallback, null,
          timeout - costTime);
      } catch (MQBrokerException e) {
        throw new MQClientException("unknown exception", e);
      }
    } else {
      sendCallback.onException(new RemotingTooMuchRequestException("call timeout"));
    }
  } catch (Exception e) {
    sendCallback.onException(e);
  }
}

代码示例来源:origin: apache/rocketmq

public static Message cloneMessage(final Message msg) {
  Message newMsg = new Message(msg.getTopic(), msg.getBody());
  newMsg.setFlag(msg.getFlag());
  newMsg.setProperties(msg.getProperties());
  return newMsg;
}

代码示例来源:origin: apache/rocketmq

private SendResult sendSelectImpl(
  Message msg,
  MessageQueueSelector selector,
  Object arg,
  final CommunicationMode communicationMode,
  final SendCallback sendCallback, final long timeout
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
  long beginStartTime = System.currentTimeMillis();
  this.makeSureStateOK();
  Validators.checkMessage(msg, this.defaultMQProducer);
  TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
  if (topicPublishInfo != null && topicPublishInfo.ok()) {
    MessageQueue mq = null;
    try {
      mq = selector.select(topicPublishInfo.getMessageQueueList(), msg, arg);
    } catch (Throwable e) {
      throw new MQClientException("select message queue throwed exception.", e);
    }
    long costTime = System.currentTimeMillis() - beginStartTime;
    if (timeout < costTime) {
      throw new RemotingTooMuchRequestException("sendSelectImpl call timeout");
    }
    if (mq != null) {
      return this.sendKernelImpl(msg, mq, communicationMode, sendCallback, null, timeout - costTime);
    } else {
      throw new MQClientException("select message queue return null.", null);
    }
  }
  throw new MQClientException("No route info for this topic, " + msg.getTopic(), null);
}

代码示例来源:origin: apache/rocketmq

(SendMessageResponseHeader) response.decodeCommandCustomHeader(SendMessageResponseHeader.class);
MessageQueue messageQueue = new MessageQueue(msg.getTopic(), brokerName, responseHeader.getQueueId());

代码示例来源:origin: apache/rocketmq

private SendResult send(final Message message, long timeout) {
  checkMessageType(message);
  org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
  try {
    org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
    if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
      log.error(String.format("Send message to RocketMQ failed, %s", message));
      throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
    }
    message.sysHeaders().put(Message.BuiltinKeys.MESSAGE_ID, rmqResult.getMsgId());
    return OMSUtil.sendResultConvert(rmqResult);
  } catch (Exception e) {
    log.error(String.format("Send message to RocketMQ failed, %s", message), e);
    throw checkProducerException(rmqMessage.getTopic(), message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID), e);
  }
}

代码示例来源:origin: apache/rocketmq

@Override
public void sendMessageBefore(SendMessageContext context) {
  //if it is message trace data,then it doesn't recorded
  if (context == null || context.getMessage().getTopic().startsWith(((AsyncTraceDispatcher) localDispatcher).getTraceTopicName())) {
    return;
  }
  //build the context content of TuxeTraceContext
  TraceContext tuxeContext = new TraceContext();
  tuxeContext.setTraceBeans(new ArrayList<TraceBean>(1));
  context.setMqTraceContext(tuxeContext);
  tuxeContext.setTraceType(TraceType.Pub);
  tuxeContext.setGroupName(context.getProducerGroup());
  //build the data bean object of message trace
  TraceBean traceBean = new TraceBean();
  traceBean.setTopic(context.getMessage().getTopic());
  traceBean.setTags(context.getMessage().getTags());
  traceBean.setKeys(context.getMessage().getKeys());
  traceBean.setStoreHost(context.getBrokerAddr());
  traceBean.setBodyLength(context.getMessage().getBody().length);
  traceBean.setMsgType(context.getMsgType());
  tuxeContext.getTraceBeans().add(traceBean);
}

代码示例来源:origin: apache/rocketmq

long beginTimestampPrev = beginTimestampFirst;
long endTimestamp = beginTimestampFirst;
TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
if (topicPublishInfo != null && topicPublishInfo.ok()) {
  boolean callTimeout = false;
    times,
    System.currentTimeMillis() - beginTimestampFirst,
    msg.getTopic(),
    Arrays.toString(brokersSent));
throw new MQClientException("No route info of this topic, " + msg.getTopic() + FAQUrl.suggestTodo(FAQUrl.NO_TOPIC_ROUTE_INFO),
  null).setResponseCode(ClientErrorCode.NOT_FOUND_TOPIC_EXCEPTION);

代码示例来源:origin: apache/rocketmq

/**
 * Validate message
 */
public static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer)
  throws MQClientException {
  if (null == msg) {
    throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message is null");
  }
  // topic
  Validators.checkTopic(msg.getTopic());
  // body
  if (null == msg.getBody()) {
    throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message body is null");
  }
  if (0 == msg.getBody().length) {
    throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message body length is zero");
  }
  if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) {
    throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL,
      "the message body size over max value, MAX: " + defaultMQProducer.getMaxMessageSize());
  }
}

代码示例来源:origin: apache/rocketmq

@Override
public void sendMessageAfter(SendMessageContext context) {
  if (context == null || context.getMessage().getTopic().startsWith(((AsyncTraceDispatcher) localDispatcher).getTraceTopicName())
    || context.getMqTraceContext() == null) {
    return;

代码示例来源:origin: apache/rocketmq

private MessageExtBrokerInner makeOpMessageInner(Message message, MessageQueue messageQueue) {
  MessageExtBrokerInner msgInner = new MessageExtBrokerInner();
  msgInner.setTopic(message.getTopic());
  msgInner.setBody(message.getBody());
  msgInner.setQueueId(messageQueue.getQueueId());
  msgInner.setTags(message.getTags());
  msgInner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(msgInner.getTags()));
  msgInner.setSysFlag(0);
  MessageAccessor.setProperties(msgInner, message.getProperties());
  msgInner.setPropertiesString(MessageDecoder.messageProperties2String(message.getProperties()));
  msgInner.setBornTimestamp(System.currentTimeMillis());
  msgInner.setBornHost(this.storeHost);
  msgInner.setStoreHost(this.storeHost);
  msgInner.setWaitStoreMsgOK(false);
  MessageClientIDSetter.setUniqID(msgInner);
  return msgInner;
}

代码示例来源:origin: apache/rocketmq

System.out.println(messageByMsgId);
Assert.assertEquals(message.getTopic(), messageByMsgId.getTopic());
Assert.assertEquals(message.getTopic(), messageByOffset.getTopic());

代码示例来源:origin: apache/rocketmq

log.info("async send msg by retry {} times. topic={}, brokerAddr={}, brokerName={}", tmp, msg.getTopic(), addr,
  retryBrokerName);
try {

代码示例来源:origin: apache/rocketmq

requestHeader.setTopic(msg.getTopic());
requestHeader.setDefaultTopic(this.defaultMQProducer.getCreateTopicKey());
requestHeader.setDefaultTopicQueueNums(this.defaultMQProducer.getDefaultTopicQueueNums());

代码示例来源:origin: didi/DDMQ

public SendResult send(Message msg, MessageQueue mq, long timeout)
  throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
  this.makeSureStateOK();
  Validators.checkMessage(msg, this.defaultMQProducer);
  if (!msg.getTopic().equals(mq.getTopic())) {
    throw new MQClientException("message's topic not equal mq's topic", null);
  }
  return this.sendKernelImpl(msg, mq, CommunicationMode.SYNC, null, null, timeout);
}

代码示例来源:origin: didi/DDMQ

public void send(Message msg, MessageQueue mq, SendCallback sendCallback, long timeout)
  throws MQClientException, RemotingException, InterruptedException {
  this.makeSureStateOK();
  Validators.checkMessage(msg, this.defaultMQProducer);
  if (!msg.getTopic().equals(mq.getTopic())) {
    throw new MQClientException("message's topic not equal mq's topic", null);
  }
  try {
    this.sendKernelImpl(msg, mq, CommunicationMode.ASYNC, sendCallback, null, timeout);
  } catch (MQBrokerException e) {
    throw new MQClientException("unknown exception", e);
  }
}

代码示例来源:origin: didi/DDMQ

@Override
public void send(final Message message) {
  checkMessageType(message);
  org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
  try {
    Validators.checkMessage(rmqMessage, this.rocketmqProducer);
  } catch (MQClientException e) {
    throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
  }
  msgCacheQueue.add(message);
}

代码示例来源:origin: didi/DDMQ

private SendResult send(final Message message, long timeout) {
  checkMessageType(message);
  org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
  try {
    org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
    if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
      log.error(String.format("Send message to RocketMQ failed, %s", message));
      throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
    }
    message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
    return OMSUtil.sendResultConvert(rmqResult);
  } catch (Exception e) {
    log.error(String.format("Send message to RocketMQ failed, %s", message), e);
    throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
  }
}

代码示例来源:origin: didi/DDMQ

private SendMessageRequestHeader getMessageRequestHeader(Message msg, MessageQueue mq) {
  SendMessageRequestHeader requestHeader = new SendMessageRequestHeader();
  requestHeader.setProducerGroup(producer.getProducerGroup());
  requestHeader.setTopic(msg.getTopic());
  requestHeader.setDefaultTopic(producer.getCreateTopicKey());
  requestHeader.setDefaultTopicQueueNums(producer.getDefaultTopicQueueNums());
  requestHeader.setQueueId(mq.getQueueId());
  requestHeader.setSysFlag(0);
  requestHeader.setBornTimestamp(System.currentTimeMillis());
  requestHeader.setFlag(msg.getFlag());
  requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties()));
  requestHeader.setReconsumeTimes(0);
  requestHeader.setUnitMode(producer.isUnitMode());
  return requestHeader;
}

相关文章