-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
762df6d
commit b6b7235
Showing
24 changed files
with
218 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
target/ | ||
|
||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
npm-debug.log | ||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
RabbitMQ Cloud Foundry Samples | ||
============================== | ||
|
||
This repository contains sample applications to demonstrate the use of [RabbitMQ](http://www.rabbitmq.com/) on [Cloud Foundry](http://www.cloudfoundry.com). | ||
|
||
Examples are provided for the following languages/runtimes: | ||
|
||
* [Java with Spring](spring) | ||
* [Ruby with Rails](rails) | ||
* [Ruby with Sinatra](sinatra) | ||
* [Node.js](nodejs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: node app.js |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
This is a simple Node.js application demonstrating the use of RabbitMQ on Cloud Foundry. | ||
|
||
## Deploying to Cloud Foundry ## | ||
|
||
After installing in the 'cf' [command-line interface](http://docs.cloudfoundry.com/docs/using/managing-apps/cf/) for Cloud Foundry, targeting a Cloud Foundry instance, and logging in, the application can be pushed using these commands: | ||
|
||
$ cf push | ||
|
||
The provided `manifest.yml` file will be used to provide the application parameters to Cloud Foundry. You may need to provide a different URL for the application if the `rabbitmq-node` URL is already being used in your Cloud Foundry domain. The `manifest.yml` file specifies a RabbitMQ services that is available on the [run.pivotal.io](http://docs.cloudfoundry.com/docs/dotcom/getting-started.html) Cloud Foundry services marketplace. You may need to change the details of the RabbitMQ service to push to a different Cloud Foundry instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
applications: | ||
- name: rabbitmq-node | ||
memory: 256M | ||
instances: 1 | ||
url: rabbitmq-node.${target-base} | ||
path: . | ||
services: | ||
rabbit-sample: | ||
label: cloudamqp | ||
provider: cloudamqp | ||
version: n/a | ||
plan: lemur |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
This is a very simple Rails 3 application demonstrating the use of RabbitMQ on Cloud Foundry. | ||
|
||
## Deploying to Cloud Foundry ## | ||
|
||
After installing in the 'cf' [command-line interface](http://docs.cloudfoundry.com/docs/using/managing-apps/cf/) for Cloud Foundry, targeting a Cloud Foundry instance, and logging in, the application can be pushed using these commands: | ||
|
||
$ cf push | ||
|
||
The provided `manifest.yml` file will be used to provide the application parameters to Cloud Foundry. You may need to provide a different URL for the application if the `rabbitmq-rails` URL is already being used in your Cloud Foundry domain. The `manifest.yml` file specifies a RabbitMQ services that is available on the [run.pivotal.io](http://docs.cloudfoundry.com/docs/dotcom/getting-started.html) Cloud Foundry services marketplace. You may need to change the details of the RabbitMQ service to push to a different Cloud Foundry instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
applications: | ||
- name: rabbitmq-rails | ||
memory: 256M | ||
instances: 1 | ||
url: rabbitmq-rails.${target-base} | ||
path: . | ||
services: | ||
rabbit-rails: | ||
label: cloudamqp | ||
provider: cloudamqp | ||
version: n/a | ||
plan: lemur |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
This is a very simple Sinatra application demonstrating the use of RabbitMQ on Cloud Foundry. | ||
|
||
## Deploying to Cloud Foundry ## | ||
|
||
After installing in the 'cf' [command-line interface](http://docs.cloudfoundry.com/docs/using/managing-apps/cf/) for Cloud Foundry, targeting a Cloud Foundry instance, and logging in, the application can be pushed using these commands: | ||
|
||
$ cf push | ||
|
||
The provided `manifest.yml` file will be used to provide the application parameters to Cloud Foundry. You may need to provide a different URL for the application if the `rabbitmq-sinatra` URL is already being used in your Cloud Foundry domain. The `manifest.yml` file specifies a RabbitMQ services that is available on the [run.pivotal.io](http://docs.cloudfoundry.com/docs/dotcom/getting-started.html) Cloud Foundry services marketplace. You may need to change the details of the RabbitMQ service to push to a different Cloud Foundry instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require './rabbit' | ||
|
||
run RabbitMQ.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
applications: | ||
- name: rabbitmq-sinatra | ||
memory: 256M | ||
instances: 1 | ||
url: rabbitmq-sinatra.${target-base} | ||
path: . | ||
services: | ||
rabbit-sinatra: | ||
label: cloudamqp | ||
provider: cloudamqp | ||
version: n/a | ||
plan: lemur |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,94 @@ | ||
require 'sinatra' | ||
require 'sinatra/base' | ||
require 'erb' | ||
require 'cgi' | ||
|
||
require 'bunny' | ||
require 'json' | ||
|
||
enable :sessions | ||
|
||
# Extract the connection string for the rabbitmq service from the | ||
# service information provided by Cloud Foundry in an environment | ||
# variable. | ||
def amqp_url | ||
services = JSON.parse(ENV['VCAP_SERVICES'], :symbolize_names => true) | ||
url = services.values.map do |srvs| | ||
srvs.map do |srv| | ||
if srv[:label] =~ /^rabbitmq-/ | ||
srv[:credentials][:url] | ||
else | ||
[] | ||
class RabbitMQ < Sinatra::Base | ||
enable :sessions | ||
|
||
# Extract the connection string for the rabbitmq service from the | ||
# service information provided by Cloud Foundry in an environment | ||
# variable. | ||
def amqp_url | ||
services = JSON.parse(ENV['VCAP_SERVICES'], :symbolize_names => true) | ||
url = services.values.map do |srvs| | ||
srvs.map do |srv| | ||
if srv[:credentials][:uri] =~ /^amqp/ | ||
srv[:credentials][:uri] | ||
else | ||
[] | ||
end | ||
end | ||
end | ||
end.flatten!.first | ||
end | ||
end.flatten!.first | ||
end | ||
|
||
# Opens a client connection to the RabbitMQ service, if one isn't | ||
# already open. This is a class method because a new instance of | ||
# the controller class will be created upon each request. But AMQP | ||
# connections can be long-lived, so we would like to re-use the | ||
# connection across many requests. | ||
def client | ||
unless $client | ||
c = Bunny.new(amqp_url) | ||
c.start | ||
$client = c | ||
# Opens a client connection to the RabbitMQ service, if one isn't | ||
# already open. This is a class method because a new instance of | ||
# the controller class will be created upon each request. But AMQP | ||
# connections can be long-lived, so we would like to re-use the | ||
# connection across many requests. | ||
def client | ||
unless $client | ||
c = Bunny.new(amqp_url) | ||
c.start | ||
$client = c | ||
|
||
# We only want to accept one un-acked message | ||
$client.qos :prefetch_count => 1 | ||
# We only want to accept one un-acked message | ||
$client.qos :prefetch_count => 1 | ||
end | ||
$client | ||
end | ||
$client | ||
end | ||
|
||
# Return the "nameless exchange", pre-defined by AMQP as a means to | ||
# send messages to specific queues. Again, we use a class method to | ||
# share this across requests. | ||
def nameless_exchange | ||
$nameless_exchange ||= client.exchange('') | ||
end | ||
# Return the "nameless exchange", pre-defined by AMQP as a means to | ||
# send messages to specific queues. Again, we use a class method to | ||
# share this across requests. | ||
def nameless_exchange | ||
$nameless_exchange ||= client.exchange('') | ||
end | ||
|
||
# Return a queue named "messages". This will create the queue on | ||
# the server, if it did not already exist. Again, we use a class | ||
# method to share this across requests. | ||
def messages_queue | ||
$messages_queue ||= client.queue("messages") | ||
end | ||
# Return a queue named "messages". This will create the queue on | ||
# the server, if it did not already exist. Again, we use a class | ||
# method to share this across requests. | ||
def messages_queue | ||
$messages_queue ||= client.queue("messages") | ||
end | ||
|
||
def take_session key | ||
res = session[key] | ||
session[key] = nil | ||
res | ||
end | ||
def take_session key | ||
res = session[key] | ||
session[key] = nil | ||
res | ||
end | ||
|
||
get '/' do | ||
@published = take_session(:published) | ||
@got = take_session(:got) | ||
erb :index | ||
end | ||
get '/' do | ||
@published = take_session(:published) | ||
@got = take_session(:got) | ||
erb :index | ||
end | ||
|
||
post '/publish' do | ||
# Send the message from the form's input box to the "messages" | ||
# queue, via the nameless exchange. The name of the queue to | ||
# publish to is specified in the routing key. | ||
nameless_exchange.publish params[:message], :content_type => "text/plain", | ||
:key => "messages" | ||
# Notify the user that we published. | ||
session[:published] = true | ||
redirect to('/') | ||
end | ||
post '/publish' do | ||
# Send the message from the form's input box to the "messages" | ||
# queue, via the nameless exchange. The name of the queue to | ||
# publish to is specified in the routing key. | ||
nameless_exchange.publish params[:message], :content_type => "text/plain", | ||
:key => "messages" | ||
# Notify the user that we published. | ||
session[:published] = true | ||
redirect to('/') | ||
end | ||
|
||
post '/get' do | ||
session[:got] = :queue_empty | ||
post '/get' do | ||
session[:got] = :queue_empty | ||
|
||
# Wait for a message from the queue | ||
messages_queue.subscribe(:ack => true, :timeout => 10, | ||
:message_max => 1) do |msg| | ||
# Show the user what we got | ||
session[:got] = msg[:payload] | ||
end | ||
# Wait for a message from the queue | ||
messages_queue.subscribe(:ack => true, :timeout => 10, | ||
:message_max => 1) do |msg| | ||
# Show the user what we got | ||
session[:got] = msg[:payload] | ||
end | ||
|
||
redirect to('/') | ||
redirect to('/') | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This is a very simple Java and Spring application demonstrating the use of RabbitMQ on Cloud Foundry. | ||
|
||
## Deploying to Cloud Foundry ## | ||
|
||
After installing in the 'cf' [command-line interface](http://docs.cloudfoundry.com/docs/using/managing-apps/cf/) for Cloud Foundry, targeting a Cloud Foundry instance, and logging in, the application can be pushed using these commands: | ||
|
||
$ mvn package | ||
$ cf push | ||
|
||
The provided `manifest.yml` file will be used to provide the application parameters to Cloud Foundry. You may need to provide a different URL for the application if the `rabbitmq-spring` URL is already being used in your Cloud Foundry domain. The `manifest.yml` file specifies a RabbitMQ services that is available on the [run.pivotal.io](http://docs.cloudfoundry.com/docs/dotcom/getting-started.html) Cloud Foundry services marketplace. You may need to change the details of the RabbitMQ service to push to a different Cloud Foundry instance. |
Oops, something went wrong.