Bluelock / camel-spring-amqp

Spring AMQP Component for Apache Camel
61 stars 54 forks source link

Setting BasicProperties #15

Closed rowlandwatkins closed 11 years ago

rowlandwatkins commented 11 years ago

Hi,

Is there any way to specify BasicProperties without digging into the code?

I see on http://static.springsource.org/spring-amqp-net/docs/1.0.x/reference/html/amqp.html that it's supposed to be possible to specify 'messageId', 'timestamp', 'contentType' via the IMessageProperties interface, using SetHeader(string key, object val).

I'd ideally like to do the following:

sendMessage("spring-amqp:exch:queue:key", message, headers)

and uses the headers to set. So far that doesn't seem to do the job.

As an alternative, I've started looking at modifying toAMQPMessage to set the BasicProperties beyond setMessageId.

Cheers,

Rowlamd

deckerego commented 11 years ago

I'll take a look and see if I can implement this within https://github.com/deckerego/camel-spring-amqp . If you happen to get things working on your side and feel like sending a pull request, I'm sure the kind people at Bluelock would be more than happy to oblige ;)

deckerego commented 11 years ago

This changed a bit with the RabbitMQ 3 release, refactoring and will push.

deckerego commented 11 years ago

To best deal with the ever-evolving basic properties, it seems like the best bet is to fetch certain "constants" from the Camel message headers and use them as basic properties. For example, if you create a Camel message with the header key SpringAMQPMessage.CONTENT_TYPE and the value "plain/text" it would set the BasicProperties.ContentType to be "plain/text."

Header values are already set - so that shouldn't be an issue. The issue is just setting the magical message properties defined by the AMQP spec.

Does this sound acceptable? Seems like the cleanest implementation.

apoltavtsev commented 11 years ago

I have tried to set header parameter ( with header exchange) using "camel:setHeader" construction on producer side:

[route] [from uri="file:src/data/outgoingMessages?noop=true" /] [log message="Message is loaded" /]

[camel:setHeader headerName="age"] [camel:constant>32</camel:constant] [/camel:setHeader]

[to uri="spring-amqp:HeaderExchange?type=headers&durable=true&autodelete=false" /] [log message="Message is sent" /] [/route]

...

it works

this is corresponding routing on consumer side:

[route] [from uri="spring-amqp:HeaderExchange:HeaderExchangeQueue:age=32?type=headers&durable=true&autodelete=false" /]

[log message="Message is received" /] [to uri="file:src/data/incomingMessages"/]

[log message="Message content is written to local file " /]

[/route]

The problem is - it is NOT possible to set message properties (like "replyTo", "priority", "appId", "timestamp", etc) in similar way like:

[route] [from uri="file:src/data/outgoingMessages?noop=true" /] [log message="Message is loaded" /]

[camel:setProperty propertyName="priority"] [camel:constant]10[/camel:constant] [/camel:setProperty]

[to uri="spring-amqp:HeaderExchange?type=headers&durable=true&autodelete=false" /] [log message="Message is sent" /] [/route]

It does not work because of properties (in current case "priority") are not propagated (in HeadersPostProcessor:postProcessMessage) from camelMessage to amqp message which is sent to consumer.

The question is - will current implementation be extended to support this "propagation" scenario in next releases (or do you plan to implement properties propagation in some another way) ?

PS: replace "]" by ">" and "[" by "<" to get routing from this post in "normal" view (I have replaced "<" and ">" because of xml input is not allowed in comments ... xml tags are removed during commiting of comment).

deckerego commented 11 years ago

Yup, the scenario you put forth would be handled by my suggestion. I would just need to explicitly monitor for the AMQP keywords and place them in special headers.

I'll start working on that and get it tested out in the deckerego fork.

rowlandwatkins commented 11 years ago

This is great, much better than the current hack I'm using, thanks so much!