├── .ruby-version ├── ssl ├── server │ └── README.md ├── client │ └── README.md └── testca │ └── openssl.cnf ├── .gitignore ├── Berksfile ├── example └── php │ ├── celery.php │ ├── lib │ └── Connection │ │ ├── CeleryFactory.php │ │ ├── RabbitFactory.php │ │ └── BaseFactory.php │ ├── rabbit_producer.php │ └── rabbit_consumer.php ├── metadata.rb ├── composer.json ├── vagrant_boxes ├── haproxy.json ├── celery.json └── rabbitmq.json ├── Berksfile.lock ├── generateCerts.sh ├── Vagrantfile ├── composer.lock ├── README.md └── LICENSE /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.0.0-p481 2 | -------------------------------------------------------------------------------- /ssl/server/README.md: -------------------------------------------------------------------------------- 1 | Server certs are generated here. The rabbitmq vagrant servers automatically use these to enable SSL on AMQP port 5671. -------------------------------------------------------------------------------- /ssl/client/README.md: -------------------------------------------------------------------------------- 1 | Clients certs are generated here. These certs and keys will need to be used by any clients that connect to the rabbitmq 2 | cluster on port 5671. Check out the example folder to see some working clients. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | .buildpath 3 | .project 4 | .idea/ 5 | celery/*.pyc 6 | celery/config.json 7 | ssl/client/*.pem 8 | ssl/client/*.p12 9 | ssl/server/*.pem 10 | ssl/server/*.p12 11 | ssl/testca/*.pem 12 | ssl/testca/*.cer 13 | ssl/testca/serial* 14 | ssl/testca/index* 15 | ssl/testca/certs/* 16 | ssl/testca/private/* 17 | vendor/ 18 | berks_cookbooks/ 19 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | # vi: set ft=ruby : 2 | source 'https://api.berkshelf.com' 3 | 4 | metadata 5 | 6 | cookbook 'apt' 7 | cookbook 'build-essential' 8 | cookbook 'celery', git: 'https://github.com/turbine-web/celery-cookbook.git' 9 | cookbook 'cpu' 10 | cookbook 'erlang' 11 | cookbook 'haproxy' 12 | cookbook 'python' 13 | cookbook 'rabbitmq' 14 | cookbook 'supervisor', git: 'https://github.com/poise/supervisor.git', branch: 'master' 15 | cookbook 'yum' 16 | cookbook 'yum-epel' 17 | cookbook 'yum-erlang_solutions' 18 | -------------------------------------------------------------------------------- /example/php/celery.php: -------------------------------------------------------------------------------- 1 | getInstance(); 9 | 10 | echo "Sending Celery Task to Add 2 + 2 \n"; 11 | $ret = $c->PostTask('tasks.add', array(2, 2)); 12 | 13 | $ret->get(60); // wait for result - this is optional. 14 | if ($ret->isSuccess()) { 15 | echo $ret->getResult(); 16 | } else { 17 | echo "ERROR\n"; 18 | echo $ret->getTraceback(); 19 | } 20 | echo "\n"; -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'rabbitmq-cluster' 2 | maintainer 'Kyle Boorky' 3 | maintainer_email 'kboorky@turbine.com' 4 | license 'Apache 2.0' 5 | description 'Vagrant cluster of RabbitMQ and Celery servers' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '1.0.0' 8 | 9 | supports 'ubuntu' 10 | 11 | depends 'apt' 12 | depends 'build-essential' 13 | depends 'cpu' 14 | depends 'erlang' 15 | depends 'haproxy' 16 | depends 'python' 17 | depends 'celery' 18 | depends 'rabbitmq' 19 | depends 'supervisor' 20 | depends 'yum' 21 | depends 'yum-epel' 22 | depends 'yum-erlang_solutions' -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "turbine-web/rabbitmq-cluster", 3 | "description": "Vagrant cluster of RabbitMQ and Celery servers", 4 | "type": "module", 5 | "keywords": [ 6 | "celery", 7 | "rabbitmq", 8 | "haproxy" 9 | ], 10 | "homepage": "https://github.com/turbine-web/rabbitmq-cluster", 11 | "require": { 12 | "php": ">=5.4", 13 | "massivescale/celery-php": "@dev" 14 | }, 15 | "repositories": [ 16 | { 17 | "type": "git", 18 | "url": "git@github.com:divideandconquer/celery-php.git" 19 | } 20 | ], 21 | "autoload": { 22 | "psr-4": { 23 | "PhpExample\\": "example/php/lib/" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vagrant_boxes/haproxy.json: -------------------------------------------------------------------------------- 1 | { 2 | "box": "ubuntu1204-chef1144", 3 | "boxurl": "http://opscode-vm-bento.s3.amazonaws.com/vagrant/vmware/opscode_ubuntu-12.04_chef-provisionerless.box", 4 | "recipes": [ 5 | "haproxy" 6 | ], 7 | "json": { 8 | "haproxy": { 9 | "mode": "tcp", 10 | "enable_default_http": false, 11 | "install_method": "source", 12 | "listeners": { 13 | "listen": { 14 | "rabbitcluster 0.0.0.0:5671": [ 15 | "mode tcp", 16 | "balance roundrobin", 17 | "option tcplog" 18 | ], 19 | "stats :9090": [ 20 | "balance", 21 | "mode http", 22 | "stats enable", 23 | "stats auth admin:admin" 24 | ] 25 | } 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /vagrant_boxes/celery.json: -------------------------------------------------------------------------------- 1 | { 2 | "box": "ubuntu1204-chef1144", 3 | "boxurl": "http://opscode-vm-bento.s3.amazonaws.com/vagrant/vmware/opscode_ubuntu-12.04_chef-provisionerless.box", 4 | "recipes": [ 5 | "apt", 6 | "python", 7 | "supervisor", 8 | "celery" 9 | ], 10 | "json": { 11 | "celery": { 12 | "autostart": true, 13 | "directory": "/var/celery", 14 | "app": "tasks", 15 | "workdir": "/var/celery", 16 | "include": "celery.task.http", 17 | "user": "vagrant", 18 | "group": "vagrant", 19 | "config": { 20 | "rabbit_user": "admin", 21 | "rabbit_pass": "admin", 22 | "rabbit_host": "proxy", 23 | "rabbit_port": 5671, 24 | "ca_certs": "/vagrant/ssl/testca/cacert.pem", 25 | "keyfile": "/vagrant/ssl/client/key.pem", 26 | "certfile": "/vagrant/ssl/client/cert.pem" 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /example/php/lib/Connection/CeleryFactory.php: -------------------------------------------------------------------------------- 1 | __DIR__ . '/../../../../ssl/testca/cacert.pem', 19 | 'verify_peer' => true, 20 | 'local_cert' => __DIR__ . '/../../../../ssl/client/certkey.pem', 21 | 'CN_match' => $this->getParameter(static::PARAMETER_SSL_COMMON_NAME) 22 | ); 23 | 24 | //create connections 25 | $c = new Celery($this->getParameter(static::PARAMETER_HOST), $this->getParameter(static::PARAMETER_USER), $this->getParameter(static::PARAMETER_PASSWORD), '/', 'celery', 'celery', 5671, false, false, $ssl_options); 26 | return $c; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /example/php/rabbit_producer.php: -------------------------------------------------------------------------------- 1 | getInstance(); 18 | $channel = $connection->channel(); 19 | $channel->exchange_declare('hello', 'fanout', false, false, false); 20 | 21 | echo "Connection re-established. \n"; 22 | } 23 | $msg = new AMQPMessage('hello - ' . $count); 24 | $channel->basic_publish($msg, 'hello'); 25 | echo "Sending message: hello - $count \n"; 26 | $count++; 27 | } catch (\Exception $e) { 28 | echo "Connection lost. Re-establishing connection...\n"; 29 | $channel = false; 30 | } 31 | sleep(1); 32 | } 33 | $channel->close(); 34 | $connection->close(); 35 | -------------------------------------------------------------------------------- /example/php/lib/Connection/RabbitFactory.php: -------------------------------------------------------------------------------- 1 | __DIR__ . '/../../../../ssl/testca/cacert.pem', 20 | 'verify_peer' => true, 21 | 'local_cert' => __DIR__ . '/../../../../ssl/client/certkey.pem', 22 | 'CN_match' => $this->getParameter(static::PARAMETER_SSL_COMMON_NAME) 23 | ); 24 | 25 | //create connections 26 | $connection = new AMQPSSLConnection($this->getParameter(static::PARAMETER_HOST), 5671, $this->getParameter(static::PARAMETER_USER), $this->getParameter(static::PARAMETER_PASSWORD), "/", $ssl_options); 27 | 28 | return $connection; 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /ssl/testca/openssl.cnf: -------------------------------------------------------------------------------- 1 | [ ca ] 2 | default_ca = testca 3 | 4 | [ testca ] 5 | dir = . 6 | certificate = $dir/cacert.pem 7 | database = $dir/index.txt 8 | new_certs_dir = $dir/certs 9 | private_key = $dir/private/cakey.pem 10 | serial = $dir/serial 11 | 12 | default_crl_days = 7 13 | default_days = 365 14 | default_md = sha1 15 | 16 | policy = testca_policy 17 | x509_extensions = certificate_extensions 18 | 19 | [ testca_policy ] 20 | commonName = supplied 21 | stateOrProvinceName = optional 22 | countryName = optional 23 | emailAddress = optional 24 | organizationName = optional 25 | organizationalUnitName = optional 26 | 27 | [ certificate_extensions ] 28 | basicConstraints = CA:false 29 | 30 | [ req ] 31 | default_bits = 2048 32 | default_keyfile = ./private/cakey.pem 33 | default_md = sha1 34 | prompt = yes 35 | distinguished_name = root_ca_distinguished_name 36 | x509_extensions = root_ca_extensions 37 | 38 | [ root_ca_distinguished_name ] 39 | commonName = hostname 40 | 41 | [ root_ca_extensions ] 42 | basicConstraints = CA:true 43 | keyUsage = keyCertSign, cRLSign 44 | 45 | [ client_ca_extensions ] 46 | basicConstraints = CA:false 47 | keyUsage = digitalSignature 48 | extendedKeyUsage = 1.3.6.1.5.5.7.3.2 49 | 50 | [ server_ca_extensions ] 51 | basicConstraints = CA:false 52 | keyUsage = keyEncipherment 53 | extendedKeyUsage = 1.3.6.1.5.5.7.3.1 54 | -------------------------------------------------------------------------------- /example/php/rabbit_consumer.php: -------------------------------------------------------------------------------- 1 | callbacks)) { 12 | $channel->wait(); 13 | } 14 | } 15 | 16 | echo "Starting consumer. Make sure a producer is running so I have messages to read!\n"; 17 | $channel = false; 18 | while (true) { 19 | try { 20 | if ($channel === false) { 21 | //connect/reconnect to the 'hello' channel 22 | $connection = $rabbit->getInstance(); 23 | 24 | //get the default queue in the 'hello' channel 25 | $channel = $connection->channel(); 26 | $channel->exchange_declare('hello', 'fanout', false, false, false); 27 | $queue_name = $channel->queue_declare("", false, false, true, false); 28 | $queue_name = array_shift($queue_name); 29 | $channel->queue_bind($queue_name, 'hello'); 30 | 31 | //setup callback to handle messages 32 | $callback = function ($msg) { 33 | echo " Received Message: $msg->body\n"; 34 | }; 35 | $channel->basic_consume($queue_name, '', false, true, false, false, $callback); 36 | } 37 | //listen for messages 38 | handleMsg($channel); 39 | } catch (\Exception $e) { 40 | echo "Connection lost. Reconnecting...\n"; 41 | echo $e->getMessage() . "\n"; 42 | $channel = false; 43 | sleep(1); 44 | } 45 | } 46 | $channel->close(); 47 | $connection->close(); 48 | -------------------------------------------------------------------------------- /Berksfile.lock: -------------------------------------------------------------------------------- 1 | DEPENDENCIES 2 | apt 3 | build-essential 4 | celery 5 | git: https://github.com/turbine-web/celery-cookbook.git 6 | revision: 5455aedc6331802d47635f0ff8372c6468da428d 7 | cpu 8 | erlang 9 | haproxy 10 | python 11 | rabbitmq 12 | rabbitmq-cluster 13 | path: . 14 | metadata: true 15 | supervisor 16 | git: https://github.com/poise/supervisor.git 17 | revision: e5ad4bf21c2aa4dc56e7bad84b836d897a87dedf 18 | branch: master 19 | yum 20 | yum-epel 21 | yum-erlang_solutions 22 | 23 | GRAPH 24 | apt (2.4.0) 25 | build-essential (2.0.4) 26 | celery (1.0.0) 27 | python (>= 0.0.0) 28 | supervisor (>= 0.0.0) 29 | cpu (0.2.0) 30 | erlang (1.5.6) 31 | apt (>= 1.7.0) 32 | build-essential (>= 0.0.0) 33 | yum (~> 3.0) 34 | yum-epel (>= 0.0.0) 35 | yum-erlang_solutions (>= 0.0.0) 36 | haproxy (1.6.4) 37 | build-essential (>= 0.0.0) 38 | cpu (>= 0.2.0) 39 | python (1.4.6) 40 | build-essential (>= 0.0.0) 41 | yum-epel (>= 0.0.0) 42 | rabbitmq (3.2.2) 43 | erlang (>= 0.9.0) 44 | rabbitmq-cluster (1.0.0) 45 | apt (>= 0.0.0) 46 | build-essential (>= 0.0.0) 47 | celery (>= 0.0.0) 48 | cpu (>= 0.0.0) 49 | erlang (>= 0.0.0) 50 | haproxy (>= 0.0.0) 51 | python (>= 0.0.0) 52 | rabbitmq (>= 0.0.0) 53 | supervisor (>= 0.0.0) 54 | yum (>= 0.0.0) 55 | yum-epel (>= 0.0.0) 56 | yum-erlang_solutions (>= 0.0.0) 57 | supervisor (0.4.11) 58 | python (>= 0.0.0) 59 | yum (3.2.2) 60 | yum-epel (0.4.0) 61 | yum (~> 3.0) 62 | yum-erlang_solutions (0.2.0) 63 | yum (~> 3.0) 64 | -------------------------------------------------------------------------------- /generateCerts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | read -p "Enter an SSL Common Name [rabbit]: " CN 4 | read -s -p "Enter an SSL Passphrase: " PP 5 | 6 | #default CN to rabbit 7 | commonName="rabbit" 8 | if [[ -z "$CN" ]]; then 9 | CN=$commonName 10 | fi 11 | 12 | #clean up old certs 13 | find ssl/* -name "*.pem" -type f -delete 14 | find ssl/* -name "*.p12" -type f -delete 15 | rm -f ssl/testca/index.txt* 16 | rm -f ssl/testca/serial* 17 | rm -f ssl/testca/cacert.cer 18 | rm -rf ssl/testca/certs 19 | rm -rf ssl/testca/private 20 | 21 | cd ssl/testca 22 | mkdir certs private 23 | chmod 700 private 24 | touch index.txt 25 | echo 01 > serial 26 | 27 | openssl req -x509 -config openssl.cnf -newkey rsa:2048 -days 365 -out cacert.pem -outform PEM -subj /CN=$CN/ -nodes 28 | openssl x509 -in cacert.pem -out cacert.cer -outform DER 29 | 30 | cd ../server 31 | openssl genrsa -out key.pem 2048 32 | openssl req -new -key key.pem -out req.pem -outform PEM -subj /CN=$CN/O=server/ -nodes 33 | 34 | cd ../testca 35 | openssl ca -config openssl.cnf -in ../server/req.pem -out ../server/cert.pem -notext -batch -extensions server_ca_extensions 36 | 37 | cd ../server 38 | openssl pkcs12 -export -out keycert.p12 -in cert.pem -inkey key.pem -passout pass:$PP 39 | cat cert.pem key.pem > certkey.pem 40 | 41 | cd ../client 42 | openssl genrsa -out key.pem 2048 43 | openssl req -new -key key.pem -out req.pem -outform PEM -subj /CN=$CN/O=client/ -nodes 44 | 45 | cd ../testca 46 | openssl ca -config openssl.cnf -in ../client/req.pem -out ../client/cert.pem -notext -batch -extensions client_ca_extensions 47 | 48 | cd ../client 49 | openssl pkcs12 -export -out keycert.p12 -in cert.pem -inkey key.pem -passout pass:$PP 50 | cat cert.pem key.pem > certkey.pem -------------------------------------------------------------------------------- /vagrant_boxes/rabbitmq.json: -------------------------------------------------------------------------------- 1 | { 2 | "box": "ubuntu1204-chef1144", 3 | "boxurl": "http://opscode-vm-bento.s3.amazonaws.com/vagrant/vmware/opscode_ubuntu-12.04_chef-provisionerless.box", 4 | "recipes": [ 5 | "rabbitmq", 6 | "rabbitmq::mgmt_console", 7 | "rabbitmq::plugin_management", 8 | "rabbitmq::policy_management", 9 | "rabbitmq::user_management" 10 | ], 11 | "json": { 12 | "rabbitmq": { 13 | "cluster": true, 14 | "cluster_disk_nodes": [], 15 | "ssl": true, 16 | "ssl_port": 5671, 17 | "ssl_cacert": "/vagrant/ssl/testca/cacert.pem", 18 | "ssl_cert": "/vagrant/ssl/server/cert.pem", 19 | "ssl_key": "/vagrant/ssl/server/key.pem", 20 | "ssl_verify": "verify_peer", 21 | "ssl_fail_if_no_peer_cert": true, 22 | "erlang_cookie": "lbhjfgjlhfdvlkdfnvidsfbvlkplkmihfbsdctgfghjjfcvbjuytresasdfghjk", 23 | "policies": { 24 | "mirror": { 25 | "pattern": ".*", 26 | "params": { 27 | "ha-mode": "all" 28 | }, 29 | "priority": 100 30 | } 31 | }, 32 | "disabled_policies": [ 33 | "ha-all", 34 | "ha-two" 35 | ], 36 | "enabled_plugins": [ 37 | "rabbitmq_federation", 38 | "rabbitmq_federation_management" 39 | ], 40 | "disabled_users": [ 41 | "guest" 42 | ], 43 | "enabled_users": [ 44 | { 45 | "name": "admin", 46 | "password": "admin", 47 | "tag": "administrator", 48 | "rights": [ 49 | { 50 | "vhost": null, 51 | "conf": ".*", 52 | "write": ".*", 53 | "read": ".*" 54 | } 55 | ] 56 | } 57 | ] 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /example/php/lib/Connection/BaseFactory.php: -------------------------------------------------------------------------------- 1 | params[static::PARAMETER_HOST] = static::DEFAULT_HOST; 34 | $this->params[static::PARAMETER_USER] = static::DEFAULT_USER; 35 | $this->params[static::PARAMETER_PASSWORD] = static::DEFAULT_PASSWORD; 36 | $this->params[static::PARAMETER_SSL_COMMON_NAME] = static::DEFAULT_SSL_COMMON_NAME; 37 | 38 | //pull in arguments 39 | $short_opts = static::PARAMETER_HOST . ':' . static::PARAMETER_USER . ':' . static::PARAMETER_PASSWORD . ':'; 40 | $long_opts = array(); 41 | $long_opts[] = static::PARAMETER_SSL_COMMON_NAME . ':'; 42 | $long_opts[] = 'help'; 43 | $options = getopt($short_opts, $long_opts); 44 | 45 | //override defaults 46 | $this->params = array_merge($this->params, $options); 47 | 48 | if (isset($this->params['help'])) { 49 | echo "\n----------------- USAGE --------------\nphp " . $argv[0] . " [-h ] [-u ] [-p ] [--ssl-common-name ]\n\n"; 50 | exit; 51 | } 52 | } 53 | 54 | /** 55 | * Returns the parameters passed in as CLI arguments or their defaults 56 | * @param $key 57 | * @return mixed 58 | */ 59 | public function getParameter($key) 60 | { 61 | return isset($this->params[$key]) ? $this->params[$key] : null; 62 | } 63 | 64 | /** 65 | * Retrieves a connection 66 | * @return mixed 67 | */ 68 | abstract public function getInstance(); 69 | 70 | } -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | # read json box configs 7 | proxy = JSON.parse( IO.read('vagrant_boxes/haproxy.json') ) 8 | rabbit = JSON.parse( IO.read('vagrant_boxes/rabbitmq.json') ) 9 | celery = JSON.parse( IO.read('vagrant_boxes/celery.json') ) 10 | 11 | # define servers 12 | servers = [ 13 | { :hostname => 'rabbit0', :type => 'rabbit', :primary => false}, 14 | { :hostname => 'rabbit1', :type => 'rabbit', :primary => false}, 15 | { :hostname => 'rabbit2', :type => 'rabbit', :primary => false}, 16 | { :hostname => 'celery0', :type => 'celery', :primary => false}, 17 | { :hostname => 'proxy', :type => 'proxy', :primary => false} 18 | ] 19 | 20 | # cookbook path 21 | cookbooks_path = 'berks_cookbooks' 22 | 23 | # update rabbit cluster disk nodes and proxy 24 | rabbit['json']['rabbitmq']['cluster_disk_nodes'] = [] 25 | counter = 0 26 | servers.each do |server| 27 | if server[:type] == 'rabbit' 28 | # dynamically add the rabbit servers to the cluster configuration 29 | rabbit['json']['rabbitmq']['cluster_disk_nodes'].push("rabbit@"+server[:hostname]) 30 | 31 | # dynamically add rabbit servers to the haproxy config 32 | conf = "server " + server[:hostname] + " " + server[:hostname] + ":5671 check inter 5000" 33 | 34 | # is this the main server or a backup? (change this if you prefer round robin etc..) 35 | if counter == 0 36 | conf = conf + " downinter 500" 37 | else 38 | conf = conf + " backup" 39 | end 40 | 41 | proxy['json']['haproxy']['listeners']['listen']['rabbitcluster 0.0.0.0:5671'].push(conf) 42 | counter = counter + 1 43 | end 44 | end 45 | 46 | boxes = { 47 | 'rabbit' => rabbit, 48 | 'proxy' => proxy, 49 | 'celery' => celery 50 | } 51 | 52 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 53 | 54 | # Setup hostmanager config to update the host files 55 | config.hostmanager.enabled = true 56 | config.hostmanager.manage_host = true 57 | config.hostmanager.ignore_private_ip = false 58 | config.hostmanager.include_offline = true 59 | config.vm.provision :hostmanager 60 | 61 | # Forward our SSH Keys into the VM 62 | config.ssh.forward_agent = true 63 | 64 | 65 | # Loop through all servers and configure them 66 | servers.each do |server| 67 | config.vm.define server[:hostname], primary: server[:primary] do |node_config| 68 | node_config.vm.box = boxes[server[:type]]['box'] 69 | node_config.vm.box_url = boxes[server[:type]]['boxurl'] 70 | node_config.vm.hostname = server[:hostname] 71 | node_config.vm.network :private_network, :auto_network => true 72 | node_config.hostmanager.aliases = server[:hostname] 73 | 74 | node_config.vm.provision :chef_solo do |chef| 75 | chef.json = boxes[server[:type]]['json'] 76 | chef.cookbooks_path = [cookbooks_path] 77 | 78 | boxes[server[:type]]['recipes'].each do |recipe| 79 | chef.add_recipe recipe 80 | end 81 | end 82 | end 83 | end 84 | 85 | # vagrant trigger to get cookbooks and install them in 86 | # cookbook path 87 | [:up, :provision].each do |cmd| 88 | config.trigger.before cmd, :stdout => true do 89 | info 'Cleaning cookbook directory' 90 | run "rm -rf #{cookbooks_path}" 91 | info 'Installing cookbook dependencies with berkshelf' 92 | run "berks vendor #{cookbooks_path}" 93 | end 94 | end 95 | end 96 | 97 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "10d20f887c3aaa6e00b508b32956d18c", 8 | "packages": [ 9 | { 10 | "name": "massivescale/celery-php", 11 | "version": "dev-master", 12 | "source": { 13 | "type": "git", 14 | "url": "git@github.com:divideandconquer/celery-php.git", 15 | "reference": "6ceeadfcdda21ceeebd1725b92c9f92ac3b03d59" 16 | }, 17 | "require": { 18 | "videlalvaro/php-amqplib": ">=2.0.0" 19 | }, 20 | "type": "library", 21 | "autoload": { 22 | "classmap": [ 23 | "celery.php" 24 | ] 25 | }, 26 | "license": [ 27 | "BSD-2-Clause" 28 | ], 29 | "authors": [ 30 | { 31 | "name": "GDR!", 32 | "email": "info@massivescale.net", 33 | "homepage": "http://massivescale.net/", 34 | "role": "Developer" 35 | } 36 | ], 37 | "description": "PHP client for Celery task queue", 38 | "homepage": "https://github.com/gjedeer/celery-php/", 39 | "keywords": [ 40 | "amqp", 41 | "celery", 42 | "cron", 43 | "python", 44 | "queue", 45 | "task" 46 | ], 47 | "time": "2014-07-16 22:06:08" 48 | }, 49 | { 50 | "name": "videlalvaro/php-amqplib", 51 | "version": "v2.4.0", 52 | "source": { 53 | "type": "git", 54 | "url": "https://github.com/videlalvaro/php-amqplib.git", 55 | "reference": "d8294736e47340e8d96f37d788b15f578bfc084f" 56 | }, 57 | "dist": { 58 | "type": "zip", 59 | "url": "https://api.github.com/repos/videlalvaro/php-amqplib/zipball/d8294736e47340e8d96f37d788b15f578bfc084f", 60 | "reference": "d8294736e47340e8d96f37d788b15f578bfc084f", 61 | "shasum": "" 62 | }, 63 | "require": { 64 | "ext-bcmath": "*", 65 | "php": ">=5.3.0" 66 | }, 67 | "require-dev": { 68 | "phpunit/phpunit": "3.7.*" 69 | }, 70 | "suggest": { 71 | "ext-sockets": "Use AMQPSocketConnection" 72 | }, 73 | "type": "library", 74 | "autoload": { 75 | "psr-0": { 76 | "PhpAmqpLib": "" 77 | } 78 | }, 79 | "notification-url": "https://packagist.org/downloads/", 80 | "license": [ 81 | "LGPL-2.1" 82 | ], 83 | "authors": [ 84 | { 85 | "name": "Alvaro Videla" 86 | } 87 | ], 88 | "description": "This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.", 89 | "homepage": "https://github.com/videlalvaro/php-amqplib/", 90 | "keywords": [ 91 | "message", 92 | "queue", 93 | "rabbitmq" 94 | ], 95 | "time": "2014-06-21 09:27:57" 96 | } 97 | ], 98 | "packages-dev": [ 99 | 100 | ], 101 | "aliases": [ 102 | 103 | ], 104 | "minimum-stability": "stable", 105 | "stability-flags": { 106 | "massivescale/celery-php": 20 107 | }, 108 | "prefer-stable": false, 109 | "platform": { 110 | "php": ">=5.4" 111 | }, 112 | "platform-dev": [ 113 | 114 | ] 115 | } 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RabbitMQ Cluster 2 | 3 | This project sets up a rabbit cluster as an example of how to use [RabbitMQ](http://www.rabbitmq.com/) with 4 | SSL, mirroring, user management, and load balanced with an HA proxy. It also includes a working 5 | example of using [Celery](http://www.celeryproject.org/). 6 | 7 | # Setup 8 | 9 | To run the example provided, you must have [Vagrant](http://www.vagrantup.com/) and [VirtualBox](https://www.virtualbox.org/) 10 | installed on your machine. 11 | 12 | ```sh 13 | git clone https://github.com/turbine-web/rabbitmq-cluster.git 14 | cd rabbit-cluster 15 | 16 | # Generate a certificate authority and server/client certs 17 | # Required for the example which is over SSL 18 | sh generateCerts.sh 19 | 20 | # Vagrant plugins to manage the network 21 | vagrant plugin install vagrant-auto_network 22 | vagrant plugin install vagrant-hostmanager 23 | vagrant plugin install vagrant-triggers 24 | 25 | vagrant up 26 | ``` 27 | 28 | # Connecting 29 | 30 | To connect to the rabbit servers connect to the `proxy` hostname as admin/admin. Connecting to rabbit 31 | requires a valid client ssl cert. Make sure that any clients you intend to connect to this cluster have 32 | a copy of the ssl/client directory available to them. Additionally each client will need a copy of the 33 | Certificate Authority cert located in ssl/testca/cacert.pem. 34 | 35 | ## Examples 36 | 37 | ### PHP 38 | 39 | PHP AMQP users should compose in the [php-amqplib](https://github.com/videlalvaro/php-amqplib) library to connect directly 40 | to RabbitMQ. Add the following to your composer file: 41 | 42 | ```javascript 43 | "require": 44 | { 45 | "videlalvaro/php-amqplib": ">=2.0.0", 46 | } 47 | ``` 48 | 49 | Celery users should compose in the [celery-php](https://github.com/divideandconquer/celery-php) library. Make sure to use 50 | the divideandconquer version until SSL support is merged into the [gjedeer](https://github.com/gjedeer/celery-php) version. 51 | 52 | ```javascript 53 | "require": 54 | { 55 | "massivescale/celery-php": "@dev" 56 | }, 57 | "repositories": [ 58 | { 59 | "type": "git", 60 | "url": "git@github.com:divideandconquer/celery-php.git" 61 | } 62 | ] 63 | ``` 64 | 65 | For more information check out the example folder. Note that these examples require you to `composer install` 66 | before they will run. 67 | 68 | ```sh 69 | # pull down dependencies 70 | composer install 71 | ``` 72 | 73 | To run the Celery example, which submits a task to add two numbers together and returns the value, run 74 | the following commands: 75 | 76 | ```sh 77 | # run the celery example with the default vagrant configuration 78 | php example/php/celery.php 79 | 80 | # run the celery example with a custom host, user, password, and ssl common name: 81 | php example/php/celery.php -h proxy -u admin -p admin --ssl-common-name 82 | ``` 83 | 84 | To see a publish / subscribe implementation, run the consumer and producer files: 85 | 86 | ```sh 87 | # run the consumer example with the default vagrant configuration 88 | php example/php/rabbit_consumer.php 89 | 90 | # run the consumer example with a custom host, user, password, and ssl common name: 91 | php example/php/rabbit_consumer.php -h proxy -u admin -p admin --ssl-common-name 92 | ``` 93 | 94 | ```sh 95 | # run the producer example with the default vagrant configuration 96 | php example/php/rabbit_producer.php 97 | 98 | # run the producer example with a custom host, user, password, and ssl common name: 99 | php example/php/rabbit_producer.php -h proxy -u admin -p admin --ssl-common-name 100 | ``` 101 | 102 | # Monitoring 103 | 104 | ## haproxy 105 | 106 | To check on the health and status of servers as haproxy sees them you can navigate to [haproxy stats](http://proxy:9090/haproxy?stats) 107 | and log in with admin/admin. 108 | 109 | ## rabbitmq 110 | 111 | To view the rabbitmq management page navigate to [rabbit0](http://rabbit0:15672/#/) and log in with admin/admin. 112 | Note that you can also connect to [rabbit1](http://rabbit1:15672/#/) and [rabbit2](http://rabbit2:15672/#/). 113 | 114 | # License 115 | 116 | Copyright:: 2014, Warner Bros. Entertainment Inc. Developed by Turbine, Inc. 117 | 118 | Licensed under the Apache License, Version 2.0 (the "License"); 119 | you may not use this file except in compliance with the License. 120 | You may obtain a copy of the License at 121 | 122 | http://www.apache.org/licenses/LICENSE-2.0 123 | 124 | Unless required by applicable law or agreed to in writing, software 125 | distributed under the License is distributed on an "AS IS" BASIS, 126 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127 | See the License for the specific language governing permissions and 128 | limitations under the License. 129 | 130 | # Contributing 131 | 132 | 1. Fork it 133 | 2. Create your feature branch (`git checkout -b my-new-feature`) 134 | 3. Commit your changes (`git commit -am 'Add some feature'`) 135 | 4. Push to the branch (`git push origin my-new-feature`) 136 | 5. Create new Pull Request 137 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 Warner Bros. Entertainment Inc. Developed by Turbine, Inc. 2 | 3 | Apache License 4 | Version 2.0, January 2004 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, 12 | and distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by 15 | the copyright owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all 18 | other entities that control, are controlled by, or are under common 19 | control with that entity. For the purposes of this definition, 20 | "control" means (i) the power, direct or indirect, to cause the 21 | direction or management of such entity, whether by contract or 22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 23 | outstanding shares, or (iii) beneficial ownership of such entity. 24 | 25 | "You" (or "Your") shall mean an individual or Legal Entity 26 | exercising permissions granted by this License. 27 | 28 | "Source" form shall mean the preferred form for making modifications, 29 | including but not limited to software source code, documentation 30 | source, and configuration files. 31 | 32 | "Object" form shall mean any form resulting from mechanical 33 | transformation or translation of a Source form, including but 34 | not limited to compiled object code, generated documentation, 35 | and conversions to other media types. 36 | 37 | "Work" shall mean the work of authorship, whether in Source or 38 | Object form, made available under the License, as indicated by a 39 | copyright notice that is included in or attached to the work 40 | (an example is provided in the Appendix below). 41 | 42 | "Derivative Works" shall mean any work, whether in Source or Object 43 | form, that is based on (or derived from) the Work and for which the 44 | editorial revisions, annotations, elaborations, or other modifications 45 | represent, as a whole, an original work of authorship. For the purposes 46 | of this License, Derivative Works shall not include works that remain 47 | separable from, or merely link (or bind by name) to the interfaces of, 48 | the Work and Derivative Works thereof. 49 | 50 | "Contribution" shall mean any work of authorship, including 51 | the original version of the Work and any modifications or additions 52 | to that Work or Derivative Works thereof, that is intentionally 53 | submitted to Licensor for inclusion in the Work by the copyright owner 54 | or by an individual or Legal Entity authorized to submit on behalf of 55 | the copyright owner. For the purposes of this definition, "submitted" 56 | means any form of electronic, verbal, or written communication sent 57 | to the Licensor or its representatives, including but not limited to 58 | communication on electronic mailing lists, source code control systems, 59 | and issue tracking systems that are managed by, or on behalf of, the 60 | Licensor for the purpose of discussing and improving the Work, but 61 | excluding communication that is conspicuously marked or otherwise 62 | designated in writing by the copyright owner as "Not a Contribution." 63 | 64 | "Contributor" shall mean Licensor and any individual or Legal Entity 65 | on behalf of whom a Contribution has been received by Licensor and 66 | subsequently incorporated within the Work. 67 | 68 | 2. Grant of Copyright License. Subject to the terms and conditions of 69 | this License, each Contributor hereby grants to You a perpetual, 70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 71 | copyright license to reproduce, prepare Derivative Works of, 72 | publicly display, publicly perform, sublicense, and distribute the 73 | Work and such Derivative Works in Source or Object form. 74 | 75 | 3. Grant of Patent License. Subject to the terms and conditions of 76 | this License, each Contributor hereby grants to You a perpetual, 77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 78 | (except as stated in this section) patent license to make, have made, 79 | use, offer to sell, sell, import, and otherwise transfer the Work, 80 | where such license applies only to those patent claims licensable 81 | by such Contributor that are necessarily infringed by their 82 | Contribution(s) alone or by combination of their Contribution(s) 83 | with the Work to which such Contribution(s) was submitted. If You 84 | institute patent litigation against any entity (including a 85 | cross-claim or counterclaim in a lawsuit) alleging that the Work 86 | or a Contribution incorporated within the Work constitutes direct 87 | or contributory patent infringement, then any patent licenses 88 | granted to You under this License for that Work shall terminate 89 | as of the date such litigation is filed. 90 | 91 | 4. Redistribution. You may reproduce and distribute copies of the 92 | Work or Derivative Works thereof in any medium, with or without 93 | modifications, and in Source or Object form, provided that You 94 | meet the following conditions: 95 | 96 | (a) You must give any other recipients of the Work or 97 | Derivative Works a copy of this License; and 98 | 99 | (b) You must cause any modified files to carry prominent notices 100 | stating that You changed the files; and 101 | 102 | (c) You must retain, in the Source form of any Derivative Works 103 | that You distribute, all copyright, patent, trademark, and 104 | attribution notices from the Source form of the Work, 105 | excluding those notices that do not pertain to any part of 106 | the Derivative Works; and 107 | 108 | (d) If the Work includes a "NOTICE" text file as part of its 109 | distribution, then any Derivative Works that You distribute must 110 | include a readable copy of the attribution notices contained 111 | within such NOTICE file, excluding those notices that do not 112 | pertain to any part of the Derivative Works, in at least one 113 | of the following places: within a NOTICE text file distributed 114 | as part of the Derivative Works; within the Source form or 115 | documentation, if provided along with the Derivative Works; or, 116 | within a display generated by the Derivative Works, if and 117 | wherever such third-party notices normally appear. The contents 118 | of the NOTICE file are for informational purposes only and 119 | do not modify the License. You may add Your own attribution 120 | notices within Derivative Works that You distribute, alongside 121 | or as an addendum to the NOTICE text from the Work, provided 122 | that such additional attribution notices cannot be construed 123 | as modifying the License. 124 | 125 | You may add Your own copyright statement to Your modifications and 126 | may provide additional or different license terms and conditions 127 | for use, reproduction, or distribution of Your modifications, or 128 | for any such Derivative Works as a whole, provided Your use, 129 | reproduction, and distribution of the Work otherwise complies with 130 | the conditions stated in this License. 131 | 132 | 5. Submission of Contributions. Unless You explicitly state otherwise, 133 | any Contribution intentionally submitted for inclusion in the Work 134 | by You to the Licensor shall be under the terms and conditions of 135 | this License, without any additional terms or conditions. 136 | Notwithstanding the above, nothing herein shall supersede or modify 137 | the terms of any separate license agreement you may have executed 138 | with Licensor regarding such Contributions. 139 | 140 | 6. Trademarks. This License does not grant permission to use the trade 141 | names, trademarks, service marks, or product names of the Licensor, 142 | except as required for reasonable and customary use in describing the 143 | origin of the Work and reproducing the content of the NOTICE file. 144 | 145 | 7. Disclaimer of Warranty. Unless required by applicable law or 146 | agreed to in writing, Licensor provides the Work (and each 147 | Contributor provides its Contributions) on an "AS IS" BASIS, 148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 149 | implied, including, without limitation, any warranties or conditions 150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 151 | PARTICULAR PURPOSE. You are solely responsible for determining the 152 | appropriateness of using or redistributing the Work and assume any 153 | risks associated with Your exercise of permissions under this License. 154 | 155 | 8. Limitation of Liability. In no event and under no legal theory, 156 | whether in tort (including negligence), contract, or otherwise, 157 | unless required by applicable law (such as deliberate and grossly 158 | negligent acts) or agreed to in writing, shall any Contributor be 159 | liable to You for damages, including any direct, indirect, special, 160 | incidental, or consequential damages of any character arising as a 161 | result of this License or out of the use or inability to use the 162 | Work (including but not limited to damages for loss of goodwill, 163 | work stoppage, computer failure or malfunction, or any and all 164 | other commercial damages or losses), even if such Contributor 165 | has been advised of the possibility of such damages. 166 | 167 | 9. Accepting Warranty or Additional Liability. While redistributing 168 | the Work or Derivative Works thereof, You may choose to offer, 169 | and charge a fee for, acceptance of support, warranty, indemnity, 170 | or other liability obligations and/or rights consistent with this 171 | License. However, in accepting such obligations, You may act only 172 | on Your own behalf and on Your sole responsibility, not on behalf 173 | of any other Contributor, and only if You agree to indemnify, 174 | defend, and hold each Contributor harmless for any liability 175 | incurred by, or claims asserted against, such Contributor by reason 176 | of your accepting any such warranty or additional liability. 177 | 178 | END OF TERMS AND CONDITIONS 179 | 180 | APPENDIX: How to apply the Apache License to your work. 181 | 182 | To apply the Apache License to your work, attach the following 183 | boilerplate notice, with the fields enclosed by brackets "[]" 184 | replaced with your own identifying information. (Don't include 185 | the brackets!) The text should be enclosed in the appropriate 186 | comment syntax for the file format. We also recommend that a 187 | file or class name and description of purpose be included on the 188 | same "printed page" as the copyright notice for easier 189 | identification within third-party archives. 190 | 191 | Copyright [yyyy] [name of copyright owner] 192 | 193 | Licensed under the Apache License, Version 2.0 (the "License"); 194 | you may not use this file except in compliance with the License. 195 | You may obtain a copy of the License at 196 | 197 | http://www.apache.org/licenses/LICENSE-2.0 198 | 199 | Unless required by applicable law or agreed to in writing, software 200 | distributed under the License is distributed on an "AS IS" BASIS, 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | See the License for the specific language governing permissions and 203 | limitations under the License. --------------------------------------------------------------------------------