互操作性 Azure 服务总线消息队列消息 [英] Interoperability Azure Service Bus Message Queue Messages
问题描述
我有一个 Java 应用程序和一个 NodeJS 应用程序,它们都使用单个 Azure 服务总线消息队列.
I have a Java App and a NodeJS App both using a single Azure Service Bus Message Queue.
我在我的客户身上看到了一些奇怪的效果,如下所示.
I witness some strange effects with my clients, as follow.
JAVA MESSAGE PRODUCER(根据 Azure JMS 教程使用 QPID 库):
JAVA MESSAGE PRODUCER (using QPID libraries per Azure JMS tutorial):
TextMessage message = sendSession.createTextMessage();
message.setText("Test AMQP message from JMS");
long randomMessageID = randomGenerator.nextLong() >>>1;
message.setJMSMessageID("ID:" + randomMessageID);
sender.send(message);
System.out.println("Sent message with JMSMessageID = " + message.getJMSMessageID());
输出:发送消息 JMSMessageID = ID:2414932965987073843
OUTPUT: Sent message with JMSMessageID = ID:2414932965987073843
节点消息消费者:
serviceBus.receiveQueueMessage(queue, {timeoutIntervalInS: timeOut, isReceiveAndDelete: true}, function(err, message) {
if(message !==null)console.log(util.inspect(message, {showHidden: false, depth: null}));
});
输出:
{ body: '@u0006string3http://schemas.microsoft.com/2003/10/Serialization/�u001aTest AMQP message from JMS',
brokerProperties:
{ DeliveryCount: 1,
EnqueuedSequenceNumber: 5000004,
EnqueuedTimeUtc: 'Wed, 04 Nov 2015 21:28:21 GMT',
MessageId: '2414932965987073843',
PartitionKey: '89',
SequenceNumber: 59672695067659070,
State: 'Active',
TimeToLive: 1209600,
To: 'moequeue' },
contentType: 'application/xml; charset=utf-8' }
如果我将其与通过 serviceBus.sendQueueMessage() 插入队列的消息进行比较,则属性如下所示:
If I compare that to a message inserted into the queue via serviceBus.sendQueueMessage(), then the properties look like this:
{ body: 'test message',
brokerProperties:
{ DeliveryCount: 1,
EnqueuedSequenceNumber: 0,
EnqueuedTimeUtc: 'Wed, 04 Nov 2015 21:44:03 GMT',
MessageId: 'bc0a3d4f-15ba-434f-9fb0-1a3789885f8c',
PartitionKey: '734',
SequenceNumber: 37436171906517256,
State: 'Active',
TimeToLive: 1209600 },
contentType: 'text/plain',
customProperties:
{ message_number: 0,
sent_date: Wed Nov 04 2015 21:44:03 GMT+0000 (UTC) } }
所以内容类型一开始就不一样——为什么?- 然后第一个消息有效负载正文中的奇怪垃圾来自哪里:@u0006string3http://schemas.microsoft.com/2003/10/Serialization/u001a那是序列化的结果吗?如何缓解这种情况?
So content type is different to start with - why? - and then where does the strange garbage in the body of the first message payload come from: @u0006string3http://schemas.microsoft.com/2003/10/Serialization/�u001a Is that the result of serialization? How can this be mitigated?
也可以在这里找到代码:http://pastebin.com/T9RTFRBk
Find the code as well here: http://pastebin.com/T9RTFRBk
推荐答案
Azure 服务总线支持两种不同的协议:AMQP 和 HTTP.使用 qpid 库的 Java/JMS 正在使用 ServiceBus 的 AMQP 协议.但是,ServiceBus REST API 通过 HTTP 协议封装在 NodeJS 中.
The Azure Service Bus supports two different protocols: AMQP and HTTP. The Java/JMS using qpid libs is using AMQP protocal for ServiceBus. However, the ServiceBus REST APIs wrapped in NodeJS thur HTTP protocol.
Service Bus 中 AMQP 支持的详细信息,请参考 https://azure.microsoft.com/en-us/documentation/articles/service-bus-amqp-overview/.
Details for AMQP support in Service Bus, please refer to https://azure.microsoft.com/en-us/documentation/articles/service-bus-amqp-overview/.
ServiceBus 的 REST API,请参考 https://msdn.microsoft.com/en-us/library/azure/hh780717.aspx.
And for REST APIs of ServiceBus, please refer to https://msdn.microsoft.com/en-us/library/azure/hh780717.aspx.
AMQP 是一个二进制的应用层协议,旨在高效地支持各种消息应用程序和通信模式.- 来自维基百科
AMQP is a binary, application layer protocol, designed to efficiently support a wide variety of messaging applications and communication patterns. - from WikiPedia
但 HTTP 是一种文本协议.
But the HTTP is a text protocol.
消息格式如下,请参考 aritifact http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#section-message-format.而AMQP规范可以参考http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-overview-v1.0-os.html.
The message format is as below, please refer to the section Message Format
of the aritifact http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#section-message-format. And the AMQP specification can be refered to http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-overview-v1.0-os.html.
Bare Message
|
.---------------------+--------------------.
| |
+--------+-------------+-------------+------------+--------------+--------------+--------+
| header | delivery- | message- | properties | application- | application- | footer |
| | annotations | annotations | | properties | data | |
+--------+-------------+-------------+------------+--------------+--------------+--------+
| |
'-------------------------------------------+--------------------------------------------'
|
Annotated Message
所以Java发送的消息或者NodeJS发送的消息被序列化成不同的结果.
So the messages sent in Java or sent in NodeJS were serialized to different results.
AMQP中body内容格式化后的内容uXXXX
是Unicode Charater.
The content uXXXX
formated in the content of body from AMQP is Unicode Charater.
Unicode 字符 u0006
是 Acknowledge 控制字符,请参考 https://en.wikipedia.org/wiki/Acknowledge_character 了解一下.
The Unicode Charater u0006
is Acknowledge controll charater, please refer to https://en.wikipedia.org/wiki/Acknowledge_character to know it.
而Unicode字符u001a
是替代控制字符,请参考https://en.wikipedia.org/wiki/Substitute_character.
And the Unicode Charater u001a
is Substitute controll charater, please refer to https://en.wikipedia.org/wiki/Substitute_character.
它们限制了消息头中元数据的开始和结束.
They are limit the start and end of the metadata in the message header.
这篇关于互操作性 Azure 服务总线消息队列消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!