gpt4 book ai didi

php - 使用 Camel 从 ActiveMQ 发布 HTTP

转载 作者:可可西里 更新时间:2023-10-31 22:07:28 33 4
gpt4 key购买 nike

我们使用 Camel 路线将值从队列发布到 http 端点。

我已经使用 Camel 的 http component 成功设置了路线, 但我无法获取要发布的 jms 消息正文。

比如我的路由是这样设置的:

<route errorHandlerRef="dlc" autoStartup="true" id="route2" xmlns:ns2="http://camel.apache.org/schema/web" xmlns="http://camel.apache.org/schema/spring">
<from uri="activemq:test"/>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<to uri="http://localhost/tim/camel/" id="to2"/>
</route>

这导致了一个 POST,但是消息正文没有出现在我的 POST 字符串中(作为来自 $_SERVER 的 print_r):

Array
(
[instance] => local
[HTTP_JMSDELIVERYMODE] => 1
[HTTP_JMSDESTINATION] => queue://test
[HTTP_JMSEXPIRATION] => 0
[HTTP_JMSTYPE] =>
[HTTP_JMSTIMESTAMP] => 1291468702773
[HTTP_JMSPRIORITY] => 0
[HTTP_JMSCORRELATIONID] =>
[HTTP_JMSMESSAGEID] => ID:new-host-3.home-62248-1291465669089-4:3:1:1:4
[HTTP_JMSREDELIVERED] => false
[HTTP_USER_AGENT] => Jakarta Commons-HttpClient/3.1
[HTTP_HOST] => localhost
[HTTP_COOKIE] => $Version=0; PHPSESSID=32aa692c71e1003f2e540c1b80c3b363; $Path=/
[CONTENT_LENGTH] => 44
[CONTENT_TYPE] => text/html
[PATH] => /usr/bin:/bin:/usr/sbin:/sbin
[SERVER_SIGNATURE] => <address>Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2 mod_ssl/2.0.59 OpenSSL/0.9.7l Server at localhost Port 80</address>

[SERVER_SOFTWARE] => Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2 mod_ssl/2.0.59 OpenSSL/0.9.7l
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /wufoo/trunk/
[SERVER_ADMIN] => you@example.com
[SCRIPT_FILENAME] => /wufoo/trunk/tim/camel/index.php
[REMOTE_PORT] => 62877
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[REQUEST_URI] => /tim/camel/
[SCRIPT_NAME] => /tim/camel/index.php
[PHP_SELF] => /tim/camel/index.php
[REQUEST_TIME] => 1291468702
[argv] => Array
(
)

[argc] => 0
)

注意 REQUEST_METHOD 是 POST,但 argv 不包含消息正文。

简而言之,我需要将消息正文从“发件人”路由传输到“收件人”路由,以便它可以作为 POST 发送,但我以某种方式失败了。

提前致谢。

最佳答案

我找到了答案。为了解决这个问题,我必须将 Content Type 节点添加到标题并将正文设置为名称/值对,如下所示:

<route errorHandlerRef="dlc" autoStartup="true" inheritErrorHandler="true" id="route2" xmlns:ns2="http://camel.apache.org/schema/web" xmlns="http://camel.apache.org/schema/spring">
<from uri="activemq:test"/>
<setBody inheritErrorHandler="true" id="setBody2">
<simple>name=${body}</simple>
</setBody>
<setHeader headerName="Content-Type" inheritErrorHandler="true" id="setHeader3">
<constant>application/x-www-form-urlencoded;</constant>
</setHeader>
<setHeader headerName="CamelHttpMethod" inheritErrorHandler="true" id="setHeader4">
<constant>POST</constant>
</setHeader>
<to uri="http://localhost/tim/camel/" inheritErrorHandler="true" id="to2"/>
</route>

关于php - 使用 Camel 从 ActiveMQ 发布 HTTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4353700/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com