I am building a functionality which allows clients to crawl their website, get the links and download the html files. Word count is done on the downloaded files and the cost estimate is shown for translation of the webpages.
I want to make sure that only one estimation is running at a time. So if there are two clients trying to get estimate for their website at the same time, only one clients estimation process will run and other will have to wait.
For this I tried using RabbitMQ which was suggested to me. I am using Coldfusion with framework/1. I used the Java examples given in rabbitmq website. I can send messages but I am having trouble consuming messages. The following function is creating a object and at the same time overriding a function on the fly. This is not possible in coldfusion. I tried getting help in slack and google groups but I didnt get a definitive answer.
final Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
try {
doWork(message);
} finally {
System.out.println(" [x] Done");
}
}
};
channel.basicConsume(TASK_QUEUE_NAME, true, consumer);
I am not well acquainted with Java. I tried my best to convert the above steps in coldfusion. I didnt succeed. I tried the following and I dont even know if it is the right way to do it.
consumer = javaloader.create("com.rabbitmq.client.DefaultConsumer").init(channel);
envelope = createObject("java","com.rabbitmq.client.Envelope");
properties = createObject("java","com.rabbitmq.client.BasicProperties");
consumerTag = toString(consumer.getConsumerTag());
body = javaCast("byte[]",[]);
consumer.handleDelivery(consumerTag,envelope,properties,body);
I have wasted way more time than I need to on this. I need two way communication. I want the estimation process to keep informing the user on every step like crawl started, crawl finished and so on.
I just want to know if it is worth trying to make rabbitmq work or is it even the right tool for the job? I can simply create a table in the database and have a flag in it to queue the process. Which is the best way to achieve the functionality? Are there other useful tools for queueing tasks in coldfusion?
P.S. I have also tried the following solution: https://github.com/lmajano/messaging-polyglot