osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RabbitMQ: ConnectionFactory gives "Connection refused" yet I can write all in one .to()


Hi All.


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.


Great, right?


Well, 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!