paascloud/paascloud-master · error · IllegalArgumentException
处理MQ信息,JSON转换异常
Error message
处理MQ信息,JSON转换异常
What it means
IllegalArgumentException("处理MQ信息,JSON转换异常") thrown by OptSendEmailTopicConsumer.handlerSendEmailTopic when the email-topic message body cannot be parsed into PcSendEmailRequest. The topic consumer expects a JSON payload produced by the email producer; any parse failure aborts handling so the broker can dead-letter the bad message.
Solutions
- Inspect the logged message body to confirm whether it is malformed JSON or a field mismatch
- Align the producer's serialization (JacksonUtil.toJson) with PcSendEmailRequest and redeploy both sides
- Verify the right topic is used for email vs sms messages
- Republish a correctly serialized PcSendEmailRequest to flush the queue
Example fix
// before
request = JacksonUtil.parseJson(body, PcSendEmailRequest.class);
// after
if (PublicUtil.isEmpty(body)) { log.warn("skip empty email body, topic={}", topicName); return; }
request = JacksonUtil.parseJson(body, PcSendEmailRequest.class); Defensive patterns
Strategy: try-catch
Validate before calling
if (PublicUtil.isEmpty(body)) { log.warn("skip empty email MQ body"); return; }
// producer side:
MqMessage.checkMessage(body, keys, topicName); Try / catch
try {
request = JacksonUtil.parseJson(body, PcSendEmailRequest.class);
} catch (Exception e) {
log.error("bad email MQ body={}", body, e);
return; // dead-letter instead of rethrowing into infinite retry
} Prevention
- Publish only Jackson-serialized PcSendEmailRequest to the email topic
- Separate email and sms topics/DTOs to avoid cross-publishing
- Version the message schema and deploy producer/consumer together
- Log the raw body on parse failure for diagnosis
When it happens
Trigger: MQ body on the send-email topic is not valid JSON for PcSendEmailRequest: null/empty body (partially guarded by MqMessage.checkMessage), wrong field names/types versus the DTO, or a producer sending a legacy payload format.
Common situations: Version skew after adding/removing fields on PcSendEmailRequest; producer accidentally sends the SMS request object to the email topic; body passed through toString instead of Jackson serialization; charset/encoding corruption in transit.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/8566eb522d660815.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/consumer/OptSendEmailTopicConsumer.java:51
@Resource
private OptSendMailService optSendMailService;
/**
* Handler send email topic.
*
* @param body the body
* @param topicName the topic name
* @param tags the tags
* @param keys the keys
*/
public void handlerSendEmailTopic(String body, String topicName, String tags, String keys) {
MqMessage.checkMessage(body, keys, topicName);
PcSendEmailRequest request;
try {
request = JacksonUtil.parseJson(body, PcSendEmailRequest.class);
} catch (Exception e) {
log.error("发送短信MQ出现异常={}", e.getMessage(), e);
throw new IllegalArgumentException("处理MQ信息,JSON转换异常");
}
String subject = request.getSubject();
String text = request.getText();
Set<String> to = request.getTo();
optSendMailService.sendTemplateMail(subject, text, to);
}
}
View on GitHub (pinned to 781281a950)