alibaba/spring-cloud-alibaba · error · RuntimeException

convert to RocketMQ message failed.

Error message

convert to RocketMQ message failed.

What it means

The outer catch in convertMessage2MQ wraps any conversion failure (including the [135] null case, or charset/encoding exceptions) into RuntimeException('convert to RocketMQ message failed.', e). It is the umbrella error for all outbound payload-to-RocketMQ-message conversion problems.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/RocketMQMessageConverterSupport.java:133

				payloads = payload.getBytes(charset);
			}
			else if (payloadObj instanceof byte[] payload) {
				payloads = payload;
			}
			else {
				String jsonObj = (String) MESSAGE_CONVERTER.fromMessage(message,
						payloadObj.getClass());
				if (null == jsonObj) {
					throw new RuntimeException(String.format(
							"empty after conversion [messageConverter:%s,payloadClass:%s,payloadObj:%s]",
							MESSAGE_CONVERTER.getClass(), payloadObj.getClass(),
							payloadObj));
				}
				payloads = jsonObj.getBytes(charset);
			}
		}
		catch (Exception e) {
			throw new RuntimeException("convert to RocketMQ message failed.", e);
		}
		return getAndWrapMessage(topic, message.getHeaders(), payloads);
	}

	private static org.apache.rocketmq.common.message.Message getAndWrapMessage(
			String topic, MessageHeaders headers, byte[] payloads) {
		if (topic == null || topic.length() < 1) {
			throw new IllegalArgumentException("topic must not be empty");
		}
		if (payloads == null || payloads.length < 1) {
			throw new IllegalArgumentException("payload must not be empty");
		}
		org.apache.rocketmq.common.message.Message rocketMsg = new org.apache.rocketmq.common.message.Message(
				topic, payloads);
		if (Objects.nonNull(headers) && !headers.isEmpty()) {
			Object tag = headers.getOrDefault(Headers.TAGS,
					headers.get(toRocketHeaderKey(Headers.TAGS)));
			if (!ObjectUtils.isEmpty(tag)) {

View on GitHub (pinned to 115d590110)

Solutions

  1. Inspect the wrapped cause (`e`) - it is usually [135] or a charset/encoding error.
  2. Ensure a valid charset and a MessageConverter for the payload type.
  3. Set contentType correctly and pre-convert if necessary.
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate charset before conversion.
Charset cs;
try {
    cs = Charset.forName(mqProducerProperties.getCharset() != null
        ? mqProducerProperties.getCharset() : StandardCharsets.UTF_8.name());
} catch (Exception ex) {
    throw new IllegalArgumentException("Invalid charset for RocketMQ conversion", ex);
}

Try / catch

// Unwrap to diagnose the real conversion problem.
try {
    handler.handleMessage(msg);
} catch (RuntimeException ex) {
    if (ex.getMessage() != null && ex.getMessage().startsWith("convert to RocketMQ message failed")) {
        log.error("Conversion root cause: {}", ex.getCause());
    }
    throw ex;
}

Prevention

When it happens

Trigger: Any exception inside the conversion try block - fromMessage returning null ([135]), getBytes(charset) failing, or a converter throwing internally.

Common situations: A bad/unconfigured charset; a converter throwing on the specific payload; the [135] null-conversion bubbling up; a contentType mismatch causing the converter to throw.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/e6b58a180642c8f9. Report an issue: GitHub.