WSO2 esb 4.9.0支持Json pub sub

时间:2016-07-08 04:35:26

标签: wso2 wso2esb publish-subscribe

目前,当我在WSO2 ESB 4.9.0上设置主题时,pub / sub只向我发送soap信封消息给订户端点。我们可以按原样发送传入消息来设置ESB吗?

当我发送消息以发布如下主题时,我会收到以下soap信封回复给所有订阅者

POST to Topic
POST /TriggerTopic HTTP/1.1
Host: 10.224.234.34:8280
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 3453ddc5-a279-203a-fecf-38e81bd3ba8b

{"value":"some value"}

来自TOPIC的订阅者收到的回应。

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><ns:topic xmlns:ns="http://wso2.org/ns/2009/09/eventing/notify">/TestTopic</ns:topic></soapenv:Header><soapenv:Body><jsonObject><value>some value</value></jsonObject></soapenv:Body></soapenv:Envelope>

有没有办法可以将请求对象消息原样传递给所有订阅者?

1 个答案:

答案 0 :(得分:1)

订阅者必须将内容类型指定为application / json

示例发布商:

test = 'ifconfig eth6.36\r\neth6.36   Link encap:Ethernet  HWaddr A0:36:9F:5F:24:EE  \r\n          inet addr:36.36.36.10  Bcast:36.36.36.255  Mask:255.255.255.0\r\n          inet6 addr: fe80::a236:9fff:fe5f:24ee/64 Scope:Link\r\n          UP BROADCAST MULTICAST  MTU:9000  Metric:1\r\n          RX packets:0 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:62 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:0 \r\n          RX bytes:0 (0.0 b)  TX bytes:7004 (6.8 KiB)\r\n\r\n'

match = re.match('(eth6.36\sLink encap:)', test)
print match.groups()
...
AttributeError: 'NoneType' object has no attribute 'groups'

样本订阅者:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Publisher" transports="http" startOnLoad="true" trace="disable">
    <description/>
    <target>
        <inSequence>
            <property name="messageType" value="application/json" scope="axis2" type="STRING"/>
            <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" type="STRING"/>
            <property name="OUT_ONLY" value="true"/>
            <send>
                <endpoint>
                    <address uri="jms:/dynamicTopics/TESTTOPIC?transport.jms.ConnectionFactory=myTopicConnectionFactory"/>
                </endpoint>
            </send>
        </inSequence>
    </target>
</proxy>

使用SoapUI将此json有效负载发送到<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="Subscriber" transports="jms" startOnLoad="true" trace="disable"> <description>subscriber</description> <target> <inSequence> <log level="full"/> </inSequence> </target> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>application/json</default> </rules> </parameter> <parameter name="transport.jms.ConnectionFactory">myTopicConnectionFactory</parameter> <parameter name="transport.jms.DestinationType">topic</parameter> <parameter name="transport.jms.Destination">TESTTOPIC</parameter> </proxy> http://localhost:8280/services/Publisher

查找日志:{"value":"some value"}