0

我调用了一个 rabbitmq 队列,它返回一个 json 有效负载。

        <inSequence>
            <call>
                <endpoint>
                    <address statistics="enable" trace="enable" uri="rabbitmq:/AMQPProducerSample?rabbitmq.server.host.name=10.0.0.2&amp;rabbitmq.server.port=5672&amp;rabbitmq.server.virtual.host=dev&amp;rabbitmq.server.vhost=devAuth&amp;rabbitmq.queue.name=hello&amp;rabbitmq.queue.durable=false&amp;rabbitmq.queue.auto.ack=true&amp;rabbitmq.queue.exclusive=false&amp;rabbitmq.replyto.name=false">
                        <suspendOnFailure>
                            <initialDuration>-1</initialDuration>
                            <progressionFactor>-1</progressionFactor>
                            <maximumDuration>0</maximumDuration>
                        </suspendOnFailure>
                        <markForSuspension>
                            <retriesBeforeSuspension>0</retriesBeforeSuspension>
                        </markForSuspension>
                    </address>
                </endpoint>
            </call>
            <header name="Content-Type" scope="transport" value="application/json"/>
            <respond description="respond whatever"/>
        </inSequence>

但是当队列的答案返回时,控制台显示: [2020-10-19 19:20:39,741] WARN {RabbitMQUtils} - Unable to determine content type for message urn:uuid:88BF095D7137B387921603153239744 setting to text/plain

并将“文本”添加到我已经 json 有效负载中: {“text”:“{“jwt”:“5f8e2d21c2184”,“error”:false}“}

如何将 rabbitmq 的答案设置为 json,还是需要转换该答案?因为它得到所有条形保护。

4

2 回答 2

0

答案的类型由端点设置为消息的属性,如 de rabbitmq 文档所述: https ://www.rabbitmq.com/consumers.html#message-properties 如果使用 php rabbitmq 库添加'content_type'=>'application_json'到消息的属性数组。

于 2020-10-21T20:19:49.323 回答
0

请尝试以下 Synapse 工件。

<proxy xmlns="http://ws.apache.org/ns/synapse"
    name="RabbitMQRPCProxy"
    startOnLoad="true"
    trace="enable"
       transports="http">
   <description/>
   <target>
    <inSequence>
        <log level="full">
            <property name="received" value="true"/>
        </log>
        <call>
            <endpoint>
                 <address uri="rabbitmq://?rabbitmq.server.host.name=localhost&amp;rabbitmq.server.port=5672&amp;rabbitmq.server.user.name=guest&amp;rabbitmq.server.password=guest&amp;rabbitmq.queue.name=rpc_queue&amp;rabbitmq.queue.routing.key=rpc_queue&amp;rabbitmq.replyto.name=dummy"/>
            </endpoint>
        </call>
        <log level="full">
            <property name="response" value="true"/>
        </log>
        <respond/>
    </inSequence>
    <outSequence/>
   </target>
</proxy>

这里,

  • 当 WSO2 Enterprise Integrator(WSO2 EI) 启动时,它会创建一个匿名的、独占的回调队列。
  • 对于远程过程调用请求,WSO2 EI 发送具有以下属性的消息:
    • reply_to:设置为回调队列
    • correlation_id:这被设置为每个请求的唯一值。
  • 然后将请求发送到 rpc_queue。
  • RPC 服务器等待该队列上的请求。当出现请求时,它会执行该工作并将带有结果的消息发送回 WSO2 EI 服务器,使用来自 reply_to 字段的队列具有相同的相关 ID。
  • WSO2 EI 等待reply_to队列中的数据。当出现一条消息时,它会检查correlation_id 属性。如果它与请求中的值匹配,则将响应返回给应用程序。

有关更多详细信息,请查看 RabbitMQ侦听器和发送者文档。

于 2020-10-20T04:17:37.323 回答