简体   繁体   English

Apache NMS IBytesMessage出队后有前缀

[英]Apache NMS IBytesMessage has a prefix after dequeuing

I've tried my best to figure this out, but I'm guessing my inexperience with Do.net/C# and message queues is showing through.我已尽力解决这个问题,但我猜我对 Do.net/C# 和消息队列的经验不足正在显现出来。

The problem问题

In a nutshell the situation I'm dealing with is, I have two projects.简而言之,我正在处理的情况是,我有两个项目。

The first project is a legacy Do.net project using the Apache NMS library to consume messages from an ActiveMQ queue.一个项目是一个遗留的 Do.net 项目,它使用 Apache NMS 库来使用来自 ActiveMQ 队列的消息。

The queue is normally connected in production via SSL, but developing locally I have connected via TCP which all works fine and actively connects & dequeues as expected.队列通常通过 SSL 在生产中连接,但在本地开发我通过 TCP 连接,一切正常,并按预期主动连接和出队。

Once the messages are dequeued they are deserialised using the JsonConvert DeserializeObject method.消息出列后,将使用 JsonConvert DeserializeObject 方法对它们进行反序列化。

The second project is a NodeJS project which I've created to put messages onto the queue.第二个项目是我创建的一个 NodeJS 项目,用于将消息放入队列。

The messages are just a simple object, stringified to JSON.这些消息只是一个简单的 object,字符串化为 JSON。

I'm using the AMQP Rhea npm package to connect and send the messages, in AMQP format.我正在使用 AMQP Rhea npm package以 AMQP 格式连接和发送消息。

This again all works fine and the messages are enqueued as expected.这再次一切正常,并且消息按预期排队。

The problem is when I come to deserialising the message pulled from the queue.问题是当我开始反序列化从队列中提取的消息时。

There's an exception because it encounters a prefix to my JSON message - I have no idea where the prefix comes from.有一个例外,因为它遇到了我的 JSON 消息的前缀 - 我不知道前缀来自哪里。

I have a creeping suspicion it's because there's a clash between the protocols I'm using and that's causing the issue, but before I find myself in that particular rabbit hole - or just resorting to using a shaky method of removing the prefix - I'm hoping one of you with more experience can help point me in the right direction.我有一个令人毛骨悚然的怀疑,这是因为我正在使用的协议之间存在冲突,这导致了问题,但在我发现自己陷入那个特定的兔子洞之前——或者只是诉诸于使用一种不稳定的方法来删除前缀——我是希望你们中有更多经验的人可以帮助我指明正确的方向。


Code代码

Here's a couple of snippets of the offending C#:这是有问题的 C# 的几个片段:

This is how I'm dequeueing the messages:这就是我使消息出列的方式:


    string dequeuedMessage = string.Empty;
    List<string> messages = new List<string>();

    IMessage message = _consumer.Receive(waitForMessage);

    if (message is ITextMessage || message is IBytesMessage)
    {

        dequeuedMessage = (message is ITextMessage) ? (message as ITextMessage).Text : Encoding.UTF8.GetString((message as IBytesMessage).Content);
        messages.Add(dequeuedMessage);
    }
    else
        break;

What's interesting is the message always comes through as type IBytesMessage, not what the previous author was expecting (ITextMessage), which is why I'm having that creeping suspicion.有趣的是,消息总是以 IBytesMessage 类型出现,而不是之前作者所期望的类型 (ITextMessage),这就是为什么我有那种令人毛骨悚然的怀疑。

And this is how I'm deserialising the message:这就是我反序列化消息的方式:

    private IMessage BuildMessageObject(string message)
    {
        IMessage convertedMessage = JsonConvert.DeserializeObject<QueueMessage>(message);
            
        return convertedMessage;
    }

Here's a look at the prefix:看一下前缀:

\0SpE\0SsE\0Sw\xb1\0\0\x01\xac{"Message":"Message Content Snipped for Brevity"}

It appears to always be the same, so maybe it means something to someone.它似乎总是一样的,所以也许它对某人意味着什么。

What I've Tried & Expectations我的尝试和期望

To quickly debug, I tried connecting to the queue in the Do.net project using AMQP, but it appears that the Apache NMS package doesn't support this.为了快速调试,我尝试使用 AMQP 连接到 Do.net 项目中的队列,但似乎 Apache NMS package 不支持此功能。

I'm not in a position to completely rewrite the connection with another package either.我也不在 position 中来完全重写与另一个 package 的连接。

I've also written something to dequeue the message in my Node app and I get the JSON back without the prefix, but this connects with the AMQP protocol which may be why?我还写了一些东西来使我的 Node 应用程序中的消息出列,并且我得到了没有前缀的 JSON,但这可能与 AMQP 协议连接,这可能是为什么?

Thanks for any help.感谢您帮助。

Edit: I should add that I'm using ActiveMQ Classic and not Artemis.编辑:我应该补充一点,我使用的是 ActiveMQ Classic 而不是 Artemis。

Answering my own question, it appears it is an issue with the amqp/rhea package and using the AMQP protocol as I suspected.回答我自己的问题,这似乎是 amqp/rhea package 和我怀疑的使用 AMQP 协议的问题。

The problem, without running into details I can't fully explain, is that the message from the queue has been encoded and the message body includes that encoding.问题是,如果不深入我无法完全解释的细节,来自队列的消息已被编码并且消息正文包含该编码。

The NMS library uses ActiveMQ's native OpenWire protocol. NMS 库使用 ActiveMQ 的原生 OpenWire 协议。

I'm probably going to have to resolve this by moving from using the amqp/rhea package and trying to find an openwire equivalent - which is preferable than trying to find an AMQP equivalent for the Do.net project.我可能不得不通过不再使用 amqp/rhea package 并尝试找到一个 openwire 等效项来解决这个问题——这比尝试为 Do.net 项目找到一个 AMQP 等效项更可取。

Edit:编辑:

As it turns out, the rhea package is sufficient to solve the problem.事实证明,rhea package 足以解决问题。 In sending the message body, I've instead created it as a Buffer instead of type Message:在发送消息正文时,我将其创建为 Buffer 而不是 Message 类型:

const messageAsBuffer = Buffer.from(message);
sender.send(messageAsBuffer, undefined, 1);

where undefined can be a message tag and 1 can be any integer that is not 0, specifying the message is not in AMQP format.其中undefined可以是消息标签, 1可以是任何不为 0 的 integer,指定消息不是 AMQP 格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM