通过 ActiveMQ Broker 插件获取 AMQ 消息

Get AMQ Message via ActiveMQ Broker Plugin

我已经使用 BrokerFilter Class 实现了自定义 ActiveMQ 代理插件。我已经重写了如下所示的发送方法。

public void send(final ProducerBrokerExchange producerExchange, final Message messageSend) throws Exception {

     logger.info("Message  : " + messageSend);
     // Returns the JMS Type of Mesage
     logger.info("Message Type  : " +  messageSend.getType());

     // Lookig for method to get the message text
        ?

}

日志的第一行显示了对象中的消息文本,但似乎没有可用的方法来获取消息文本。

    INFO | Message : ActiveMQTextMessage {commandId = 5, responseRequired = false, messageId = ID:192.168.10.6-63132-1613444356003-4:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:192.168.10.6-63132-1613444356003-4:1:1:1, destination = topic://reporting, transactionId = null, expiration = 0, timestamp = 1613444364819, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = , replyTo = null, persistent = false, type = NewAgent, priority = 0, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, **text = Hello** }

    INFO | getType : New

有人可以指导我使用适当的 class 或 get/intercept 消息文本的方法吗?我的目标是获取消息text/body并将其存储在redis中。

您需要弄清楚它是什么类型的消息并对其进行转换,以便从消息中获取文本(或其他内容)。尝试类似的东西:

public void send(final ProducerBrokerExchange producerExchange, final Message messageSend) throws Exception {

  logger.info("Message  : " + messageSend);
  // Returns the JMS Type of Mesage
  logger.info("Message Type  : " +  messageSend.getType());
  logger.info("Message Class : " + messageSend.getClass().toString());
  // Lookig for method to get the message text
  
  if (messageSend instanceof ActiveMQTextMessage) {
    ActiveMQTextMessage txtMsg = (ActiveMQTextMessage)messageSend;
    Logger.info("Message Text : " + txtMsg.getText();
  }

}

Text message 文档。