Java Code Examples for org.apache.rocketmq.common.message.MessageExt#getUserProperty()
The following examples show how to use
org.apache.rocketmq.common.message.MessageExt#getUserProperty() .
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: DeFiBusClientRemotingProcessor.java From DeFiBus with Apache License 2.0 | 6 votes |
private void processResponse(MessageExt msg) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("receive reply message :{}", msg); } final String uniqueId = msg.getUserProperty(DeFiBusConstant.PROPERTY_RR_REQUEST_ID); RRResponseFuture rrResponseFuture = ResponseTable.getRrResponseFurtureConcurrentHashMap().get(uniqueId); if (rrResponseFuture != null && !rrResponseFuture.release()) { if (rrResponseFuture.getRrCallback() != null) { rrResponseFuture.getRrCallback().onSuccess(msg); ResponseTable.getRrResponseFurtureConcurrentHashMap().remove(uniqueId); } else { rrResponseFuture.putResponse(msg); } } else { LOGGER.warn("receive reply message {} , but requester has gone away", msg.toString()); } }
Example 2
Source File: DeFiBusClientUtil.java From DeFiBus with Apache License 2.0 | 6 votes |
public static Message createReplyMessage(MessageExt sourceMsg, byte[] content) { String cluster = sourceMsg.getUserProperty(DeFiBusConstant.PROPERTY_MESSAGE_CLUSTER); String replyTopic = DeFiBusConstant.RR_REPLY_TOPIC; if (!StringUtils.isEmpty(cluster)) { replyTopic = cluster + "-" + replyTopic; } else { LOGGER.warn("no cluster info from message, can not reply"); return null; } Message msg = new Message(); msg.setTopic(replyTopic);//回程topic msg.setBody(content);//body msg.putUserProperty(DeFiBusConstant.PROPERTY_MESSAGE_REPLY_TO, sourceMsg.getUserProperty(DeFiBusConstant.PROPERTY_MESSAGE_REPLY_TO));//回给谁 msg.putUserProperty(DeFiBusConstant.PROPERTY_RR_REQUEST_ID, sourceMsg.getUserProperty(DeFiBusConstant.PROPERTY_RR_REQUEST_ID));//原uniqueId String sourceBroker = sourceMsg.getUserProperty(DeFiBusConstant.PROPERTY_MESSAGE_BROKER); if (!StringUtils.isEmpty(sourceBroker)) { msg.putUserProperty(DeFiBusConstant.PROPERTY_MESSAGE_BROKER, sourceBroker);//消息从哪个broker来 } return msg; }
Example 3
Source File: ClientRemotingProcessor.java From rocketmq with Apache License 2.0 | 6 votes |
private void processReplyMessage(MessageExt replyMsg) { final String correlationId = replyMsg.getUserProperty(MessageConst.PROPERTY_CORRELATION_ID); final RequestResponseFuture requestResponseFuture = RequestFutureTable.getRequestFutureTable().get(correlationId); if (requestResponseFuture != null) { requestResponseFuture.putResponseMessage(replyMsg); RequestFutureTable.getRequestFutureTable().remove(correlationId); if (requestResponseFuture.getRequestCallback() != null) { requestResponseFuture.getRequestCallback().onSuccess(replyMsg); } else { requestResponseFuture.putResponseMessage(replyMsg); } } else { String bornHost = replyMsg.getBornHostString(); log.warn(String.format("receive reply message, but not matched any request, CorrelationId: %s , reply from host: %s", correlationId, bornHost)); } }
Example 4
Source File: TransactionalMessageServiceImpl.java From rocketmq with Apache License 2.0 | 6 votes |
/** * If return true, skip this msg * * @param removeMap Op message map to determine whether a half message was responded by producer. * @param doneOpOffset Op Message which has been checked. * @param msgExt Half message * @return Return true if put success, otherwise return false. */ private boolean checkPrepareQueueOffset(HashMap<Long, Long> removeMap, List<Long> doneOpOffset, MessageExt msgExt) { String prepareQueueOffsetStr = msgExt.getUserProperty(MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET); if (null == prepareQueueOffsetStr) { return putImmunityMsgBackToHalfQueue(msgExt); } else { long prepareQueueOffset = getLong(prepareQueueOffsetStr); if (-1 == prepareQueueOffset) { return false; } else { if (removeMap.containsKey(prepareQueueOffset)) { long tmpOpOffset = removeMap.remove(prepareQueueOffset); doneOpOffset.add(tmpOpOffset); return true; } else { return putImmunityMsgBackToHalfQueue(msgExt); } } } }
Example 5
Source File: TransactionalMessageBridge.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
public MessageExtBrokerInner renewImmunityHalfMessageInner(MessageExt msgExt) { MessageExtBrokerInner msgInner = renewHalfMessageInner(msgExt); String queueOffsetFromPrepare = msgExt.getUserProperty(MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET); if (null != queueOffsetFromPrepare) { MessageAccessor.putProperty(msgInner, MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET, String.valueOf(queueOffsetFromPrepare)); } else { MessageAccessor.putProperty(msgInner, MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET, String.valueOf(msgExt.getQueueOffset())); } msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgInner.getProperties())); return msgInner; }
Example 6
Source File: TransactionalMessageServiceImpl.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
/** * If return true, skip this msg * * @param removeMap Op message map to determine whether a half message was responded by producer. * @param doneOpOffset Op Message which has been checked. * @param msgExt Half message * @param checkImmunityTime User defined time to avoid being detected early. * @return Return true if put success, otherwise return false. */ // private boolean checkPrepareQueueOffset(HashMap<Long, Long> removeMap, List<Long> doneOpOffset, MessageExt msgExt, long checkImmunityTime) { if (System.currentTimeMillis() - msgExt.getBornTimestamp() < checkImmunityTime) { String prepareQueueOffsetStr = msgExt.getUserProperty(MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET); if (null == prepareQueueOffsetStr) { return putImmunityMsgBackToHalfQueue(msgExt); } else { long prepareQueueOffset = getLong(prepareQueueOffsetStr); if (-1 == prepareQueueOffset) { return false; } else { if (removeMap.containsKey(prepareQueueOffset)) { long tmpOpOffset = removeMap.remove(prepareQueueOffset); doneOpOffset.add(tmpOpOffset); return true; } else { return putImmunityMsgBackToHalfQueue(msgExt); } } } } else { return true; } }
Example 7
Source File: TransactionalMessageBridge.java From rocketmq-read with Apache License 2.0 | 5 votes |
public MessageExtBrokerInner renewImmunityHalfMessageInner(MessageExt msgExt) { MessageExtBrokerInner msgInner = renewHalfMessageInner(msgExt); String queueOffsetFromPrepare = msgExt.getUserProperty(MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET); if (null != queueOffsetFromPrepare) { MessageAccessor.putProperty(msgInner, MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET, String.valueOf(queueOffsetFromPrepare)); } else { MessageAccessor.putProperty(msgInner, MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET, String.valueOf(msgExt.getQueueOffset())); } msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgInner.getProperties())); return msgInner; }
Example 8
Source File: TransactionalMessageServiceImpl.java From rocketmq-read with Apache License 2.0 | 5 votes |
/** * If return true, skip this msg * * @param removeMap Op message map to determine whether a half message was responded by producer. * @param doneOpOffset Op Message which has been checked. * @param msgExt Half message * @param checkImmunityTime User defined time to avoid being detected early. * @return Return true if put success, otherwise return false. */ private boolean checkPrepareQueueOffset(HashMap<Long, Long> removeMap, List<Long> doneOpOffset, MessageExt msgExt, long checkImmunityTime) { if (System.currentTimeMillis() - msgExt.getBornTimestamp() < checkImmunityTime) { String prepareQueueOffsetStr = msgExt.getUserProperty(MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET); if (null == prepareQueueOffsetStr) { return putImmunityMsgBackToHalfQueue(msgExt); } else { long prepareQueueOffset = getLong(prepareQueueOffsetStr); if (-1 == prepareQueueOffset) { return false; } else { if (removeMap.containsKey(prepareQueueOffset)) { long tmpOpOffset = removeMap.remove(prepareQueueOffset); doneOpOffset.add(tmpOpOffset); return true; } else { return putImmunityMsgBackToHalfQueue(msgExt); } } } } else { return true; } }
Example 9
Source File: TransactionalMessageBridge.java From rocketmq with Apache License 2.0 | 5 votes |
public MessageExtBrokerInner renewImmunityHalfMessageInner(MessageExt msgExt) { MessageExtBrokerInner msgInner = renewHalfMessageInner(msgExt); String queueOffsetFromPrepare = msgExt.getUserProperty(MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET); if (null != queueOffsetFromPrepare) { MessageAccessor.putProperty(msgInner, MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET, String.valueOf(queueOffsetFromPrepare)); } else { MessageAccessor.putProperty(msgInner, MessageConst.PROPERTY_TRANSACTION_PREPARED_QUEUE_OFFSET, String.valueOf(msgExt.getQueueOffset())); } msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgInner.getProperties())); return msgInner; }
Example 10
Source File: TransactionProducer.java From rocketmq with Apache License 2.0 | 4 votes |
@Override public LocalTransactionState checkLocalTransaction(MessageExt msg) { MsgMeta msgMeta = parseFromMsg(msg); if (msgMeta.batchId != sendConfig.batchId) { // message not generated in this test return LocalTransactionState.ROLLBACK_MESSAGE; } statBenchmark.getCheckCount().incrementAndGet(); int times = 0; try { String checkTimes = msg.getUserProperty(MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES); times = Integer.parseInt(checkTimes); } catch (Exception e) { return LocalTransactionState.ROLLBACK_MESSAGE; } times = times <= 0 ? 1 : times; boolean dup; synchronized (cache) { Integer oldCheckLog = cache.get(msgMeta.msgId); Integer newCheckLog; if (oldCheckLog == null) { newCheckLog = 1 << (times - 1); } else { newCheckLog = oldCheckLog | (1 << (times - 1)); } dup = newCheckLog.equals(oldCheckLog); } if (dup) { statBenchmark.getDuplicatedCheckCount().incrementAndGet(); } if (msgMeta.sendResult != LocalTransactionState.UNKNOW) { System.out.printf("%s unexpected check: msgId=%s,txId=%s,checkTimes=%s,sendResult=%s\n", new SimpleDateFormat("HH:mm:ss,SSS").format(new Date()), msg.getMsgId(), msg.getTransactionId(), msg.getUserProperty(MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES), msgMeta.sendResult.toString()); statBenchmark.getUnexpectedCheckCount().incrementAndGet(); return msgMeta.sendResult; } for (int i = 0; i < times - 1; i++) { LocalTransactionState s = msgMeta.checkResult.get(i); if (s != LocalTransactionState.UNKNOW) { System.out.printf("%s unexpected check: msgId=%s,txId=%s,checkTimes=%s,sendResult,lastCheckResult=%s\n", new SimpleDateFormat("HH:mm:ss,SSS").format(new Date()), msg.getMsgId(), msg.getTransactionId(), msg.getUserProperty(MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES), s); statBenchmark.getUnexpectedCheckCount().incrementAndGet(); return s; } } return msgMeta.checkResult.get(times - 1); }