in rocketmq-jms/core/src/main/java/org/apache/rocketmq/jms/domain/JmsBaseMessageProducer.java [161:190]
public void send(Destination destination, javax.jms.Message message) throws JMSException {
JmsBaseMessage jmsMsg = (JmsBaseMessage) message;
initJMSHeaders(jmsMsg, destination);
try {
if (context == null) {
throw new IllegalStateException("Context should be inited");
}
org.apache.rocketmq.common.message.Message rocketmqMsg = MessageConverter.convert2RMQMessage(jmsMsg);
MQProducer producer = producerMap.get(context.getProducerId());
if (producer == null) {
throw new Exception("producer is null ");
}
SendResult sendResult = producer.send(rocketmqMsg);
if (sendResult != null && sendResult.getSendStatus() == SendStatus.SEND_OK) {
jmsMsg.setHeader(JmsBaseConstant.JMS_MESSAGE_ID, "ID:" + sendResult.getMsgId());
} else {
throw new Exception("SendResult is " + (sendResult == null ? "null" : sendResult.toString()));
}
}
catch (Exception e) {
logger.error("Send rocketmq message failure !", e);
//if fail to send the message, throw out JMSException
JMSException jmsException = new JMSException("Send rocketmq message failure!");
jmsException.setLinkedException(e);
throw jmsException;
}
}