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?
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);
Related
I have a Apache Camel route that starts with a Mail consumer, followed by some custom processing steps as part of several sub-routes. All routs are connected directly. When some processing fails downstream, the failed exchange returns to the Mail consumer, which performs a rollback and puts the mail message currently being processed back into its original unread state in the inbox:
2022-11-18 16:23:13 WARN MailConsumer:572 - Exchange failed, so rolling back message status: Exchange[7A8EE72E3AFB7CC-00000000000000C0]
This again triggers the Camel mail consumer, resulting in an error loop. I do have a Camel error handler configured for some part of the processing, but not all of it.
How can I configure the mail consumer such that a downstream processing failure does not return the mail back to its unread state?
The mail consumer is configured as follows:
.from("imaps://{{imapPath}}?username={{imapUserName}}&password=RAW({{imapPassword}})&delay={{imapPollingPeriodMs}}&moveTo={{processedMailFolderName}}")
I have one of the camel route as follows, there are many routes.
from("jms:queue:TEST.LQ?transacted=true&connectionFactory=jmsConnectionFactory&cacheLevelName=CACHE_NONE")
.routeId("routeid")
.autoStartup("true")
.transacted("requried")
....
....
I getting below error if TEST.LQ MQ or Queue manager is unavailable.
ERROR [JmsConsumer[TEST.LQ]] [] [o.a.c.c.j.DefaultJmsMessageListenerContainer ] Could not refresh JMS Connection for destination
I tried to handle exception by catching below code, but JmsMessageListenerContainer only throws the message not an exceptiom
onException(MQException.class, JMSException.class)
How stop route if IF MQ is not available?
The camel jms component has the option for this -
Add the testConnectionOnStartup=true option in your from(uri) :
from("jms:queue:TEST.LQ?transacted=true&connectionFactory=jmsConnectionFactory&cacheLevelName=CACHE_NONE&testConnectionOnStartup=true")
This will throw an exception if a connection is not available during startup which can then be handled.
More details are available in the jms-component page
#sree1611,
You can add exceptionListener or errorHandler query parameter in camel jms uri.
To create your own exception listener, implement org.apache.camel.spi.ExceptionHandler
To create your own error handler, implement org.springframework.util.ErrorHandler
I hope errors while consuming from MQ can't be bridged with camel error handlers, so you can't catch JMS exceptions (occurred during message consumption from MQ) in onException().
I'm using apache camel xml based paho routes for the subscription, publication process. While online, everything works fine. But I'm not able to receive the offline message.
I have set the following.,
Constant Client ID
Clean Session is FALSE,
Both subscribed & published with QoS 2
With the standalone Program, it's getting all the offline messages. With the camel route it's not happening.
Finally, I was able to solve this one manually.
Camel PAHO Client is not populating the callback function before performing the broker connection. They are doing it only when the connection is made.
So, once the connection is success then the broker just sends all the offline messages. In this case, our client does not have callback handlers to handle these messages. So they are lost.
Other clients (IoThub Client) which uses the PAHO internally is doing it right by setting the callback and initiating the connection.
I am using camel jms in a synchronous way using request-reply pattern.The camel route exposes a cxf endpoint and it places the message in to the jms queue another component process it and sends the response in replyto queue.
A new thread is getting created while receiving the reply from replyto queue?Iam facing issues with using log4j MDC with in the camel route.The values store in MDC are no more available?
Is it the behaviour of camel jms request/reply pattern?
Below is the JMS endpoint:
<to id="QueueEndpoint" pattern="InOut" uri="hornetq:queue:{{esb.api.requestqueue}}?replyTo=queue:{{esb.api.responsequeue}}&useMessageIDAsCorrelationID=true&replyToType=Exclusive&requestTimeout={{esb.api.queue.requesttimeout}}"/>
I have a Camel route which Consumes messages from a Queue and stores the message into a Database. Now I wanted to shut down running camel route manually in a graceful manner. I have a RestEndpoint to be triggered whenever I need to stop Camel route. This endpoint should stop the route. But if there is any in-flight message or transaction running during the shutdown it has to be completed successfully without consuming any new messages from from("") endpoint of camel route and shut down after completing inflight message or transaction. Can anyone help me how Can I code this?
Below are the few options to control/monitor camel routes
CamelContext API's
Control bus component
JMX API's
You can go through below two sites to get started
http://camel.apache.org/controlbus.html
https://dzone.com/articles/apache-camel-monitoring
shutdownRunningTask(ShutdownRunningTask.CompleteCurrentTaskOnly)