Goofing around with JRuby implementation of chapter 4 alert stuff
This commit is contained in:
parent
c01332ff84
commit
d3918bd79c
5
sylvilagus/jruby/Gemfile
Normal file
5
sylvilagus/jruby/Gemfile
Normal file
@ -0,0 +1,5 @@
|
||||
source :rubygems
|
||||
|
||||
group :development, :test do
|
||||
gem 'rspec'
|
||||
end
|
18
sylvilagus/jruby/Gemfile.lock
Normal file
18
sylvilagus/jruby/Gemfile.lock
Normal file
@ -0,0 +1,18 @@
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
diff-lcs (1.1.3)
|
||||
rspec (2.12.0)
|
||||
rspec-core (~> 2.12.0)
|
||||
rspec-expectations (~> 2.12.0)
|
||||
rspec-mocks (~> 2.12.0)
|
||||
rspec-core (2.12.0)
|
||||
rspec-expectations (2.12.0)
|
||||
diff-lcs (~> 1.1.3)
|
||||
rspec-mocks (2.12.0)
|
||||
|
||||
PLATFORMS
|
||||
java
|
||||
|
||||
DEPENDENCIES
|
||||
rspec
|
2
sylvilagus/jruby/lib/sylvilagus.rb
Normal file
2
sylvilagus/jruby/lib/sylvilagus.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module Sylvilagus
|
||||
end
|
4
sylvilagus/jruby/lib/sylvilagus/ch04.rb
Normal file
4
sylvilagus/jruby/lib/sylvilagus/ch04.rb
Normal file
@ -0,0 +1,4 @@
|
||||
module Sylvilagus
|
||||
module Ch04
|
||||
end
|
||||
end
|
63
sylvilagus/jruby/lib/sylvilagus/ch04/alert_producer.rb
Normal file
63
sylvilagus/jruby/lib/sylvilagus/ch04/alert_producer.rb
Normal file
@ -0,0 +1,63 @@
|
||||
require 'sylvilagus/init'
|
||||
require 'sylvilagus/ch04'
|
||||
require 'optparse'
|
||||
require 'rabbitmq-client.jar'
|
||||
require 'gson.jar'
|
||||
import com.rabbitmq.client.ConnectionFactory
|
||||
import com.google.gson.Gson
|
||||
|
||||
class Sylvilagus::Ch04::AlertProducer
|
||||
def main
|
||||
opts = {}
|
||||
OptionParser.new do |opts|
|
||||
opts.on('-r', '--routing-key=',
|
||||
'Routing key for message (e.g. myalert.im)') do |r|
|
||||
opts[:routing_key] = r
|
||||
end
|
||||
opts.on('-m', '--message=', 'Message text for alert.') do |m|
|
||||
opts[:message] = m
|
||||
end
|
||||
end.parse!
|
||||
|
||||
factory = ConnectionFactory.new
|
||||
factory.uri = ENV.fetch('SYLVILAGUS_ALERT_AMQP_URI')
|
||||
@conn = factory.new_connection
|
||||
puts "Made it! conn=#{@conn}"
|
||||
channel = @conn.create_channel
|
||||
|
||||
gson = Gson.new
|
||||
puts gson.to_json({'wat' => 'now?', 'huh' => [1, 2, 3]})
|
||||
|
||||
ensure
|
||||
@conn.close if @conn
|
||||
end
|
||||
end
|
||||
|
||||
# creds_broker = pika.PlainCredentials('alert_user', 'alertme')
|
||||
# conn_params = pika.ConnectionParameters('localhost',
|
||||
# virtual_host='/',
|
||||
# credentials=creds_broker)
|
||||
# conn_broker = pika.BlockingConnection(conn_params)
|
||||
#
|
||||
# channel = conn_broker.channel()
|
||||
#
|
||||
# msg = json.dumps({'message': args.message})
|
||||
# msg_props = pika.BasicProperties()
|
||||
# msg_props.content_type = 'application/json'
|
||||
# msg_props.durable = False
|
||||
#
|
||||
# channel.basic_publish(body=msg,
|
||||
# exchange='alerts',
|
||||
# properties=msg_props,
|
||||
# routing_key=args.routing_key)
|
||||
#
|
||||
# print(
|
||||
# ('Sent message {} tagged with routing key {!r} to ' +
|
||||
# 'exchange "alerts" on vhost "/".').format(msg, args.routing_key)
|
||||
# )
|
||||
#
|
||||
# conn_broker.close()
|
||||
|
||||
if $0 == __FILE__
|
||||
Sylvilagus::Ch04::AlertProducer.new.main
|
||||
end
|
Loading…
Reference in New Issue
Block a user