camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ismail Emre Kartoglu <ismailemrekarto...@gmail.com>
Subject Re: rabbitmq component headers
Date Wed, 21 Sep 2016 06:06:57 GMT
Sorry, I’ve switched to using the camel & rabbitmq-component version 2.17.3 (latest in
maven central repo), and my initial issue does not exist with this version. 

Now I have a slightly different question:

from("rabbitmq://localhost/A?username=guest&password=guest&routingKey=B&threadPoolSize=1&autoAck=false")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("X: " + exchange.getIn().getBody(String.class));
                        exchange.getOut().setBody("Test X");
			exchange.getOut().getHeaders().put(“key”, “val"); **
                    }
                })
.to("rabbitmq://localhost/C?username=guest&password=guest&routingKey=D&threadPoolSize=1&autoAck=false");



If you comment out the line with **, the message does not get sent to exchange C, as specified
in the “to” endpoint, because:

1) in-message headers contain the exchange name and routing key of the consumer.
2) out-message headers copy the in-headers if no out-message header is set.
3) RabbitMQProducer.java (2.17.3), line 246 and 248 set the exchange name and routing key
from the header, and ignore the producer URI configuration.


I think the documentation suggests that this is the expected behaviour. But it would be more
intuitive to set the exchange name and the routing key from the producer uri, rather than
setting it from the in-message headers (which are not visible in code) and ignoring the producer
configuration.

Kind regards
Ismail


> On 21 Sep 2016, at 05:26, Ismail Emre Kartoglu <ismailemrekartoglu@gmail.com> wrote:
> 
> Thanks Willem.
> 
> The documentation says the URI should look like:
> 
> rabbitmq://hostname[:port]/exchangeName?[options]
> 
> So I do have the exchange name in the URI in my example.
> 
> See http://camel.apache.org/rabbitmq.html <http://camel.apache.org/rabbitmq.html>
> 
> Sent from phone
> 
> 
> On 21 Sep 2016 1:49 a.m., "Willem Jiang" <willem.jiang@gmail.com <mailto:willem.jiang@gmail.com>>
wrote:
> You should add the exchangeName parameter to the rabbitmq uri if you don’t want to
specify the message header there.
> 
> --
> Willem Jiang
> 
> 
> Blog: http://willemjiang.blogspot.com <http://willemjiang.blogspot.com/> (English)
> http://jnn.iteye.com <http://jnn.iteye.com/> (Chinese)
> Twitter: willemjiang
> Weibo: 姜宁willem
> 
> 
> 
> On September 21, 2016 at 5:14:54 AM, Emre Kartoglu Ismail (ismailemrekartoglu@gmail.com
<mailto:ismailemrekartoglu@gmail.com>) wrote:
> > Hello Camel users,
> >
> > I have a question regarding the camel-rabbitmq component. The following
> > code sends the message “test” to exchange “A” with routing key “B” every
> > 5 seconds:
> >
> >
> > from("timer:test?period=5000").process(new Processor() {
> > @Override
> > public void process(Exchange exchange) throws Exception {
> > exchange.getOut().setBody("test", String.class);
> > exchange.getOut().getHeaders().put("rabbitmq.EXCHANGE_NAME", "A”); **
> > exchange.getOut().getHeaders().put("rabbitmq.ROUTING_KEY", "B”); **
> > }
> > })
> > .to("rabbitmq://localhost/A?username=guest&password=guest&routingKey=B&threadPoolSize=1&autoAck=false");
> >
> >
> >
> > However when I comment out the lines with **, the message does not get
> > sent. Is this an expected behaviour? I found this stack overflow post,
> > essentially discussing the same issue:
> > http://stackoverflow.com/questions/22449086/apache-camel-rabbitmq-endpoint-not-creating
<http://stackoverflow.com/questions/22449086/apache-camel-rabbitmq-endpoint-not-creating>
> > .
> >
> > There is a paragraph at http://camel.apache.org/rabbitmq.html <http://camel.apache.org/rabbitmq.html>
that says
> >
> > "Headers are set by the consumer once the message is received. The
> > producer will also set the headers for downstream processors once the
> > exchange has taken place. Any headers set prior to production that the
> > producer sets will be overridden.”
> >
> > The last sentence seems to suggest that the behaviour I described here
> > is expected. My question then is would it not make more sense if we did
> > not have to specifically set the headers in the out message?
> >
> >
> > Kind regards,
> > Ismail
> >
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message