Abdulrazak-Alkl / activemessaging

Automatically exported from code.google.com/p/activemessaging
0 stars 0 forks source link

Timed out trying to send the message #23

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. using rails to send a message to destination
2.
3.

What is the expected output? What do you see instead?

sometimes  raised error:
"Timed out trying to send the message ... to destination queue_XXX via
broker default "

but sometimes it is worked ok!

What version of the product are you using? On what operating system?
activemessaging VERSION = "0.5" , rails app operating system :  x86_64
x86_64 x86_64 GNU/Linux (Red Hat 4.1.1-52) , ruby version=1.8.6 (2007-03-13
patchlevel 0) [x86_64-linux], Rails 1.2.3;
Active MQ version=4.1.1; and operating system : windows XP,SP2

Please provide any additional information below.

 publish timeout =10;
broker.yml file:
production:
    adapter: stomp
    login: ""
    passcode: ""
    host: xxx.ddns.us
    port: 61683
    reliable: false
    reconnectDelay: 5

i try to telnet xxx.ddns.us 61683 ,It is ok.

Original issue reported on code.google.com by domat...@gmail.com on 20 Nov 2007 at 2:59

GoogleCodeExporter commented 8 years ago
activemq 4.1.1 is not recommended.

I also see both windows xp and redhat listed - which is running rails, and 
which is
running activemq?

Original comment by kooks...@gmail.com on 20 Nov 2007 at 9:25

GoogleCodeExporter commented 8 years ago
thanks for you reply.
"activemq 4.1.1 is not recommended." ; and what version i will use?

activemessaging VERSION = "0.5" , rails app operating system :  x86_64
x86_64 x86_64 GNU/Linux (Red Hat 4.1.1-52) , ruby version=1.8.6 (2007-03-13
patchlevel 0) [x86_64-linux], Rails 1.2.3;

Tomorrow, i catched the exception:
/usr/local/ruby/lib/ruby/1.8/timeout.rb:54:in `open'
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:56:in `socket'
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:216:in 
`transmit'
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:138:in `send'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb:248:i
n
`publish'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb:146:i
n
`execute_filter_chain'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb:247:i
n
`publish' /usr/local/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb:246:i
n
`publish'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/processor.rb:21:
in
`publish' [RAILS_ROOT]/app/models

But when i restart the lighttpd(runs rails), it often goes ok.

Original comment by domat...@gmail.com on 21 Nov 2007 at 2:52

GoogleCodeExporter commented 8 years ago
And aother exception a got:

Connection reset by peer
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:230:in `write'

/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:230:in `write'
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:230:in `puts'
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:230:in 
`_transmit'
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:229:in 
`synchronize'
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:229:in 
`_transmit'
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:217:in 
`transmit'
/usr/local/ruby/lib/ruby/gems/1.8/gems/stomp-1.0.5/lib/stomp.rb:138:in `send'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb:248:i
n
`publish'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb:146:i
n
`execute_filter_chain'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb:247:i
n
`publish' /usr/local/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb:246:i
n
`publish'
[RAILS_ROOT]/vendor/plugins/activemessaging/lib/activemessaging/processor.rb:21:
in
`publish'

Original comment by domat...@gmail.com on 21 Nov 2007 at 3:01

GoogleCodeExporter commented 8 years ago
The problem may be in the code gateway.rb -->
      def connection broker_name='default'
        return @@connections[broker_name] if @@connections.has_key?(broker_name)
        config = load_connection_configuration(broker_name)
        @@connections[broker_name] = Gateway.adapters[config[:adapter]].new(config)
      end
the connect which is in the connection pool,may be dead , when reusing it may be
throw timeout exception;

so i change it to -->
      def connection broker_name='default', re_connect=false
        return @@connections[broker_name] if @@connections.has_key?(broker_name) and
not re_connect
        config = load_connection_configuration(broker_name)
        @@connections[broker_name] = Gateway.adapters[config[:adapter]].new(config)
      end

also changed this code -->
        begin
          Timeout.timeout timeout do
            execute_filter_chain(:out, message, details) do |message|
              connection(real_destination.broker_name).send real_destination.value,
message.body, message.headers
            end
          end
        rescue Timeout::Error
          begin
            Timeout.timeout timeout do
              execute_filter_chain(:out, message, details) do |message|
                connection(real_destination.broker_name,true).send
real_destination.value, message.body, message.headers  #recreate connection
              end
            end          
          rescue Timeout::Error=>toe
               ActiveMessaging.logger.error("Timed out trying to send the message
#{message} to destination #{destination_name} via broker
#{real_destination.broker_name}")
               raise toe
          end
        end
when throw timeout exception first time , recreate connection in the pool.
now the application run's better :)

but i think it's not the good solution,
who can give me other better solution?

Thanks!

Original comment by domat...@gmail.com on 27 Nov 2007 at 7:59

GoogleCodeExporter commented 8 years ago
For activemq, use some flavor of 5, which used to be the 4.2 branch; it has some
fixes related to how the server manages lost connections that you will want.

For the connection, let's remember that you are using stomp, which is just an 
http
connection, so really, the connection object is just the info used to contact 
the
service, not really an open connection as would be implied by just looking at 
the
activemessaging code.  In fact, a new tcp connection is attempted on each call 
to
transmit in the stomp gem. The line in the stomp gem that is failing is 56:

            s = TCPSocket.open @host, @port

So the timeout is occurring in trying to create a TCPSocket connection to the 
stomp
server.  If this call works on a retry (which will just try the exact thing 
again),
then it implies there is something flaky in the network between your client and
server, probably not a code problem, though you are totally right that the best 
you
can do sometimes is just retry since networks can be flaky.

That's all background/analysis really, here's a solution to try:

There is retry logic already built into the stomp gem, you enable it in your
broker.yml file by setting "reliable: true" - this will cause the broker to 
retry the
transmission rather than just throwing an error - no need to add your own retry 
code
for this.  

Give that a whirl and see how it does for you, and you might also have a look 
at the
network between the boxen and see if there is a significant packet loss in 
getting
from A to B.

Original comment by kooks...@gmail.com on 27 Nov 2007 at 3:23

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
in my broker.yml file :
"reliable: false" 
because the network between A and B is often  significant packet loss , so much 
as
B(activemq server) is down,

but the whole process(including send message to ativemq and othen process) must 
be
finished .

so have any setting such as "retry times" in broker.yml when i using "reliable:
true" ? i think that  i need this parameter setting.

Thanks very much.

i have already upgraded the activemq to the newest version 5.0

Original comment by domat...@gmail.com on 27 Nov 2007 at 4:52

GoogleCodeExporter commented 8 years ago
the reliable flag, and the way it is handled (i.e. how many times to retry) is 
in the
stomp gem, not in activemessaging.

That said, turn on reliable, and if you want to limit how long to wait for it 
to come
back on a send/publish, there is a timeout value you can set on the publish 
method,
here is the signature:

def publish destination_name, body, publisher=nil, headers={}, timeout=10

By default, it will only try to publish for 10 seconds, increase as you will.

-Andrew

Original comment by kooks...@gmail.com on 18 Dec 2007 at 9:02

GoogleCodeExporter commented 8 years ago
Thanks,it's ok now.

Original comment by domat...@gmail.com on 29 Jan 2008 at 2:39

GoogleCodeExporter commented 8 years ago
ok - closing this out then.

Original comment by kooks...@gmail.com on 29 Jan 2008 at 2:43