New Camel user here.
I have a Spring Boot / Camel app and successfully got a route working which polls a REST endpoint, splits the JSON array into custom POJOS, transforms each one into one of our Protobufs, and then writes the protobuf out to our RabbitMQ.
So far so good.
However, it took me quite a bit of work to debug and get that last step working (writing out to the bus). Basically, I could never establish a connection to the bus using ConnectionFactory and instead, eventually figured out how to do it by putting the entire connection/writing to the bus using just the .to() statement in the DSL.
So I'm really, really interested to know what I was doing wrong with ConnectionFactory. Any help would be much appreciated!
Ok, so this is what worked:
(newlines added for clarity)
.to(“rabbitmq://hostname:5672/exchange?
username=user&
password=password&
vhost=sandbox&
exchangeType=topic&
routingKey=routingkey&
durable=false&
autoDelete=false”);
Actually, I have a quick question here: Is doing the above wasteful in the sense that the connection isn't pooled and it's establishing the connection with every single write?
Ok, and this is what didn't work and kept giving me a java.net.ConnectException: Connection refused
error:
RabbitMQEndpoint endpoint = new RabbitMQEndpoint();
endpoint.setHostname(“hostname”);
endpoint.setVhost(“sandbox”);
endpoint.setUsername(“user”);
endpoint.setPassword(“password”);
endpoint.setPortNumber(5672);
endpoint.setRoutingKey(“routingkey”);
endpoint.setExchangeName(“exchange”);
endpoint.setExchangeType(“topic”);
endpoint.setDurable(false);
endpoint.setAutoDelete(false);
Connection connectionFactory = new RabbitMQConnectionFactorySupport().createFactoryFor(endpoint);
So what am I missing??
For what it's worth, if the above connection worked, I was going to write the bus with the following .to() statement. Does it look correct? In particular, can I specify anything after the 'rabbitmq:' in place of the 'bogusbus'?
.to(“rabbitmq:bogusbus?exchangeType=topic&exchangeName=exchange&routingKey=routingkey”);
Thank you so much for your help!
According to the documentation you can configure a com.rabbitmq.client.ConnectionFactory
and then reference it as follows in your route:
.to("rabbitmq:exchangeName?connectionFactory=#rabbitConnectionFactory&...")
Where rabbitConnectionFactory
is the bean name of the connection factory instance in your bean registry (notice the needed #
).
Take care that all connection options on the URI are ignored if you reference a connectionFactory!