带有 Apache Synapse 的 REST 代理服务器

REST Proxy Server with Apache Synapse

我是 ESB 和 Apache Synapse 的新手。我有一个简单的 REST API,它采用 GET 方法和 returns 一个简单的 json 响应。我尝试使用 Apache Synapse 创建代理。

配置如下。

    <proxy name="SampeJsonProxy">
        <target>
            <endpoint>
                <address uri="http://localhost:8081/kafka/publish/hello" format="json"  methods="GET"/>
            </endpoint>
            <inSequence>
                <log level="full"/>
            </inSequence>
            <outSequence>
                <send/>
            </outSequence>
        </target>
    </proxy>

当我在 REST 上卷曲时 API 我得到的响应是

curl -v http://127.0.0.1:8081/kafka/publish/hello
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8081 (#0)
> GET /kafka/publish/hello HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 48
< Date: Wed, 10 Feb 2021 13:48:27 GMT
<
 {"name": "John", "age": 31, "city": "New York"}* Connection #0 to host 127.0.0.1 left intact

当我在 synapse 服务器上执行 curl 操作时,我得到如下信息但没有响应。

curl -v http://127.0.0.1:8280/kafka/publish/hello
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8280 (#0)
> GET /kafka/publish/hello HTTP/1.1
> Host: 127.0.0.1:8280
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 202 Accepted
< Date: Wed, 10 Feb 2021 13:48:18 GMT
< Server: Synapse-PT-HttpComponents-NIO
< Transfer-Encoding: chunked
<
* Connection #0 to host 127.0.0.1 left intact

synapse server 上的登录如下所示。

INFO LogMediator To: /kafka/publish/hello, MessageID: urn:uuid:46af1619-6bbb-4fe9-b00f-2ec1e7e938a3, Direction: request

我 运行 通过编辑 synapse_sample_150.xml 并用上述代理和 运行 替换内容来配置 synapse.bat -sample 150

我不明白为什么这不起作用。有人可以帮助我理解这个问题。我参考了 here.

中的第二个例子

我发现了问题。我打错了 proxy.Giving 卷曲 http://127.0.0.1:8280/services/SampeJsonProxy 解决给出正确的输出。