22
RACK-AMQP A NEW RUBY WEBAPP SERVER

RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

RACK-AMQPA NEW RUBY WEBAPP SERVER

Page 2: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

WhatRack-AMQP is:

jackalope (rack app server)

amqurl (client with curl syntax)

rack-amqp-client (ruby client lib)

AMQParty (ruby client lib, API-compatible with HTTParty)

Demo

Page 3: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

WhatRack-AMQP is:

jackalope (rack app server)

amqurl (client with curl syntax)

rack-amqp-client (ruby client lib)

AMQParty (ruby client lib, API-compatible with HTTParty)

Demo

Page 4: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

WHY

Page 5: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

SOAMany services communicating with each other

Need direct fetch capabilities (GET, POST), also publish-subscribe

HTTP doesn't do pub/sub

We have all this HTTP infrastructure and code already!

We know HTTP

Page 6: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

HTTP in your SOA

seems simple, but it's actually complex

Load Balancers

SSL Everywhere

Fixed IPs or hostnames or service locators

Connection setup / teardown

Page 7: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

AMQPOpen standard

Allows any system to connect (Ruby, Java, Haskell, whatever)

Secure by default

Everything is a queue

No load balancing

No fixed locations, just queue names

Persistent connection

Page 8: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

HOW

Page 9: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

Implements AMQP

Robust messaging for applications

Easy to use

Runs on all major operating systems

Supports a huge number of developer platforms

Open source and commercially supported

Page 10: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

AMQP Topologies

Page 11: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to
Page 12: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

Simple-enough config

{ssl_options, [{cacertfile, "/path/to/testca/cacert.pem"}, {certfile, "/path/to/server/cert.pem"}, {keyfile, "/path/to/server/key.pem"}, {verify, verify_peer}, {fail_if_no_peer_cert, false}]},

{default_vhost, <<"/">>}, {default_user, <<"guest">>}, {default_pass, <<"guest">>}, {default_permissions, [<<".*">>, <<".*">>, <<".*">>]},

Page 13: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

Simple-enough config

{ssl_options, [{cacertfile, "/path/to/testca/cacert.pem"}, {certfile, "/path/to/server/cert.pem"}, {keyfile, "/path/to/server/key.pem"}, {verify, verify_peer}, {fail_if_no_peer_cert, false}]},

{default_vhost, <<"/">>}, {default_user, <<"guest">>}, {default_pass, <<"guest">>}, {default_permissions, [<<".*">>, <<".*">>, <<".*">>]},

Page 14: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

SERVER

Page 15: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

The common language for ruby web applications

1 class HelloWorld!2 def call(env)!3 [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]!4 end!5 end

Page 16: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

The common language for ruby web applications

1 class HelloWorld!2 def call(env)!3 [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]!4 end!5 end

Response Code Headers Body

Page 17: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

Rack-AMQP

#!/usr/bin/env ruby!

require "rack/amqp"!

Rack::AMQP::Server.start rackup_file: File.absolute_path(ARGV[0])

rack-amqp/bin/raqup

Page 18: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

class Rack::AMQP::Server! def start! ::AMQP.start(host: 'localhost') do |client|! chan = ::AMQP::Channel.new(client)!! chan.queue("test.simple").subscribe do |metadata, payload|! response, headers = handle_request(metadata, payload)!! message_id = metadata.message_id! reply_to = metadata.reply_to!! amqp_headers = {! routing_key: reply_to, correlation_id: message_id,! type: 'REPLY', app_id: server_agent,! timestamp: Time.now.to_i, headers: headers! }! amqp_headers[:content_type] = type if type = headers['Content-Type']! amqp_headers[:content_encoding] = enc if enc = headers['Content-Encoding']!! chan.direct("").publish(response, amqp_headers)! end!! puts "#{server_agent} running"! end! end!end

AMQP

Page 19: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

class Rack::AMQP::Server! def handle_request(meta, body)! headers = meta.headers! http_method = meta.type! path = headers['path']!! parts = path.split(/\?/)! uri = parts[0]! query = parts[1] || ""!! env = default_env! env.update({! 'REQUEST_METHOD' => http_method,! 'PATH_INFO' => uri,! 'QUERY_STRING' => query,! 'REQUEST_PATH' => uri,! })!! response_code, headers, body = app.call(env)!! headers.merge!('X-AMQP-HTTP-Status' => response_code)!! body_chunks = []! body.each { |chunk| body_chunks << chunk }! body.close!! [body_chunks.join, headers]! end!end

Rack

Page 20: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

NOT FINISHED!

Page 21: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

TODO

Test in staging, test in production

Iron-out performance issues

Load test

Support more curl options for amqurl

Allow config file for jackalope

Page 22: RACK-AMQPfiles.meetup.com/1780846/rack-amqp devops.pdfSSL Everywhere Fixed IPs or hostnames or service locators Connection setup / teardown AMQP Open standard Allows any system to

Thanks!Josh Szmajda

@jszmajda

@rubyhangout

CTO, Optoro

We are hiring ;)

http://www.github.com/joshsz/rack-amqp