Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please include a fully working example #5

Open
edescourtis opened this issue Sep 18, 2014 · 3 comments
Open

Please include a fully working example #5

edescourtis opened this issue Sep 18, 2014 · 3 comments

Comments

@edescourtis
Copy link

Would it be possible to include a complete example(s) as source?

@jlouis
Copy link
Owner

jlouis commented Sep 19, 2014

Yes it would. Do you have a small example in mind which is rather self-contained and still useful? I was thinking about something where you had a database connection, but it easily ends up being large and contrived for an example.

So I am all for it, but I do think we should figure out what a good example would comprise.

@ferd
Copy link

ferd commented Sep 19, 2014

@jlouis use a simple thing like a dumb web server:

$ while true ; do  echo -e "HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length: ${#$(date)}\r\n\r\n$(date)" | nc -l -p 8081 ; done

(I use that to test dumb proxying/load-balancing modes here).

Put HTTP calls to localhost:8081 behind a fuse, and have fun taking the server up and down by killing the process. The fuse should tell you when it's entirely down to stop connecting.

For the fun of it, boot a second server on 8082, and have them output their name or something. Consider this to be switching from 'primary to replica' or from 'geographically close to in another datacenter" as a failover. Trigger the switch on failure, or by putting sleep time in the first server to simulate overload (and long time to respond).

@joaothallis
Copy link

joaothallis commented Nov 20, 2024

Thank you @ferd for the example, I tried to run here and an error happened:

bash-5.2$  while true ; do  echo -e "HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length: ${#$(date)}\r\n\r\n$(date)" | nc -l -p 8081 ; done
bash: HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length: ${#$(date)}\r\n\r\n$(date): bad substitution
nc: missing port with option -l
usage: nc [-46AacCDdEFhklMnOortUuvz] [-K tc] [-b boundif] [-i interval] [-p source_port]
          [--apple-recv-anyif] [--apple-awdl-unres]
          [--apple-boundif ifbound]
          [--apple-no-cellular] [--apple-no-expensive]
          [--apple-no-flowadv] [--apple-tcp-timeout conntimo]
          [--apple-tcp-keepalive keepidle] [--apple-tcp-keepintvl keepintvl]
          [--apple-tcp-keepcnt keepcnt] [--apple-tclass tclass]
          [--tcp-adp-rtimo num_probes] [--apple-intcoproc-allow]
          [--apple-tcp-adp-wtimo num_probes]
          [--setsockopt-later] [--apple-no-connectx]
          [--apple-delegate-pid pid] [--apple-delegate-uuid uuid]
          [--apple-kao] [--apple-ext-bk-idle]
          [--apple-netsvctype svc] [---apple-nowakefromsleep]
          [--apple-notify-ack] [--apple-sockev]
          [--apple-tos tos] [--apple-tos-cmsg]
          [-s source_ip_address] [-w timeout] [-X proxy_version]
          [-x proxy_address[:port]] [hostname] [port[s]]

I am able to run with this example:

while true ; do echo -e "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: $(date | wc -c)\r\n\r\n$(date)" | nc -l 8081 ; done

nc -l -p: Modern versions of nc (netcat) may not support the -p option with -l for specifying the port. You can simply pass the port number after -l.

@edescourtis I created this example using Tesla.Middleware.Fuse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants