New to ActiveMQ. Using ruby stomp gem. I believe I'm successfully publish'ing messages to the server, as I see them in the queue in my browser admin client. But on subscribe nothing happens, no error, no output. The "in subscribe" test text from puts never appears in stdout, nor does the msg.
Should I be using a different naming format for the queues?
require 'stomp'
port = 61613
client = Stomp::Client.new( 'admin', 'admin', '127.0.0.1', port )
client.publish("/queue/mine2", "hello world!")
puts "about to subscribe"
client.subscribe("/queue/mine2") do |msg|
puts "in subscribe"
puts msg
end
client.close
I believe You are closing the client before it gets a chance to receive anything.
If there is no preemption between client.subscribe and client.close background thread that listens for new messages never gets run.
You should try adding
client.join
before closing it.
Although client.join did successfully pull down the first message or two for me, after it ran, the code completely stopped working, and the subscriber would simply hang again. I was starting my client in a very similar way (just lacking creds):
client = Stomp::Client.new('localhost', 61613)
But I was able to get it working by using a URL instead:
client = Stomp::Client.new('stomp://localhost:61613')
With creds, it would look something like:
client = Stomp::Client.new('stomp://login:passcode#host:port')
Hope this helps the next person with this issue.
Related
I downloaded the red5-recorder (http://www.red5-recorder.com/) , which fails to allow me to start recording. After debugging I found that the netconnection, needed to record to a media server, created does not fire a NetStatusEvent event, so essentially it fails silently. I have implemented the connection with the following minimal working example:
trace("make net connection");
nc = new NetConnection();
nc.client = { onBWDone: function():void{ trace("bandwidth check done.") } };
trace("add event listener");
nc.addEventListener(NetStatusEvent.NET_STATUS, function(event:NetStatusEvent) {
trace("handle");
});
trace("connect!");
nc.connect("rtmp://localshost/oflaDemo/test/");
trace("connect done");
The output of this piece of code is:
make net connection
add event listener
connect!
connect done
The actionscript api states that the connect-call always fires such an event:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetConnection.html#includeExamplesSummary
Moreover, the netconnection is not 'connected' (a state of the NetConnection object) 10 seconds after the call. I also took a look at this: NetConnect fails silently in Flash when called from SilverLight But the fix suggested by the author, swapping rtmp and http in the connection uri, do not work. Also, I tested the uri and in fact the exact same code sniplet in a personal project, where it did work. I just can not seem to find why connecting to a media server fails silently in the red5-recorder project.
The awkward part is that if I pass some random string as a conenction uri, still nothing happens (no event, no exception, no crash). Also not setting nc.client becore nc.connect(), which caused exceptions in my experience, did not cause exceptions.
Any suggestions are welcome.
You are setting the address to localshost instead localhost.
nc.connect("rtmp://localshost/oflaDemo/test/");
Correct address:
nc.connect("rtmp://localhost/oflaDemo/test/");
I have stream of data coming to me via an http hit. I want to update data in realtime. I have started pushing HTTP hits data to a redis pubsub. Now I want to show it to users.
I want to update user's screen as soon as I get some data on redis channel. I want to use ruby as that is the language I am comfortable with.
I would use Sinatra's "stream" feature coupled with EventSource on the client side. Leaves IE out, though.
Here's some mostly functional server side code pulled from https://github.com/redis/redis-rb/blob/master/examples/pubsub.rb (another option is https://github.com/pietern/hiredis-rb):
get '/the_stream', provides: 'text/event-stream' do
stream :keep_open do |out|
redis = Redis.new
redis.subscribe(:channel1, :channel2) do |on|
on.message do |channel, msg|
out << "data: #{msg}\n\n" # This is an EventSource message
end
end
end
end
Client side. Most modern browsers support EventSource, except IE:
var stream = new EventSource('/the_stream');
stream.onmessage = function(e) {
alert("I just got this from the server: " + e.data);
}
As of I know you can do this via Faye check this link out
There are couple approach If you wish you can try
I remember myself building a Long Polling server using thin and sinatra to achieve something like this now If u wish you can do the same
I know of few like this and this flash client that you can use to connect directly to redis
There is EventMachine Websocket implementation u can use and hook it up with HTML 5 and Flash for non HTML 5 browser
Websocket-Rack
Other Approach you can try just a suggestion since most of them arent written in ruby
Juggernaut ( I dont think it based on Redis Pub-sub Thing also there used to ruby thing earlier not sure of now)
Socket.io
Webd.is
NULLMQ Not a redis pub sub but this is Zero MQ implementation in javascript
There are few other approach you can find If u google up :)
Hope this help
I have faye implementation in my rails application. The publish method works correctly when both browsers are on the same computer. When I access the application from another browser on another computer, it only works from client to server and does not publish to other clients. Also the publish event does not push to client when there are changes in the browser on the server.
Controller publish code:
def publish(channel, data)
message = {
:channel => channel,
:data => data,
:ext => {:faye_token => FAYE_OUTGOING_AUTH_TOKEN}
}
uri = URI.parse('http://localhost:9292/faye')
Net::HTTP.post_form(uri, :message => message.to_json)
end
Command to run faye:
rackup faye.ru -s thin -E production -d
Example:
A: Server,
B: Client1,
C: Client2
A B and C are different computers in same network, and are all subscribed to the same channel.
If I input data on B, A will see the data but C will not see the data until I refresh the page (Which is getting the data from db).
If I input data on A, it does not get published to the other clients.
If I input data on C, to a channel that only C and B are subscribed to, only C gets to see the data, and it is not published to B.
If A, B, and C were different browsers on the same computer, all the above cases would work.
I have ran this in Development mode, and have tried WEBrick, Unicorn, and Thin.
Any help would be appreciated.
Thanks.
To resolve the issue I replaced all instances of "localhost" with the address of the server on which Faye is running. This includes for subscribing clients to channels as well.
Hope it helps,
Cheers!
Hey Babak: I am also facing same kind of problem, I am using nodejs + express + faye. so I should add ip_addr:port to each subscribe,client
var client = new Faye.Client('/faye',{
endpoints:{
websocket:'http:ws.chat-yummyfoods.rhcloud.com'
}
,timeout: 20
});
client.disable('websocket');
console.log("client:"+client);
var subscription=client.subscribe('/channel', function(message) {
console.log("Message:"+message.text);
$('#messages').append('<p>'+message.text+'</p>');
});
subscription.then(function(){
console.log('subscribe is active');
alert('subscribe is active');
});
I have a carrierwave upload that takes a lot of time to process, but is required to finish before the user can continue on to the next action in the browser. I'm using an Ajax file upload on the front-end, so the app UI gives progress updates on the upload and processing. This works fine on my dev environment because the timeout on my dev server is relatively long, however not so good on Heroku since Cedar times out the request after 30 seconds if no response is sent. I've been trying to create a streaming response which sends a space every couple of seconds until the process has completed by creating a response object which responds to each thus:
class LongPoller
def initialize(yield_every=2,task)
#yield_every = yield_every
#task = task
end
def each
t = Thread.new(&#task)
while t.alive?
sleep #yield_every
yield ' '
end
yield t.value.to_json
end
end
This isn't working as expected though, because Thin seems to be batching the responses and not sending them back to the client.
Anyone have any ideas how I can get this to work?
Im using Pony to send email withing my sinatra applications. But the problem - i cant figure out how to debug or test it. Lest say, in php you can configure sendmail fake app (in php.ini) that will store all outgoing email as plain textfiles with all data in it.
How about ruby apps? Is it possible?
You surely found the solution already yourself
In the pony.rb file there is this code part which sends the mail:
def self.transport(tmail)
..
end
You can simply add a method to return the env:
def debug?
true #false
end
and do something special if debug mode is on
def self.transport(tmail)
puts "Debug message" if debug?
if File.executable? sendmail_binary
transport_via_sendmail(tmail)
else
transport_via_smtp(tmail)
end
end