【问题标题】:Get AMQ Message via ActiveMQ Broker Plugin通过 ActiveMQ 代理插件获取 AMQ 消息
【发布时间】:2021-02-16 03:56:21
【问题描述】:

我已经使用BrokerFilter 类实现了一个自定义 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

有人可以指导我使用适当的类或方法来获取/拦截消息文本吗?我的目标是获取消息文本/正文并将其存储在 redis 中。

【问题讨论】:

    标签: java activemq


    【解决方案1】:

    您需要弄清楚它是什么类型的消息并将其转换为从消息中获取文本(或其他内容)。尝试类似:

    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 文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-14
      • 2016-04-14
      • 1970-01-01
      • 2011-12-05
      • 2018-03-01
      • 2020-11-01
      相关资源
      最近更新 更多