vitorvr
vitorvr

Reputation: 655

Sending messages to Azure Servicebus Queue using Apache Camel

I need to send messages to a queue in Azure Service Bus. I was using HTTP Post to send that messages, but I need to improve my flow rate, then I decided to test AMQP protocol.

Below the code:

public void configure() throws Exception {

    AMQPComponent amqp = AMQPComponent.amqpComponent("amqps://server.servicebus.windows.net",
                                "accessKey", "secretKey");

    getContext().addComponent("amqp", amqp);

    ActiveMQJMSConnectionFactory connection = new ActiveMQJMSConnectionFactory("tcp://localhost:61616",
                                "admin", "admin");

    getContext().addComponent("amq", JmsComponent.jmsComponent(connection));

    from("amq:TEST")
     .routeId("fromQueueToAzure")
     .autoStartup(true)
     .removeHeaders("JMS*")
     .to("amqp:amqp.queue")
     .log("sent");
}

When I start this route, the communication works, but for every message that Camel are sending to Servicebus, I got this log:

2019-02-07 18:47:11 [main] INFO  DefaultCamelContext:3202 - Apache Camel 2.22.0 (CamelContext: camel-1) started in 0.602 seconds
2019-02-07 18:47:12 [AmqpProvider :(1):[amqps://server.servicebus.windows.net:-1]] INFO  SaslMechanismFinder:106 - Best match for SASL auth was: SASL-PLAIN
2019-02-07 18:47:12 [AmqpProvider :(1):[amqps://server.servicebus.windows.net:-1]] INFO  JmsConnection:1329 - Connection ID:5f75145f-6f10-4867-a590-782e507d51a8:1 connected to remote Broker: amqps://server.servicebus.windows.net
2019-02-07 18:47:13 [Camel (camel-1) thread #1 - JmsConsumer[TEST]] INFO  fromQueueToAzure:159 - sent
2019-02-07 18:47:14 [AmqpProvider :(2):[amqps://server.servicebus.windows.net:-1]] INFO  SaslMechanismFinder:106 - Best match for SASL auth was: SASL-PLAIN
2019-02-07 18:47:14 [AmqpProvider :(2):[amqps://server.servicebus.windows.net:-1]] INFO  JmsConnection:1329 - Connection ID:08ea246c-523e-4eb3-822e-c7d7b26aea85:2 connected to remote Broker: amqps://server.servicebus.windows.net
2019-02-07 18:47:15 [Camel (camel-1) thread #1 - JmsConsumer[TEST]] INFO  fromQueueToAzure:159 - sent
2019-02-07 18:47:16 [AmqpProvider :(3):[amqps://server.servicebus.windows.net:-1]] INFO  SaslMechanismFinder:106 - Best match for SASL auth was: SASL-PLAIN
2019-02-07 18:47:16 [AmqpProvider :(3):[amqps://server.servicebus.windows.net:-1]] INFO  JmsConnection:1329 - Connection ID:c8c40237-a73c-43cf-970d-c5cbf726eb21:3 connected to remote Broker: amqps://server.servicebus.windows.net
2019-02-07 18:47:17 [Camel (camel-1) thread #1 - JmsConsumer[TEST]] INFO  fromQueueToAzure:159 - sent

Camel is spending one second per message to send to Servicebus. Is it a normal behavior? Is it possible to make Camel send faster?

Upvotes: 0

Views: 1450

Answers (1)

Tim Bish
Tim Bish

Reputation: 18356

It appears that on each send the Camel route is creating a new Connection so that would explain why your sends are slow. In order to improve performance you'd want to use something like PooledJMS to create a connection pool so that a new connection and accompanying resources aren't recreated on each send.

You could try something like the following which uses the camel-amqp component but uses Qpid JMS directly with PooledJMS to configure it.

    JmsConnectionFactory cf = new JmsConnectionFactory("amqp://localhost:5672");
    JmsPoolConnectionFactory pooledCF = new JmsPoolConnectionFactory();
    pooledCF.setConnectionFactory(cf);

    AMQPComponent component = new AMQPComponent();
    component.setConnectionFactory(pooledCF);

    CamelContext context = new DefaultCamelContext();
    context.addComponent("amqp", component);

Upvotes: 1

Related Questions