注意他们的老大:public interface Message
- @see javax.jms.MessageConsumer#receive()
- @see javax.jms.MessageConsumer#receive(long)
- @see javax.jms.MessageConsumer#receiveNoWait()
- @see javax.jms.MessageListener#onMessage(Message)
- @see javax.jms.BytesMessage
- @see javax.jms.MapMessage
- @see javax.jms.ObjectMessage
- @see javax.jms.StreamMessage
- @see javax.jms.TextMessage
ActiveMQBytesMessage :内容为data = {“id”:“101”,“type”:10,“name”:“Lucy”}
ActiveMQTextMessage: {commandId = 5, responseRequired = true, messageId = ID:localhost.localdomain-33927-1627368748710-1:4:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:localhost.localdomain-33927-1627368748710-1:4:1:1, destination = topic://textTopic, transactionId = null, expiration = 0, timestamp = 1627368840034, arrival = 0, brokerInTime = 1627368840035, brokerOutTime = 1627368840038, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@5ded348a, marshalledProperties = org.apache.activemq.util.ByteSequence@6b352ef2, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {timestamp=1627368840016}, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = {“id”:“101”,“type”:10,“name”:“Lucy”}}
@JmsListener(destination = "dataTopic", containerFactory = "topicListener")
public void receiveDataTopic(Object message) {
ActiveMQBytesMessage msg = (ActiveMQBytesMessage) message;
String data = new String(msg.getMessage().getContent().getData());
}
@JmsListener(destination = "textTopic", containerFactory = "topicListener")
public void receiveTextTopic(Object message) {
String text = null;
try {
text = ((TextMessage) message).getText();
} catch (JMSException e) {
log.error("MQTT消息转换异常");
return;
}
}