【发布时间】:2019-04-22 12:42:05
【问题描述】:
我有一个使用“stomp.py”库的 python 客户端,我使用该库将 XML 有效负载发送到 Spring Boot 微服务,该微服务具有反序列化 JMS 消息的实现。
我有一个简单的 python 类
class ActiveMqMessageProducer():
def active_mq_props(self):
active_mq_property = PropertyParser.PropertyParser().get_property(property_for='active-mq')
return {'username': active_mq_property['username'], 'password': active_mq_property['password'], 'topic': active_mq_property['topic']}
def active_mq_connection(self):
props = self.active_mq_props()
conn = stomp.StompConnection12()
conn.start()
conn.connect(username=props['username'], passcode=props['password'], wait=True)
return conn
def send_payload(self, payload):
props = self.active_mq_props()
conn = self.active_mq_connection()
conn.send(destination=f'/topic/{props["topic"]}', body=payload)
conn.disconnect()
当我发送以下有效负载时
<?xml version="1.0" encoding="utf-8"?>
<line timestamp="2018-03-14T14:03:11+0000" id="866381">
<total/>
</line>
到 Spring Boot 微服务我得到一个错误
threw exception; nested exception is java.lang.ClassCastException:
org.apache.activemq.command.ActiveMQBytesMessage cannot be cast to
org.apache.activemq.command.ActiveMQTextMessage.
我了解上述异常,但我无法在 python 客户端中设置正确的内容类型和标头,因此不会发生此异常。
我尝试了一些变化,但都徒劳无功。 有人可以阐明我需要在客户端中设置内容类型和标头的内容吗? 提前致谢。
【问题讨论】:
标签: python-3.x activemq stomp