Stomp的MessageMap格式完全不能用了吗?

发布于 2024-09-04 23:09:05 字数 1265 浏览 3 评论 0原文

我将 Java 中的 MapMessages 发送到 ActiveMQ,并使用 PHP 中的 Stomp 检索它们。我的消息创建代码如下所示:

MapMessage message = session.createMapMessage();
message.setInt("id", 42);
message.setInt("status", 42);
message.setString("result", "aString");

当我在 PHP 中检索它们时,创建的数组如下所示:

Array (
[map] => Array (
        [0] => Array (
                [entry] => Array (
                        [0] => Array (
                                [string] => id
                                [int] => 42
                            )

                        [1] => Array (
                                [string] => status
                                [int] => 42
                            )

                        [2] => Array (
                                [string] => Array (
                                        [0] => result
                                        [1] => aString
                                    )
                            )
                    )
            )
    )
)

我应该用它做什么?有没有办法说服 Stomp 以合理的方式反序列化它,或者是否有一些 PHP 咒语可以让访问这个数组不那么痛苦?特别是,我不能只迭代条目并构建关联数组,因为如果存在字符串 & ,则该数组看起来完全不同。 int 而不是两个字符串。

I'm sending MapMessages in Java to ActiveMQ and retrieving them using Stomp in PHP. My message creation code looks like this:

MapMessage message = session.createMapMessage();
message.setInt("id", 42);
message.setInt("status", 42);
message.setString("result", "aString");

When I retrieve them in PHP, the array that's created looks like this:

Array (
[map] => Array (
        [0] => Array (
                [entry] => Array (
                        [0] => Array (
                                [string] => id
                                [int] => 42
                            )

                        [1] => Array (
                                [string] => status
                                [int] => 42
                            )

                        [2] => Array (
                                [string] => Array (
                                        [0] => result
                                        [1] => aString
                                    )
                            )
                    )
            )
    )
)

What am I supposed to do with that? Is there a way to convince Stomp to unserialize it in a reasonable manner or is there some PHP incantation make accessing this array less painful? In particular, I can't just iterate through the entries and build an associative array because the array looks completely different if there is a string & int as opposed to two strings.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风挽心 2024-09-11 23:09:05

这是我的想法。有谁知道更清洁的解决方案?

$entries = $msg->map['map'][0]['entry'];
$map = array();
foreach($entries as $entry) {
    $vals = array_values($entry);
    if(count($vals) == 1 && is_array($vals[0])) {
        $vals = $vals[0];
    }
    $map[$vals[0]] = $vals[1];
}

这给了我:

array
  'id' => int 42
  'status' => int 42
  'result' => string 'aString' (length=7)

这几乎就是我正在寻找的东西,但是到达那里的代码似乎非常脆弱。

Here's what I've come up with. Does anyone know of a cleaner solution?

$entries = $msg->map['map'][0]['entry'];
$map = array();
foreach($entries as $entry) {
    $vals = array_values($entry);
    if(count($vals) == 1 && is_array($vals[0])) {
        $vals = $vals[0];
    }
    $map[$vals[0]] = $vals[1];
}

This gives me:

array
  'id' => int 42
  'status' => int 42
  'result' => string 'aString' (length=7)

which is pretty much what I'm looking for, but the code to get there seems pretty fragile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文