Sending message to ZeroMQ from Rails 4 - zeromq

I'm trying to send message to ZeroMQ from Rails 4 application.
I added gem "zmq" to my Gemfile, then I use this code in some method in my Application Controller.
context = ZMQ::Context.new(1)
Rails prints exception:
uninitialized constant ApplicationController::ZMQ
If I add require 'zmq'to application_controller.rb Rails prints other message:
cannot load such file -- zmq

I found the reason of this error. Gem zmq (rb-zmq) doesn't work correctly with ZeroMQ 3.x.x, only with 2.x.x:
https://github.com/zeromq/rbzmq/issues/25

Related

Rails 3.2 ruby 1.9.3 exception_notification in staging not able to send mail

I am applying exception notification gem for rails 3.2 application.
Following is my code
gemfile
gem 'exception_notification'
config/environments/staging.rb
Rails.application.config.middleware.use ExceptionNotification::Rack, email: {
email_prefix: '[Exception] ',
sender_address: %('HPAE - Error' <mymail#gmail.com> ),
exception_recipients: %w(mamail1#gmail.com)
}
It runs perfectly in my local but on server in staging its not working. I am not receiving any error mails from staging.
Do I need to change my code or do any setting?
Thanks,

How can I redirect error messages to the browser in CGI/Ruby?

I've been using CGI/Perl for a while and have got used to using Carp to redirect error messages to the browser with something like:
use CGI::Carp qw(warningsToBrowser fatalsToBrowser set_message);
set_message("Please report this error to the administrator");
...
warningsToBrowser(1);
I'm considering making the switch to using Ruby instead of Perl, but I can't find a way to do a similar error redirection. Is there a Ruby module which can do this?
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end
See this railscast: Better Errors & RailsPanel and this thread redirect errors to browser in ruby + cgi, where it suggests this:
$stdout.sync = true
$stderr.reopen $stdout
puts "Content-type: text/html\n\n"`
The content-type needs to be early in the code, as any errors before it will not be sent to the browser.

Ruby and ActiveMQ. AMQ339016: Error creating subscription Stomp::Error::BrokerException

I am running a simple Ruby program to produce and consume ActiveMQ Stomp messages. I keep on getting this error.
/root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/stomp-1.3.4/lib/stomp/client.rb:132:in `join': AMQ339016: Error creating subscription f7b282396a9bef2da1ccd42d16dc511758234113 (Stomp::Error::BrokerException)
from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/stomp-1.3.4/lib/stomp/client.rb:132:in `join'
from consumer.rb:10:in `<main>'
I made sure ActiveMQ is up and from I can tell it is not necessary to configure the xml config files since ActiveMQ is supposed to support Stomp out of the box. My program looks like this:
require 'rubygems'
require 'stomp'
client = Stomp::Client.open "stomp://localhost:61613"
client.subscribe "/queue/myqueue" do |message|
puts "received: #{message.body} on #{message.headers['destination']}"
end
client.join
client.close
puts "completed process"
The full example code can be found here:
http://arhipov.blogspot.com/2009/05/activemq-ruby-stomp-transport.html

Sinatra and Activerecord "cannot load such file -- sinatra/activerecord"

I'm following Micheal Herman's post on Sinatra + PostgreSQL + Heroku, put keep running into an error
require 'sinatra/activerecord'
when I try to launch the app ($ ruby app.rb) or create my database ( $ rake db:create_migration NAME=...) I keep receiving the following error:
cannot load such file -- sinatra/activerecord
sinatra-activerecord-1.2.3 is in my gemlist. What am i missing?
it worked for me after changing this line in environments.rb
sqlite:///dev.db
to
sqlite3:///dev.db

wrong number of arguments (3 for 2) after upgrading from Rails 3.0.14 to Rails 3.1.4

Everything was working fine in Rails 3.0.14, but after changing
gem 'rails', '3.0.14' to gem 'rails', '3.1.4' and running bundle update rails I now get the following error:
Started GET "/" for 127.0.0.1 at 2012-03-16 11:11:44 -0400
Processing by PagesController#index as HTML
Completed 500 Internal Server Error in 54ms
ArgumentError (wrong number of arguments (3 for 2)):
app/controllers/application_controller.rb:37:in `customize_by_subdomain'```
The most popular answer seemed to be that sqlite3 needed to be updated, but I did bundle update sqlite3 and I still have the same problem.
Here is the full trace: https://gist.github.com/2050530
The method that it is complaining about looks like this:
35 def customize_by_subdomain
36 subdomain = (request.subdomain.present? && request.subdomain != 'www' && request.subdomain) || 'launch'
37 #current_org = Organization.find_by_subdomain(subdomain) || Organization.find_by_subdomain('launch')
38 end
I have looked at the multitude of similar questions and I not found anything that solves my problem. The closest was question to mine was: wrong number of arguments (3 for 1) after upgrading rails from 3.1.1 to 3.1.3 but I am using authlogic and the version I am using didn't change after upgrading rails.
The only other interesting thing is my entire test suite passes, except for one request/integration spec which goes through the process of creating a new user. It seems strange that my request specs work fine when I can't even access a page in development.
Any ideas on what I can do to get to the bottom of this?
It looks like your New Relic plugin may need to be updated to a new version. In your stacktrace, the first line is from the New Relic code in your plugins folder. From their site, it looks like they released new Rails 3.1-specific code:
http://blog.newrelic.com/2011/07/29/for-the-active-record-new-relic-support-for-rails-3-1-is-here/
In the blog post, they talk about changes to the way ActiveRecord does logging, and your exception was triggered on the log_with_instrumentation method.
It looks like now you should install it as a gem rather than a plugin:
https://github.com/newrelic/rpm
Hope this helps.

Resources