Very Fast Camels and Cloud Messaging
Join the DZone community and get the full member experience.Join For Free
apache camel is a popular, mature, open-source integration library. it implements the enterprise integration patterns which is a set of patterns that often come up when integrating distributed systems. i've written a lot about camel in the past, including why i like it better than spring integration , how the routing engine works , how to use jms selectors with aws sqs , and a lot more .
camel also implements 197 connectors/adapters for talking to external systems (go to the source code, components/ directory and run this: ls -lp components/ | grep / | wc -l), github has a lot more , and you can write your own pretty trivially. this gives camel a much broader range of connectivity options than any other integration library.
recently, i was fortunate to be able to help out a top, household-named, e-retailer with their use of camel. they take online orders and process them using an event driven architecture which includes publishing events like "order_received", "order_cancelled", "order_ready_to_ship" and others. these events are handled by microservices interested in participating in the order processing flows, and are quite loosely coupled because of the eda in place.
the nature of this type of retail business in question is very seasonal. and there are times during the year (holidays, etc) that tend to increase load by orders of magnitude. so being able to scale without outages to meet these seasonal peaks is paramount.
luckily, as they're a smart bunch, they use apache camel for their integrations, and specifically the implementation of some of these services. each order generates quite a few events, and they must be processed in a timely fashion and keep up with the rest of the load. the queueing service for this was amazon sqs, and camel has an aws sqs component for that.
for nominal load, camel was processing these events just fine. but when the queue got deeper, camel was having some trouble keeping up. we were only getting 200 messages per minute, which doesn't pass the smell test. digging in a little deeper, we found that the aws libraries allow you to scale vertically increasing the number of connections and by batching message delivery (max, 10 batched messages). batching helps, and camel was implemented to deal with the batching, but it still wasn't fast enough, only about 10k messages per hour.
upon further digging we could see only a single thread was handling the polling of the message queue. so instead of processing the messages inline with the thread that polls the queue, we decided to use a seda queue so that we can pull messages from sqs and quickly dump into an in-memory queue so we could start the next poll, something like this:
from("amazon-sqs://order.queue").to("seda:incomingorders"); from("seda:incomingorders").process(do our processing in another thread...);
this allowed us to deal with the load using the staged event driven architecture pattern. this change gave us another boost in performance to about 40k messages per hour, but we're talking about a very popular commerce site, so still not enough scaling to meet the needs of the system during peak.
so we took one more look and wondered why we couldn't have multiple threads/connections polling at once? the aws libraries were written with this in mind, but there wasn't a way to configure camel to do this for this specific type of endpoint. camel can do this for other endpoints (jms, seda, etc), but we needed to make a small little change in camel sqs for this.
and here's the beauty of using open-source, community-style, development philosophies: the code is open, the community is welcoming of changes, and now future users of camel and its functionality can reap the benefits of this collaboration.
so we committed a patch that allows you to set a concurrentconsumers option on the sqs queue which will ramp up the number of threads used for connecting to and polling the queue. something like this:
from("amazon-sqs://order.queue?concurrentconsumers=50").to(.... processing here....)
see the documentation on camel-sqs for more information . this change will be part of the apache camel 2.15.0 release which should be coming out in the next couple of weeks.
with this setting, we were able to handle all of the load black friday and cyber monday could throw at the site, at one point processing > 1.5 million messages per hour.
thank you open source!
for more camel , activemq , microservices, and cloud goodness, follow me on twitter @christianposta and my blog http://christianposta.com/blog
Published at DZone with permission of Christian Posta, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Introduction To Git
Authorization: Get It Done Right, Get It Done Early
Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer