我在WSO2ESB中有这样的API配置:
<api xmlns="http://ws.apache.org/ns/synapse" name="b2e_rmq_getmessage" context="/b2e_rmq_getmessage">
<resource methods="GET" uri-template="/tenants/{tenantid}/exchanges/{exchangeid}/keys/{keyid}/message*">
<resource methods="GET" uri-template="/tenants/{tenantid}/exchanges/{exchangeid}/keys*">
<resource methods="GET" uri-template="/tenants/{tenantid}/exchanges*">
<resource methods="GET" uri-template="/tenants*">
</api>
问题在于,在此代码中如何路由消息并不明显。它们甚至被随机路由,并且这个随机顺序被缓存。 例如,如果我保存此API并使用第二个(键*)选项调用它,则可以调用第4个(租户*)选项。
然后我打开API配置并再次保存 - 我用第二个(键*)选项调用它,它可以调用第3个(交换*)选项。
我的实验表明,编写代码的顺序无关紧要。
我如何为此案件进行优先处理?如果几个uri符合条件,我的目标是选择更复杂的uri。
请注意,我无法在地址末尾删除通配符,以便能够使用rest参数。此外,我无法更改URI模板,因为这是面向资源的模型。
答案 0 :(得分:0)
我发现没有办法以“方法正确”的方式解决这个问题。我的方法是严格重写uri-mappings。例如,事实上我们只会以两种方式称“获取租户”方法:“/租户”(没有通配符),“/租户?*”。
所以,你走了:
<api xmlns="http://ws.apache.org/ns/synapse" name="b2e_elasticsearch_getrmqresource" context="/b2e_elasticsearch_getrmqresource">
<resource methods="GET" uri-template="/tenants/{tenantid}/exchanges/{exchangeid}/keys/{keyid}/messages?*" inSequence="b2e_elasticsearch_getrmqresource_getmessage_in_seq" outSequence="b2e_elasticsearch_getrmqresource_generic_out_seq" faultSequence="b2e_elasticsearch_getrmqresource_generic_fault_seq"/>
<resource methods="GET" uri-template="/tenants/{tenantid}/exchanges/{exchangeid}/keys/{keyid}/messages" inSequence="b2e_elasticsearch_getrmqresource_getmessage_in_seq" outSequence="b2e_elasticsearch_getrmqresource_generic_out_seq" faultSequence="b2e_elasticsearch_getrmqresource_generic_fault_seq"/>
<resource methods="GET" uri-template="/tenants/{tenantid}/exchanges/{exchangeid}/keys?*" inSequence="b2e_elasticsearch_getrmqresource_getroutingkey_in_seq" outSequence="b2e_elasticsearch_getrmqresource_generic_out_seq" faultSequence="b2e_elasticsearch_getrmqresource_generic_fault_seq"/>
<resource methods="GET" uri-template="/tenants/{tenantid}/exchanges/{exchangeid}/keys" inSequence="b2e_elasticsearch_getrmqresource_getroutingkey_in_seq" outSequence="b2e_elasticsearch_getrmqresource_generic_out_seq" faultSequence="b2e_elasticsearch_getrmqresource_generic_fault_seq"/>
<resource methods="GET" uri-template="/tenants/{tenantid}/exchanges" inSequence="b2e_elasticsearch_getrmqresource_getexchange_in_seq" outSequence="b2e_elasticsearch_getrmqresource_generic_out_seq" faultSequence="b2e_elasticsearch_getrmqresource_generic_fault_seq"/>
<resource methods="GET" uri-template="/tenants/{tenantid}/exchanges?*" inSequence="b2e_elasticsearch_getrmqresource_getexchange_in_seq" outSequence="b2e_elasticsearch_getrmqresource_generic_out_seq" faultSequence="b2e_elasticsearch_getrmqresource_generic_fault_seq"/>
<resource methods="GET" uri-template="/tenants?*" inSequence="b2e_elasticsearch_getrmqresource_gettenant_in_seq" outSequence="b2e_elasticsearch_getrmqresource_generic_out_seq" faultSequence="b2e_elasticsearch_getrmqresource_generic_fault_seq"/>
<resource methods="GET" uri-template="/tenants" inSequence="b2e_elasticsearch_getrmqresource_gettenant_in_seq" outSequence="b2e_elasticsearch_getrmqresource_generic_out_seq" faultSequence="b2e_elasticsearch_getrmqresource_generic_fault_seq"/>
</api>