use of com.yanghui.elephant.common.protocol.header.SendMessageRequestHeader in project elephant by yanghuijava.
the class DefaultMQProducerImpl method send.
public SendResult send(Message msg) throws MQClientException {
checkMessage(msg, defaultMQProducer);
SendResult result = new SendResult();
SendMessageRequestHeader requestHeader = new SendMessageRequestHeader();
requestHeader.setDestination(msg.getDestination());
requestHeader.setMessageId(msg.getMessageId());
requestHeader.setProducerGroup(this.defaultMQProducer.getProducerGroup());
requestHeader.setProperties(JSON.toJSONString(msg.getProperties()));
String MessageTypeName = msg.getProperties().get(MessageConstant.PROPERTY_TRANSACTION_PREPARED);
requestHeader.setMessageType(MessageType.valueOfName(MessageTypeName).getType());
RemotingCommand request = RemotingCommand.buildRequestCmd(requestHeader, RequestCode.SEND_MESSAGE);
request.setBody(msg.getBody());
MQClientException exception = null;
int timesTotal = 1 + this.defaultMQProducer.getRetryTimesWhenSendFailed();
result.setMsgId(msg.getMessageId());
for (int times = 0; times < timesTotal; times++) {
try {
RemotingCommand response = this.mqProducerFactory.getRemotingClient().invokeSync(choiceOneServer(), request, this.defaultMQProducer.getSendMsgTimeout());
switch(response.getCode()) {
case ResponseCode.SUCCESS:
result.setSendStatus(SendStatus.SEND_OK);
break;
case ResponseCode.FUSH_DB_FAIL:
result.setSendStatus(SendStatus.FLUSH_DB_FAIL);
break;
case ResponseCode.SEND_MQ_FAIL:
result.setSendStatus(SendStatus.SEND_MQ_FAIL);
break;
case ResponseCode.SERVER_FAIL:
result.setSendStatus(SendStatus.SERVER_FAIL);
break;
default:
result.setSendStatus(SendStatus.SEND_FAIL);
break;
}
return result;
} catch (RemotingTimeoutException e) {
result.setSendStatus(SendStatus.FLUSH_DISK_TIMEOUT);
break;
} catch (Exception e) {
exception = new MQClientException("message send exception", e);
continue;
}
}
if (exception != null) {
throw exception;
}
return result;
}
use of com.yanghui.elephant.common.protocol.header.SendMessageRequestHeader in project elephant by yanghuijava.
the class MessageRequestProcessor method processRequest.
@Override
public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) {
log.info("处理请求消息:{}", request);
SendMessageRequestHeader requestHeader = (SendMessageRequestHeader) request.decodeCommandCustomHeader(SendMessageRequestHeader.class);
switch(MessageType.valueOf(requestHeader.getMessageType())) {
case NORMAL_MESSAGE:
return normalMessageHandle(requestHeader, request);
case TRANSACTION_PRE_MESSAGE:
return transactionMessageHandle(requestHeader, request);
default:
break;
}
return null;
}
Aggregations