notify a web-service: sending non-blocking http requests

Discussion in 'Ruby' started by d c, Dec 24, 2007.

  1. d c

    d c Guest

    hi -

    i want to notify a webservice of something, but not wait for the
    response. whats the best way to do this?

    is there a way to use a GET call to just send a request and then continue?

    i could use the timeout library i guess with a timeout of 0 ? which i
    guess spawns a thread...

    or use
    system("curl #{url}")

    but this seems like a lot of overhead.

    is there a UDP package for ruby?
    i guess another hack might be to return a page to the user with a GIF
    image with a URL of the service i want to request,
    then it will take no resources from my system...
    <img width=1 height=1 src='http://server/notify/event" />

    tx

    /dc
    d c, Dec 24, 2007
    #1
    1. Advertising

  2. d c

    Curt Sampson Guest

    On 2007-12-24 21:47 +0900 (Mon), d c wrote:

    > i want to notify a webservice of something, but not wait for the
    > response. whats the best way to do this?


    HTTP doesn't let you do this reliably. The best thing to do is change
    the service so that it returns immediately to acknowledge receipt of the
    request. Then just use standard Net::HTTP.

    > i could use the timeout library i guess with a timeout of 0 ? which i
    > guess spawns a thread...


    Or just spawn a thread and then have the thread wait for the response.
    Be careful, however; Ruby threads are not asynchronous when you're
    waiting for IO, unless you're careful to wait in select().

    > or use
    > system("curl #{url}")


    That will wait for the response.

    > is there a UDP package for ruby?


    Yes, but you can't do HTTP over UDP; you're misunderstanding the protocol.

    cjs
    --
    Curt Sampson <> +81 90 7737 2974
    Mobile sites and software consulting: http://www.starling-software.com
    Curt Sampson, Dec 24, 2007
    #2
    1. Advertising

  3. [Note: parts of this message were removed to make it a legal post.]

    On Dec 24, 2007 7:47 AM, d c <> wrote:

    > hi -
    >
    > i want to notify a webservice of something, but not wait for the
    > response. whats the best way to do this?
    >
    > is there a way to use a GET call to just send a request and then continue?
    >



    If you're able to use the Ruby/EventMachine library, it solves this problem
    easily. Whether you can use it depends on the structure of your program.

    The HTTP client inside of EM returns a "Deferrable" object, which
    synchronously notifies your program when the HTTP request completes.
    Francis Cianfrocca, Dec 24, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendra Gunawan
    Replies:
    1
    Views:
    12,440
    Allan Herriman
    Apr 8, 2004
  2. Andre Kelmanson

    blocking i/o vs. non blocking i/o (performance)

    Andre Kelmanson, Oct 10, 2003, in forum: C Programming
    Replies:
    3
    Views:
    917
    Valentin Tihomirov
    Oct 12, 2003
  3. nukleus
    Replies:
    14
    Views:
    817
    Chris Uppal
    Jan 22, 2007
  4. Christian
    Replies:
    5
    Views:
    723
    Esmond Pitt
    Dec 2, 2007
  5. Leo Violette
    Replies:
    0
    Views:
    1,004
    Leo Violette
    Apr 17, 2009
Loading...

Share This Page