TCP connection not establishing for bunny on ruby on rails - ruby-on-rails

i am trying to do simple "hello world" program with bunny on ruby on rails.As basic am trying to get connection with tcp its throwing an error.
Could not estabilish TCP connection to 127.0.0.1:5672:
My code:
require "bunny"
begin
conn = Bunny.new
conn.start
rescue => e
puts e
end
what i have to do, am completely new to this.

Related

Faraday::ConnectionFailed (Failed to open TCP connection to api.arknode.net:4001

I am using ark-ruby gem and that code
client = Ark::Client.new(
:ip => 'api.arknode.net',
:port => '4001',
:nethash => '6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988',
:version => '1.0.1'
)
But it gives an error on heroku that Faraday::ConnectionFailed (Failed to open TCP connection to api.arknode.net:4001 (Connection refused - connect(2) for "api.arknode.net" port 4001)):
How can I fix it?
api.arknode.net has been non-responsive for about a week. HTTPS should be used for that URL. You can try changing that to 5.39.9.240 port 4001 for now and just HTTP.
Note: The network is set up with a list of seed servers. You should use a seed server to get a list of peers in which to make API calls. https://ark.brianfaust.me/#/Peer/peers_getPeers.

Rails 2.2.2 - ferret server keeps dying

We've been using ferret in a rails 2.2.2 app for years, and it's been fine (with a few quirks).
Now, though, whenever I try to use it locally, it just dies. I can start it up, and then as soon as Rails (in my local server, or in the console) tries to do a ferret search, the ferret server disappears.
The only feedback I can get is from log/acts_as_ferret.log, which has this:
Will use remote index server which should be available at druby://localhost:9010
[user] DRb connection error: connection closed
[digilearning_support_file] DRb connection error: druby://localhost:9010 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>
[asset] DRb connection error: druby://localhost:9010 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>
[cmw_step_resource] DRb connection error: druby://localhost:9010 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>
/home/max/work/charanga/elearn_container/elearn/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:354 ###index_for [DigilearningTitle(id: integer, name: string, description: text, created_at: datetime, updated_at: datetime, folder_name: string, user_id: integer, summary: text, disk_space_in_megabytes: float, top_level_live_content: boolean, live_content: boolean)]
/home/max/work/charanga/elearn_container/elearn/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:338 ###options: {:offset=>nil, :limit=>nil}
ar_options: {}
[digilearning_title] DRb connection error: druby://localhost:9010 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>
[digilearning_title] /home/max/work/charanga/elearn_container/elearn/vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:42 ### now retrieving records from AR: id_arrays = {}, options: {}
[digilearning_title] /home/max/work/charanga/elearn_container/elearn/vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:43 ### total_ids in id_arrays = 0 (uniq version of this is 0
/home/max/work/charanga/elearn_container/elearn/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:440 ### find_options = {}
[digilearning_title] /home/max/work/charanga/elearn_container/elearn/vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:45 ###0 results from AR
[digilearning_title] /home/max/work/charanga/elearn_container/elearn/vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:69 ### total_hits = 0
/home/max/work/charanga/elearn_container/elearn/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:341 ###Query: "Music"
total hits: 0, results delivered: 0
After I start it, i can see with ps that it's running. But when I start up the rails console, ferret dies. I start ferret with script/ferret_server start, which in turn just requires a file:
#!/usr/bin/env ruby
begin
require File.join(File.dirname(__FILE__), '../vendor/plugins/acts_as_ferret/lib/server_manager')
rescue LoadError
puts "Got a LoadError"
# try the gem
require 'rubygems'
gem 'acts_as_ferret'
require 'server_manager'
end
It's not outputting anything so it's not getting an exception trying to require that file.
I can't understand what has suddenly made it fail like this, though I have been making some changes to what is indexed, for one of the models. I can revert these changes and the problem doesn't go away though.
I don't know how to debug this... can anyone help? thanks
EDIT: I tried deleting all the contents of my index/development folder, thinking there might be something weird in there, but it didn't help.

Elixir Phoenix RabbitMQ MatchError

I am creating messaging app where app A need to send message to app B using rabbitMQ. I am developing using Phoenix and on rabbitMQ web site I found tutorial how to implement rabbitmq with elixir but I don't know how to use it in my Phoenix app. I tried to add code, which I find on rabbit tutorial web site, to my Phoenix page_controller.ex
defmodule ApplicationA.PageController do
use ApplicationA.Web, :controller
use AMQP
def index(conn, _params) do
{:ok, connection} = AMQP.Connection.open
{:ok, channel} = AMQP.Channel.open(connection)
AMQP.Queue.declare(channel, "hello")
AMQP.Basic.publish(channel, "", "hello", "Hello World!")
IO.puts " [x] Sent 'Hello World!'"
AMQP.Connection.close(connection)
render conn, "index.html"
end
end
but I get this error
no match of right hand side value: {:error, :econnrefused}
in line 6
{:ok, connection} = AMQP.Connection.open
Con somebody help me how I should do this on the good way?
You need to specify connection settings for RabbitMQ.
Add in your config/dev.exs something like:
config :my_app, :rabbitmq,
host: "${RABBITMQ_HOSTNAME}",
port: 5672,
username: "${RABBITMQ_UID}",
password: "${RABBITMQ_PWD}"
and then load them:
rabbit_settings = Application.get_env :my_app, :rabbitmq
{:ok, connection} = AMQP.Connection.open(rabbit_settings)

Ruby Net::HTTP.start giving connection refused

I have a ruby class in which I am making Net::HTTP.start call inside perform method.This is the code:
class Poller
def self.perform(args)
uri = URI('http://localhost:8081/adhoc/dummy_poll?noAuth=true')
begin
Net::HTTP.start(uri.host, uri.port, :read_timeout=>30) do |http|
request = Net::HTTP::Get.new uri
#response = http.request request
#responsecode = #response.code
end
rescue Exception => e
Rails.logger.error "error mess==>"+e.message()
#responsecode = "408"
end
When I enqueue this within resque from another class using this line:
Resque.enqueue_in_with_queue(:data_workflow_manager,10,Poller,args)
I get this error:
Connection refused - connect(2) for "::1" port 8081.
However, HTTP.start works fine without any errors when the perform method is called in some another class using:
Poller.perform(args)
Please help me understand, why is this happening?
try explicitly connecting to the loop back address. There may be resolution issues with localhost.
uri = URI('http://127.0.0.1:8081/adhoc/dummy_poll?noAuth=true')
It's likely you do not have any server running on port 8081 which is why the connection will be refused.
Check it with lsof -i and look for programs bound to 8081 on a linux machine.

Lua programming ,error in establishing Database connection

After writing the code to connect to database,lua returns an error as
Error in establishing connection to MySQL ,Can't connect to /var/lib/mysql/mysql.sock
I'm unable to locate the /var/lib/mysql/mysql.sock file (which I haven't created )
My Sock is /tmp/mysql.sock
Below is my code to connect to MySQL database.
mysql = require "luasql.mysql"
local env = mysql.mysql()
local conn = env:connect('test','root','')
print(env,conn)
status,errorString = conn:execute([[CREATE TABLE sample2 (id INTEGER, name TEXT);]])
print(status,errorString )
as seen there: Luasql error: "LuaSQL: error connecting to database", the problem is because luasql defaults to using a default socket path when connecting to localhost without a port. so just set the mysql host and port in env:connect or specify the socket path.
EDIT:
I believe your code should be:
env:connect('test','root','','localhost',3306) -- for tcp
-- or
env:connect('test','root','',':/tmp/mysql.sock') -- for socket

Resources