编辑:我认为这实际上是因为Camel使用了QPid JMS,并且没有JMS API的方法来获取内容类型,这不在规范中。即使AMQP 1.0支持content-type
作为属性。但是,是的,我仍然建议在下面使用自定义属性。
为了更清晰和纠正错误,进行了编辑。TL/DR:使用自定义用户属性头。
原始(REST)消息中的SMF内容类型标头会作为一个属性content-type
传递到消费的AMQP消息中,然而JMS API规范没有公开此功能;在标准JMS中没有办法检索这个值。然而,代理程序会使用它来设置消息的类型(例如TextMessage)。请查看Solace文档中的"Content-Type Mapping to Solace Message Types"。
使用Solace的SDKPerf AMQP JMS版本将接收到的消息转储到控制台(请注意,这使用QPid库):
./sdkperf_jmsamqp.sh -cip=amqp://localhost:5672 -stl=a/b/c
-md -q
curl http://localhost:9000/TOPIC/a/b/c -d 'hello' -H 'Content-Type: text'
^^^^^^^^^^^^^^^^^^ Start Message ^^^^^^^^^^^^^^^^^^^^^^^^^^^
JMSDeliveryMode: PERSISTENT
JMSDestination: a/b/c
JMSExpiration: 0
JMSPriority: 4
JMSTimestamp: 0
JMSRedelivered: false
JMSCorrelationID: null
JMSMessageID: null
JMSReplyTo: null
JMSType: null
JMSProperties: {JMSXDeliveryCount:1;}
Object Type: TextMessage
Text: len=5
hello
HTTP头部不会被映射,但会用于设置消息类型。如果我删除该HTTP头部,则接收到的AMQP消息将是二进制的。但由于其他类型的Content-Type也映射到TextMessages(例如application/json
,application/xml
等),因此收到TextMessage并不足以推断您使用哪种Content-Type发布了REST消息。
为了完整起见,我使用了带有AMQP解码器的WireShark,并且您可以在接收到的AMQP消息上看到头部存在:
Frame 3: 218 bytes on wire (1744 bits), 218 bytes captured (1744 bits) on interface \Device\NPF_Loopback, id 0
Null/Loopback
Internet Protocol Version 4, Src: 127.0.0.1, Dst: 127.0.0.1
Transmission Control Protocol, Src Port: 5672, Dst Port: 60662, Seq: 2, Ack: 1, Len: 174
Advanced Message Queueing Protocol
Length: 174
Doff: 2
Type: AMQP (0)
Channel: 2
Performative: transfer (20)
Arguments (5)
Message-Header
Durable: True
Message-Annotations (map of 1 element)
x-opt-jms-dest (byte): 1
Message-Properties
To: a/b/c
Content-Type: text <----------
Application-Properties (map of 1 element)
AaronEncoding (str8-utf8): CustomText
AMQP-Value (str32-utf8): hello
我的建议是这样的:
设置一个额外的自定义头部,即用户属性,该属性将通过AMQP消息传递:
curl http://localhost:9000/TOPIC/a/b/c -d 'hello' -H 'Solace-User-Property-AaronEncoding: CustomText' -H 'Content-Type: text'
JMSDestination: a/b/c
JMSProperties: {AaronEncoding:CustomText;JMSXDeliveryCount:1;}
Object Type: TextMessage
Text: len=5
hello
对于Solace REST交互,我一直使用的指南是:https://docs.solace.com/API/RESTMessagingPrtl/Solace-REST-Message-Encoding.htm
希望这有所帮助!