java - 通过 ActiveMQ 代理插件获取 AMQ 消息
问题描述
我已经使用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 中。
解决方案
您需要弄清楚它是什么类型的消息并将其转换为从消息中获取文本(或其他内容)。尝试类似:
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();
}
}
短信文档。
推荐阅读
- c++ - 从 C++ 中的字符串中获取 +/- 整数
- javascript - NextJS - 使用浅路由器推送时无法识别页面组件上发生状态变化的位置
- java - 在 Java 中语义使用变量名
- python - 使用成像器对图像进行一些调整后如何在 R Keras 中加载图像
- c++ - Unix Semaphore - unable to set initial value
- dart - 如何在颤动中缓存 rxdart 流以实现无限滚动
- c++ - C++ WINAPI 异常未处理堆栈溢出之前到达代码
- c++ - 通过引用传递对 lambda 的引用
- linux - Kubernetes 工作空间中的持久卷和声明
- css - 将元素放置在“闪亮”应用程序中,以便它们调整移动和桌面显示器的大小