ActiveMQ / PHP Stomp 使用 TextMessage 而不是 BytesMessage
ActiveMQ / PHP Stomp use TextMessage instead of BytesMessage
当我使用 PHP-Stomp 向 ActiveMQ 发送消息时,消息作为 BytesMessage 发送。但是我想发送一个 TextMessage。
根据 STOMP documentation 这可以通过不发送 content-length header:
... The protocol does however support a content-length
header. To provide more robust interaction between Stomp and JMS
clients, ActiveMQ keys off of the inclusion of this header to
determine what message type to create when sending from Stomp to JMS.
The logic is simple:
Inclusion of content-length header => Resulting Message
yes => BytesMessage
no => TextMessage
This same logic can be followed when going from JMS to Stomp, as well.
A Stomp client could be written to key off of the inclusion of the
content-length header to determine what type of message structure to
provide to the user.
在我的测试 PHP 脚本中我没有定义 content-length header 并且它似乎是自动添加的。
我还尝试将 content-length 作为 0、false 或 null 传递。在所有这些情况下,它都会生成一个 BytesMessage。
所以我的问题是,如何生成文本消息而不是 BytesMessage。
我的代码如下所示:
<?php
$stomp = new Stomp('tcp://localhost:61613');
$stomp->send('/topic/test.central_message_topic', 'testmessage', [
"persistent" => "true",
]);
我找到了答案。
TL;DR: 这是不可能的。
使用 PECL-Stomp 不可能不发送 content-length header,因为它是在发送请求时自动创建的。如果你通过 reuqest 将包含两个 content-length headers.
添加转换 header,将其与 activemq 一起使用:
$stomp->send('/queue/pizzamonsters', json_encode($frame), [
'transformation' => 'TEXT'
]);
已经很长时间了,但这对我有用:
try {
$stomp->send("your_queue", "your_message", array("amq-msg-type" => "text"));
} catch (StompException $e) {
die('send failed: ' . $e->getMessage());
}
<?php
$stomp = new Stomp('tcp://localhost:61613');
$stomp->send('/topic/test.central_message_topic', 'testmessage', ["content-type" =>"text/plain"]);
当我使用 PHP-Stomp 向 ActiveMQ 发送消息时,消息作为 BytesMessage 发送。但是我想发送一个 TextMessage。
根据 STOMP documentation 这可以通过不发送 content-length header:
... The protocol does however support a content-length header. To provide more robust interaction between Stomp and JMS clients, ActiveMQ keys off of the inclusion of this header to determine what message type to create when sending from Stomp to JMS. The logic is simple:
Inclusion of content-length header => Resulting Message
yes => BytesMessage
no => TextMessage
This same logic can be followed when going from JMS to Stomp, as well. A Stomp client could be written to key off of the inclusion of the content-length header to determine what type of message structure to provide to the user.
在我的测试 PHP 脚本中我没有定义 content-length header 并且它似乎是自动添加的。 我还尝试将 content-length 作为 0、false 或 null 传递。在所有这些情况下,它都会生成一个 BytesMessage。
所以我的问题是,如何生成文本消息而不是 BytesMessage。
我的代码如下所示:
<?php
$stomp = new Stomp('tcp://localhost:61613');
$stomp->send('/topic/test.central_message_topic', 'testmessage', [
"persistent" => "true",
]);
我找到了答案。
TL;DR: 这是不可能的。
使用 PECL-Stomp 不可能不发送 content-length header,因为它是在发送请求时自动创建的。如果你通过 reuqest 将包含两个 content-length headers.
添加转换 header,将其与 activemq 一起使用:
$stomp->send('/queue/pizzamonsters', json_encode($frame), [
'transformation' => 'TEXT'
]);
已经很长时间了,但这对我有用:
try {
$stomp->send("your_queue", "your_message", array("amq-msg-type" => "text"));
} catch (StompException $e) {
die('send failed: ' . $e->getMessage());
}
<?php
$stomp = new Stomp('tcp://localhost:61613');
$stomp->send('/topic/test.central_message_topic', 'testmessage', ["content-type" =>"text/plain"]);