Monday, 17 November 2014

Textual description of firstImageUrl

How to Use ActiveMQ in Rails App

Active MQ is one of the most popular messaging server . In this post we will list out the steps on how to use it in rails application.

Installation ActiveMQ procedure for Ubuntu 14.04

Download ActiveMQ 5.4.2 from http://activemq.apache.org/download.html or you can install it from console by writing following command .
sudo apt-get install activemq
Now start the server by writing following command :
$ ./activemq start
Now , for connecting activeMQ server , we can use Stomp Gem .

So for sending message , open IRB prompt and write following command :
$ irb req1.9.3-p362 :001 > require "stomp"=> true 
1.9.3-p362 :002 > client = Stomp::Client.new("admin", "admin", "localhost", 61613)
You might get error like this :
Errno::ECONNREFUSED: Connection refused - connect(2)
 from /home/usermac44/.rvm/gems/ruby-1.9.3-p362/gems/stomp-1.3.3/lib/connection/netio.rb:203:in `initialize'
We have to configure stomp protocol on our activemq server like this : Add the following line to the configuration file:
  <transportConnectors>
    <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireformat.maxFrameSize=104857600"/>
  </transportConnectors>
Now restart activemq , initiate the client and send message like this :
client = Stomp::Client.new("admin", "admin", "localhost", 61613)
 => #"0,0", 
"session"=>"ID:ACSMAC05-63136-1415951184416-2:1", "server"=>"ActiveMQ/5.8.0", "version"=>"1.0"} ......#>


client.publish {|msg|  puts msg }
It will work now . You can see the active mq console at http://localhost:8161/admin .


Thanks to santosh for writing this post .