You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Nagulapalli, Srinivas (GE Transportation)" <sr...@ge.com> on 2017/01/30 15:38:05 UTC

How to set AMQP.BasicProperties on outgoing message using Camel?

Please share how to set AMQP.BasicProperties on outgoing message(s) using Camel.

Expected RabbitMQ message:
Exchange

Displays the Exchange fine

Routing Key

Displays the Routing Key fine

Properties

content_encoding: UTF-8   /Unable to set this
content_type: text/plain   //Unable to set this
headers:
Displays the "content_encoding" and "content_type" here!



Tried below code without success.
Appreciate greatly any suggestions/pointers.

Thanks
Srini

========================================
       @Override
        public void process(final Exchange exchange) throws Exception
        {
            final String body = exchange.getIn().getBody(String.class);
            exchange.getOut().setBody(body);

            final Map<String, Object> headers = new HashMap<>();

           //Below does NOT work - it does NOT put "content_encoding" or "content_type" as key-value properties under "Properties"  :(
            exchange.setProperty("content_encoding", "UTF-8");
            exchange.setProperty("content_type", "text/plain");

            //BELOW works as expected- puts the content_encoding and content_type inside headers!
            headers.put("content_encoding", "UTF-8");
            headers.put("content_type", "text/plain");
            exchange.getOut().setHeaders(headers);

        }