@Test public void testConvertToRocketMessageWithMessageConvert() { Message msgWithStringPayload = MessageBuilder.withPayload("test body") .setHeader("test", 1) .setHeader(RocketMQHeaders.TAGS, "tags") .setHeader(RocketMQHeaders.KEYS, "my_keys") .build(); RocketMQMessageConverter messageConverter = new RocketMQMessageConverter(); org.apache.rocketmq.common.message.Message rocketMsg = RocketMQUtil.convertToRocketMessage(messageConverter.getMessageConverter(), "UTF-8", "test-topic", msgWithStringPayload); assertEquals("1", rocketMsg.getProperty("test")); assertNull(rocketMsg.getProperty(RocketMQHeaders.TAGS)); assertEquals("my_keys", rocketMsg.getProperty(RocketMQHeaders.KEYS)); Message msgWithBytesPayload = MessageBuilder.withPayload("123".getBytes()).build(); org.apache.rocketmq.common.message.Message rocketMsgWithObj = RocketMQUtil.convertToRocketMessage(messageConverter.getMessageConverter(), "UTF-8", "test-topic", msgWithBytesPayload); assertEquals("123", new String(rocketMsgWithObj.getBody())); }
@Deprecated public static org.apache.rocketmq.common.message.Message convertToRocketMessage( ObjectMapper objectMapper, String charset, String destination, org.springframework.messaging.Message message) { Object payloadObj = message.getPayload(); byte[] payloads; if (payloadObj instanceof String) { payloads = ((String) payloadObj).getBytes(Charset.forName(charset)); } else if (payloadObj instanceof byte[]) { payloads = (byte[]) message.getPayload(); } else { try { String jsonObj = objectMapper.writeValueAsString(payloadObj); payloads = jsonObj.getBytes(Charset.forName(charset)); } catch (Exception e) { throw new RuntimeException("convert to RocketMQ message failed.", e); } } return getAndWrapMessage(destination, message.getHeaders(), payloads); }
RocketMQUtil { @Deprecated public static org.apache.rocketmq.common.message.Message convertToRocketMessage( ObjectMapper objectMapper, String charset, String destination, org.springframework.messaging.Message message) { Object payloadObj = message.getPayload(); byte[] payloads; if (payloadObj instanceof String) { payloads = ((String) payloadObj).getBytes(Charset.forName(charset)); } else if (payloadObj instanceof byte[]) { payloads = (byte[]) message.getPayload(); } else { try { String jsonObj = objectMapper.writeValueAsString(payloadObj); payloads = jsonObj.getBytes(Charset.forName(charset)); } catch (Exception e) { throw new RuntimeException("convert to RocketMQ message failed.", e); } } return getAndWrapMessage(destination, message.getHeaders(), payloads); } }
RocketMQUtil { @Deprecated public static org.apache.rocketmq.common.message.Message convertToRocketMessage( ObjectMapper objectMapper, String charset, String destination, org.springframework.messaging.Message message) { Object payloadObj = message.getPayload(); byte[] payloads; if (payloadObj instanceof String) { payloads = ((String) payloadObj).getBytes(Charset.forName(charset)); } else if (payloadObj instanceof byte[]) { payloads = (byte[]) message.getPayload(); } else { try { String jsonObj = objectMapper.writeValueAsString(payloadObj); payloads = jsonObj.getBytes(Charset.forName(charset)); } catch (Exception e) { throw new RuntimeException("convert to RocketMQ message failed.", e); } } return getAndWrapMessage(destination, message.getHeaders(), payloads); }  }
RocketMQUtil { @Deprecated public static org.apache.rocketmq.common.message.Message convertToRocketMessage( ObjectMapper objectMapper, String charset, String destination, org.springframework.messaging.Message message) { Object payloadObj = message.getPayload(); byte[] payloads; if (payloadObj instanceof String) { payloads = ((String) payloadObj).getBytes(Charset.forName(charset)); } else if (payloadObj instanceof byte[]) { payloads = (byte[]) message.getPayload(); } else { try { String jsonObj = objectMapper.writeValueAsString(payloadObj); payloads = jsonObj.getBytes(Charset.forName(charset)); } catch (Exception e) { throw new RuntimeException("convert to RocketMQ message failed.", e); } } return getAndWrapMessage(destination, message.getHeaders(), payloads); }  static TransactionListener convert(RocketMQLocalTransactionListener listener); static MessagingException convert(MQClientException e); static org.springframework.messaging.Message convertToSpringMessage(
        org.apache.rocketmq.common.message.MessageExt message); static String toRocketHeaderKey(String rawKey); static org.springframework.messaging.Message convertToSpringMessage(
        org.apache.rocketmq.common.message.Message message); @Deprecated static org.apache.rocketmq.common.message.Message convertToRocketMessage(
        ObjectMapper objectMapper, String charset,
        String destination, org.springframework.messaging.Message message); static org.apache.rocketmq.common.message.Message convertToRocketMessage(
        MessageConverter messageConverter, String charset,
        String destination, org.springframework.messaging.Message<?> message); static RPCHook getRPCHookByAkSk(Environment env, String accessKeyOrExpr, String secretKeyOrExpr); static DefaultMQProducer createDefaultMQProducer(String groupName, String ak, String sk,
        boolean isEnableMsgTrace, String customizedTraceTopic); }
RocketMQUtil { @Deprecated public static org.apache.rocketmq.common.message.Message convertToRocketMessage( ObjectMapper objectMapper, String charset, String destination, org.springframework.messaging.Message message) { Object payloadObj = message.getPayload(); byte[] payloads; if (payloadObj instanceof String) { payloads = ((String) payloadObj).getBytes(Charset.forName(charset)); } else if (payloadObj instanceof byte[]) { payloads = (byte[]) message.getPayload(); } else { try { String jsonObj = objectMapper.writeValueAsString(payloadObj); payloads = jsonObj.getBytes(Charset.forName(charset)); } catch (Exception e) { throw new RuntimeException("convert to RocketMQ message failed.", e); } } return getAndWrapMessage(destination, message.getHeaders(), payloads); }  static TransactionListener convert(RocketMQLocalTransactionListener listener); static MessagingException convert(MQClientException e); static org.springframework.messaging.Message convertToSpringMessage(
        org.apache.rocketmq.common.message.MessageExt message); static String toRocketHeaderKey(String rawKey); static org.springframework.messaging.Message convertToSpringMessage(
        org.apache.rocketmq.common.message.Message message); @Deprecated static org.apache.rocketmq.common.message.Message convertToRocketMessage(
        ObjectMapper objectMapper, String charset,
        String destination, org.springframework.messaging.Message message); static org.apache.rocketmq.common.message.Message convertToRocketMessage(
        MessageConverter messageConverter, String charset,
        String destination, org.springframework.messaging.Message<?> message); static RPCHook getRPCHookByAkSk(Environment env, String accessKeyOrExpr, String secretKeyOrExpr); static DefaultMQProducer createDefaultMQProducer(String groupName, String ak, String sk,
        boolean isEnableMsgTrace, String customizedTraceTopic);  }