# Rails or Tomcat - which one to be used for backgorund task?

**URL:** <https://www.ruby-forum.com/t/rails-or-tomcat-which-one-to-be-used-for-backgorund-task/144363>\
**Category:** Rails\
**Created:** [July 29, 2008, 12:53am UTC](https://www.ruby-forum.com/t/rails-or-tomcat-which-one-to-be-used-for-backgorund-task/144363 "2008-07-29T00:53:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@rmehta](https://www.ruby-forum.com/u/rmehta)\
**Post date:** [July 29, 2008, 12:53am UTC](https://www.ruby-forum.com/t/rails-or-tomcat-which-one-to-be-used-for-backgorund-task/144363/1 "2008-07-29T00:53:03Z")

</div>

Hi,

I need advice on a decision that I have to make to decide whether I  
should do background task in Rails or in Tomcat.

What I need to do is that a user of web app will create nnumber of text  
messages which need to be sent to around 10,000+ users. Sms msg is  
passed by the Ruby application to a http server running under Tomcat to  
a java application that further passes the msg to sms gateway to be  
deliverd to user.  
I am planning to put msgs to be sent in a table in mysql by the ruby  
application. Now I am not sure which is the reliable and better way to  
send the msgs in the background - a background task in ruby or a  
backgorund task in java. Also which is the best way to schedule and  
start a background job in ruby/rails to handle such a large number of  
records to be handled?

Thanks for the help in advance.

---

<div class="post-metadata">

**Author:** ![rmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@rmehta](https://www.ruby-forum.com/u/rmehta)\
**Post date:** [July 29, 2008, 3:08am UTC](https://www.ruby-forum.com/t/rails-or-tomcat-which-one-to-be-used-for-backgorund-task/144363/2 "2008-07-29T03:08:34Z")

</div>

I dont think your challenge is where to run the background task as much  
as  
it is how to handle sending of large number of messages between systems.  
I  
would recommend you look at leveraging a messaging broker like ActiveMQ  
that  
will allow you to send messages asynchronously to a message queue that  
can  
then be picked up for processing by your java application with some JMS  
client code.  
have a look here for some example code on writing a JMS client in JRuby  
that  
would allow you to put messages onto the queue

[Adam Denenberg's Blog: JMS JRuby Producer and Consumer](http://blog.dberg.org/2008/07/jms-jruby-producer-and-consumer.html).  
That is  
of course if you are using JRuby.

If you are using straight MRI ruby/rails then have a look at integrating  
ActiveMQ with Activemessaging using the STOMP Protocol.

[http://code.google.com/p/activemessaging/wiki/ActiveMessaging](http://code.google.com/p/activemessaging/wiki/ActiveMessaging)

Adam
