【问题标题】:How to send XML message from Python Client to a Spring boot microservice如何将 XML 消息从 Python 客户端发送到 Spring Boot 微服务
【发布时间】: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


    【解决方案1】:

    我已经解决了这个问题,除了简单地添加到我现有的代码之外没有做任何更改。就这么简单

    conn = stomp.StompConnection12(auto_content_length=False).
    

    信息有点隐藏,位于 stomp 协议文档中。 但是,如果有人遇到与我类似的问题,上面的代码解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2017-08-16
      • 2016-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-09
      • 2017-09-15
      • 1970-01-01
      相关资源
      最近更新 更多