-
Notifications
You must be signed in to change notification settings - Fork 2
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
ff0d7b2
commit b985afb
Showing
7 changed files
with
51 additions
and
48 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
web: bundle exec puma -t 0:6 -p ${PORT:-4500} -e ${RACK_ENV:-development} | ||
web: bundle exec ruby app.rb -p ${PORT:-4500} | ||
web: bundle exec ruby server.rb -p ${PORT:-4500} |
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
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,6 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "settings.rb" unless defined? Settings | ||
require File.join(Settings.root, "app") | ||
require File.join(Settings.root, "server") | ||
|
||
run App | ||
run Server |
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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "app.rb" | ||
|
||
require "sinatra" | ||
require "haml" | ||
|
||
class Server < Sinatra::Application | ||
configure do | ||
set :root, Settings.root | ||
set :server, :puma | ||
end | ||
|
||
get "/" do | ||
haml :index | ||
end | ||
|
||
get "/publish" do | ||
haml :publish | ||
end | ||
|
||
post "/publish" do | ||
routing_keys = params.fetch("routing_keys", "barcelona.ruby.event") | ||
message = { message: params["message"] } | ||
|
||
# Publish message: | ||
result = Client.publish(routing_keys: routing_keys, message: message) | ||
|
||
# For demonstration only: | ||
queue_name = "barcelona_ruby_event" | ||
queue = result.channel.queues.find { |name, _q| name == queue_name }&.last | ||
messages_count = queue&.message_count || 0 | ||
|
||
# TODO: check for success | ||
haml :publish, locals: { success: "Queue #{queue_name} has now #{messages_count} messages." } | ||
|
||
# TODO: rescue other possible errors | ||
rescue ArgumentError => e | ||
haml :publish, locals: { | ||
failure: "Error: the following message has not been delivered: '#{params[:message]}' to #{routing_keys}. Error: #{e}", | ||
} | ||
end | ||
end |
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