简体   繁体   English

如何在 Apache Camel AMQP 组件中获取 AMQP 消息属性

[英]How to get AMQP Message properties in Apache Camel AMQP Component

I have a Springboot application using Apache Camel AMQP component to comsume messages from a Solace Queue.我有一个 Springboot 应用程序,它使用 Apache Camel AMQP 组件来处理来自 Solace 队列的消息。 To send a message to the Queue I use Postman and the Solace REST API. In order to differentiate the message type I add Content-Type to the header of the Http request in Postman. I used SDKPerf to check the message header consumed from solace and the message header is found under "HTTP Content Type" along with other headers.要向队列发送消息,我使用Postman和Solace REST8810005121333888。为了使消息类型I添加内容i的添加到header的信息类型I添加了content-type in 881853008888888888888888888888888888888888888888888888888888.消息 header 与其他标头一起位于“HTTP 内容类型”下。

However, I can't seem to find a way to get this Content-Type from Camel Side.但是,我似乎无法找到从 Camel Side 获取此 Content-Type 的方法。 In the documentation it says在文档中说

String header = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class);

However this always produces null. Any Ideas how to get the message properties in Camel?然而,这总是产生 null。任何想法如何在 Camel 中获取消息属性?

It may have a different name in Camel.它在 Camel 中可能有不同的名称。 Try either printing all the headers or stop it in the debugger and examine the incoming message.尝试打印所有标头或在调试器中停止它并检查传入消息。

From what I can see, the Content-Type header used in SMF is not passed through to the consumed AMQP message;据我所见,SMF 中使用的 Content-Type header 没有传递给使用的 AMQP 消息; it is only used to set the type of message (eg TextMessage).它仅用于设置消息的类型(例如TextMessage)。 Check "Content-Type Mapping to Solace Message Types" here: https://docs.solace.com/API/RESTMessagingPrtl/Solace-REST-Message-Encoding.htm#_Ref393979978在此处检查“Content-Type Mapping to Solace Message Types”: https://docs.solace.com/API/RESTMessagingPrtl/Solace-REST-Message-Encoding.htm#_Ref393979978

You can see this using SDKPerf AMQP to dump the received message (note this uses QPid libraries):您可以使用 SDKPerf AMQP 转储接收到的消息(注意这使用了 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

So yeah, this header does not get mapped through (unlike a received SMF message)... it's just to set the message type.所以是的,这个 header 没有被映射(不像收到的 SMF 消息)......它只是设置消息类型。 If I remove that HTTP header, the received AMQP message is binary.如果我删除 HTTP header,收到的 AMQP 消息是二进制的。

Since other types of Content-Types also map to TextMessages (eg application/json , application/xml , etc.), the fact you're receiving a TextMessage is not enough to infer exactly what Content-Type you published your REST message with.由于其他类型的 Content-Types 也 map 到 TextMessages(例如application/jsonapplication/xml等),您收到 TextMessage 的事实不足以推断出您发布 REST 消息时使用的内容类型。 So my suggestion is this: set an additional custom header, a User Property , which will get passed through to the AMQP message:所以我的建议是:设置一个额外的自定义 header,一个用户属性,它将传递给 AMQP 消息:

curl http://localhost:9000/TOPIC/a/b/c -d 'hello' -H 'Solace-User-Property-AaronEncoding: CustomText' -H 'Content-Type: text'


JMSProperties:                          {AaronEncoding:CustomText;JMSXDeliveryCount:1;}
Object Type:                            TextMessage
Text:                                   len=5
  hello

Hope that helps!希望有帮助!

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

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