老衲是一个 python 的脑残粉(可以看我的昵称),然后遇到一个有脑的问题
SpringBoot 搭建的 web 框架,里面集成了 rabbitmq 组建如下:
<!-- RabbitMQ 集成 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
然后将一些消息发送到 rabbitmq,后端用 celery 起了一堆 worker 来消费这些消息;
本来感觉这个架构很简单,实现起来很 easy,但是 celery 貌似对 json 对象处理有一些不兼容 JAVA 的 JSONobject ; 比如我将对象用 JSONObject 的 fromObject 方法转成 json 对象,然后发送到 MQ 中,celery 的 worker 就会报错:
[2018-11-19 14:21:52,895: CRITICAL/MainProcess] Can't decode message body: ContentDisallowed(u'Refusing to deserialize untrusted content of type application/x-java-serialized-object (application/x-java-serialized-object)',) [type:'application/x-java-serialized-object' encoding:None headers:{}]
...
Traceback (most recent call last):
File "/Users/cnbraid/.virtualenvs/celerytest/lib/python2.7/site-packages/celery/worker/consumer/consumer.py", line 553, in on_task_received
payload = message.decode()
File "/Users/cnbraid/.virtualenvs/celerytest/lib/python2.7/site-packages/kombu/message.py", line 192, in decode
self._decoded_cache = self._decode()
File "/Users/cnbraid/.virtualenvs/celerytest/lib/python2.7/site-packages/kombu/message.py", line 197, in _decode
self.content_encoding, accept=self.accept)
File "/Users/cnbraid/.virtualenvs/celerytest/lib/python2.7/site-packages/kombu/serialization.py", line 253, in loads
raise self._for_untrusted_content(content_type, 'untrusted')
ContentDisallowed: Refusing to deserialize untrusted content of type application/x-java-serialized-object (application/x-java-serialized-object)
我理解的意思是 celery 无法处理(application/x-java-serialized-object)这种对象吧?
这种情况该怎么解决呢? 我其实还是想用 celery 的,好处是起 worker 简单,easy,但是就是报上面的错误
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.