seller_dashboard_message_publisher 0.1.3-java
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +61 -0
- data/bin/console +14 -0
- data/bin/setup +99 -0
- data/bin/wrapper.sh +94 -0
- data/lib/seller_dashboard_message_publisher/app.rb +80 -0
- data/lib/seller_dashboard_message_publisher/data_manager.rb +65 -0
- data/lib/seller_dashboard_message_publisher/message.rb +43 -0
- data/lib/seller_dashboard_message_publisher/message_builder.rb +23 -0
- data/lib/seller_dashboard_message_publisher/message_publisher.rb +68 -0
- data/lib/seller_dashboard_message_publisher/version.rb +3 -0
- data/lib/seller_dashboard_message_publisher.rb +11 -0
- metadata +174 -0
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# SellerDashboard Message Publisher
|
2
|
+
|
3
|
+
Testing tool to publish messages to a private Manheim queue (such as Tibco)
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'seller_dashboard_message_publisher'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install seller_dashboard_message_publisher
|
21
|
+
|
22
|
+
Then in the Sellerdashboard, add change the config.ru file:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# This file is used by Rack-based servers to start the application.
|
26
|
+
|
27
|
+
require ::File.expand_path('../config/environment', __FILE__)
|
28
|
+
require 'seller_dashboard_message_publisher'
|
29
|
+
|
30
|
+
app = Rack::Builder.new do
|
31
|
+
map '/publisher' do
|
32
|
+
run SellerDashboardMessagePublisher::App.new
|
33
|
+
end
|
34
|
+
|
35
|
+
map '/' do
|
36
|
+
run Rails.application
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
run app
|
41
|
+
```
|
42
|
+
|
43
|
+
Once you start up the app, it will be accessible at the '/publisher' path
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
FIXME: Current usage is broken because the java jars are not being imported properly
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it ( http://github.ove.local/aokpokowur/seller_dashboard_message_publisher/fork )
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create a new Pull Request
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "seller_dashboard_message_publisher"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
|
5
|
+
bundle install
|
6
|
+
|
7
|
+
# Generic script for running ruby scripts as daemons using
|
8
|
+
# jsvc and a java class to control the daemon.
|
9
|
+
|
10
|
+
# Things you'll need to set on a per script/daemon basis:
|
11
|
+
# SCRIPT_NAME - Path to the ruby script which creates a Daemon
|
12
|
+
# object for jsvc to control
|
13
|
+
# APP_NAME - Name of your application
|
14
|
+
# MODULE_NAME
|
15
|
+
# JRUBY_JSVC_JAR
|
16
|
+
# DAEMON_JAR
|
17
|
+
# Things you can set:
|
18
|
+
# PROG_OPTS - Arguments to send to the program. A few defaults are appended to this.
|
19
|
+
|
20
|
+
export JRUBY_DAEMON_DEV=true
|
21
|
+
export SCRIPT_NAME=bin/wrapper
|
22
|
+
export MODULE_NAME="SellerDashboardMessagePublisher"
|
23
|
+
export JRUBY_JSVC_JAR=/vendor/jar/jruby-jsvc-0.5.0.jar
|
24
|
+
export DAEMON_JAR=/vendor/jar/commons-daemon-1.0.15.jar
|
25
|
+
|
26
|
+
export JRUBY_HOME="/usr/local/jruby-1.7.4/"
|
27
|
+
export BUNDLE_GEMFILE=Gemfile
|
28
|
+
|
29
|
+
# if [ -z ${SCRIPT_NAME} ]; then
|
30
|
+
# echo "SCRIPT_NAME not set"
|
31
|
+
# exit 1
|
32
|
+
# fi
|
33
|
+
|
34
|
+
# if [ -z ${MODULE_NAME} ]; then
|
35
|
+
# echo "MODULE_NAME not set"
|
36
|
+
# exit 1
|
37
|
+
# fi
|
38
|
+
|
39
|
+
# Local development - uncomment these to use jsvc-daemon from a working copy
|
40
|
+
if [ "${JRUBY_DAEMON_DEV}" ]; then
|
41
|
+
echo "jsvc-wrapper, in development mode"
|
42
|
+
JSVC=`which jsvc`
|
43
|
+
if [ -z ${JAVA_HOME} ]; then
|
44
|
+
JAVA_HOME=`jruby -e 'puts Java::JavaLang::System.get_property("java.home")'`
|
45
|
+
fi
|
46
|
+
if [ -z ${JRUBY_HOME} ]; then
|
47
|
+
JRUBY_HOME=`jruby -e 'puts Java::JavaLang::System.get_property("jruby.home")'`
|
48
|
+
fi
|
49
|
+
# Uncomment for debugging the daemon script
|
50
|
+
JSVC_ARGS_EXTRA="-debug "
|
51
|
+
JAVA_PROPS="-DJRubyDaemon.debug=true"
|
52
|
+
echo "JAVA_HOME : $JAVA_HOME"
|
53
|
+
echo "JRUBY_HOME : $JRUBY_HOME"
|
54
|
+
else
|
55
|
+
# Standard install
|
56
|
+
JSVC=/usr/bin/jsvc
|
57
|
+
JAVA_HOME=/etc/alternatives/jre_1.7.0
|
58
|
+
USER=overun
|
59
|
+
fi
|
60
|
+
|
61
|
+
# If you want your programs to run as or not as daemons pass a flag to tell them which they are
|
62
|
+
PROG_OPTS="$PROG_OPTS --daemon"
|
63
|
+
|
64
|
+
# Implements the jsvc Daemon interface.
|
65
|
+
MAIN_CLASS=com.msp.jsvc.JRubyDaemon
|
66
|
+
echo $MAIN_CLASS
|
67
|
+
|
68
|
+
RUBY_SCRIPT=$SCRIPT_NAME.rb
|
69
|
+
|
70
|
+
# Set some jars variables if they aren't already there
|
71
|
+
if [ ${#JRUBY_JSVC_JAR} -eq 0 ]; then
|
72
|
+
JRUBY_JSVC_JAR=/usr/share/java/jruby-jsvc.jar
|
73
|
+
fi
|
74
|
+
if [ ${#DAEMON_JAR} -eq 0 ]; then
|
75
|
+
DAEMON_JAR=/usr/share/java/commons-daemon.jar
|
76
|
+
fi
|
77
|
+
|
78
|
+
CLASSPATH=$JRUBY_HOME/lib/jruby.jar:$JRUBY_HOME/lib/profile.jar:$DAEMON_JAR:$JRUBY_JSVC_JAR
|
79
|
+
|
80
|
+
echo "CLASSPATH : $CLASSPATH"
|
81
|
+
|
82
|
+
JAVA_PROPS="$JAVA_PROPS -Djruby.memory.max=500m \
|
83
|
+
-Djruby.stack.max=1024k \
|
84
|
+
-Djna.boot.library.path=$JRUBY_HOME/lib/native/linux-i386:$JRUBY_HOME/lib/native/linux-amd64 \
|
85
|
+
-Djffi.boot.library.path=$JRUBY_HOME/lib/native/i386-Linux:$JRUBY_HOME/jruby/lib/native/s390x-Linux:$JRUBY_HOME/lib/native/x86_64-Linux \
|
86
|
+
-Djruby.home=$JRUBY_HOME \
|
87
|
+
-Djruby.lib=$JRUBY_HOME/lib \
|
88
|
+
-Djruby.script=jruby \
|
89
|
+
-Djruby.compat.version=RUBY1_9 \
|
90
|
+
-Djruby.shell=/bin/sh \
|
91
|
+
-Djruby.daemon.module.name=$MODULE_NAME"
|
92
|
+
|
93
|
+
JAVA_OPTS="-XX:MaxPermSize=128m -Xmx500m -Xss1024k -Xbootclasspath/a:$JRUBY_HOME/lib/jruby.jar:$JRUBY_HOME/lib/bsf.jar"
|
94
|
+
|
95
|
+
JSVC_ARGS="-home $JAVA_HOME \
|
96
|
+
$JSVC_ARGS_EXTRA \
|
97
|
+
-wait 20 \
|
98
|
+
-user $USER \
|
99
|
+
-jvm server "
|
data/bin/wrapper.sh
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#! /bin/sh
|
2
|
+
# Generic script for running ruby scripts as daemons using
|
3
|
+
# jsvc and a java class to control the daemon.
|
4
|
+
#
|
5
|
+
# Contains common parameters and start/stop
|
6
|
+
|
7
|
+
# Things you'll need to set on a per script/daemon basis:
|
8
|
+
# SCRIPT_NAME - Path to the ruby script which creates a Daemon
|
9
|
+
# object for jsvc to control
|
10
|
+
# APP_NAME - Name of your application
|
11
|
+
# MODULE_NAME
|
12
|
+
# JRUBY_JSVC_JAR
|
13
|
+
# DAEMON_JAR
|
14
|
+
# Things you can set:
|
15
|
+
# PROG_OPTS - Arguments to send to the program. A few defaults are appended to this.
|
16
|
+
|
17
|
+
# if [ -z ${SCRIPT_NAME} ]; then
|
18
|
+
# echo "SCRIPT_NAME not set"
|
19
|
+
# exit 1
|
20
|
+
# fi
|
21
|
+
|
22
|
+
# if [ -z ${MODULE_NAME} ]; then
|
23
|
+
# echo "MODULE_NAME not set"
|
24
|
+
# exit 1
|
25
|
+
# fi
|
26
|
+
|
27
|
+
# Local development - uncomment these to use jsvc-daemon from a working copy
|
28
|
+
if [ "${JRUBY_DAEMON_DEV}" ]; then
|
29
|
+
echo "jsvc-wrapper, in development mode"
|
30
|
+
JSVC=`which jsvc`
|
31
|
+
if [ -z ${JAVA_HOME} ]; then
|
32
|
+
JAVA_HOME=`jruby -e 'puts Java::JavaLang::System.get_property("java.home")'`
|
33
|
+
fi
|
34
|
+
if [ -z ${JRUBY_HOME} ]; then
|
35
|
+
JRUBY_HOME=`jruby -e 'puts Java::JavaLang::System.get_property("jruby.home")'`
|
36
|
+
fi
|
37
|
+
# Uncomment for debugging the daemon script
|
38
|
+
JSVC_ARGS_EXTRA="-debug "
|
39
|
+
JAVA_PROPS="-DJRubyDaemon.debug=true"
|
40
|
+
echo "JAVA_HOME : $JAVA_HOME"
|
41
|
+
echo "JRUBY_HOME : $JRUBY_HOME"
|
42
|
+
else
|
43
|
+
# Standard install
|
44
|
+
JSVC=/usr/bin/jsvc
|
45
|
+
JAVA_HOME=/etc/alternatives/jre_1.7.0
|
46
|
+
USER=overun
|
47
|
+
fi
|
48
|
+
|
49
|
+
# If you want your programs to run as or not as daemons pass a flag to tell them which they are
|
50
|
+
PROG_OPTS="$PROG_OPTS --daemon"
|
51
|
+
|
52
|
+
# Implements the jsvc Daemon interface.
|
53
|
+
MAIN_CLASS=com.msp.jsvc.JRubyDaemon
|
54
|
+
echo $MAIN_CLASS
|
55
|
+
|
56
|
+
RUBY_SCRIPT=$SCRIPT_NAME.rb
|
57
|
+
|
58
|
+
# Set some jars variables if they aren't already there
|
59
|
+
if [ ${#JRUBY_JSVC_JAR} -eq 0 ]; then
|
60
|
+
JRUBY_JSVC_JAR=/usr/share/java/jruby-jsvc.jar
|
61
|
+
fi
|
62
|
+
if [ ${#DAEMON_JAR} -eq 0 ]; then
|
63
|
+
DAEMON_JAR=/usr/share/java/commons-daemon.jar
|
64
|
+
fi
|
65
|
+
|
66
|
+
CLASSPATH=$JRUBY_HOME/lib/jruby.jar:$JRUBY_HOME/lib/profile.jar:$DAEMON_JAR:$JRUBY_JSVC_JAR
|
67
|
+
|
68
|
+
echo "CLASSPATH : $CLASSPATH"
|
69
|
+
|
70
|
+
JAVA_PROPS="$JAVA_PROPS -Djruby.memory.max=500m \
|
71
|
+
-Djruby.stack.max=1024k \
|
72
|
+
-Djna.boot.library.path=$JRUBY_HOME/lib/native/linux-i386:$JRUBY_HOME/lib/native/linux-amd64 \
|
73
|
+
-Djffi.boot.library.path=$JRUBY_HOME/lib/native/i386-Linux:$JRUBY_HOME/jruby/lib/native/s390x-Linux:$JRUBY_HOME/lib/native/x86_64-Linux \
|
74
|
+
-Djruby.home=$JRUBY_HOME \
|
75
|
+
-Djruby.lib=$JRUBY_HOME/lib \
|
76
|
+
-Djruby.script=jruby \
|
77
|
+
-Djruby.compat.version=RUBY1_9 \
|
78
|
+
-Djruby.shell=/bin/sh \
|
79
|
+
-Djruby.daemon.module.name=$MODULE_NAME"
|
80
|
+
|
81
|
+
JAVA_OPTS="-XX:MaxPermSize=128m -Xmx500m -Xss1024k -Xbootclasspath/a:$JRUBY_HOME/lib/jruby.jar:$JRUBY_HOME/lib/bsf.jar"
|
82
|
+
|
83
|
+
JSVC_ARGS="-home $JAVA_HOME \
|
84
|
+
$JSVC_ARGS_EXTRA \
|
85
|
+
-wait 20 \
|
86
|
+
-user $USER \
|
87
|
+
-jvm server "
|
88
|
+
|
89
|
+
#
|
90
|
+
# Stop/Start
|
91
|
+
#
|
92
|
+
|
93
|
+
# STOP_COMMAND="$JSVC $JSVC_ARGS -stop $MAIN_CLASS"
|
94
|
+
# START_COMMAND="$JSVC $JSVC_ARGS -cp $CLASSPATH $JAVA_PROPS $JAVA_OPTS $MAIN_CLASS $RUBY_SCRIPT $PROG_OPTS"
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
|
3
|
+
module SellerDashboardMessagePublisher
|
4
|
+
class App < Sinatra::Base
|
5
|
+
get '/' do
|
6
|
+
@title = 'Pubnub Publisher'
|
7
|
+
|
8
|
+
@message_types = ['sold', 'startrun', 'nosale', 'vehchg']
|
9
|
+
@ods_message_types = ['ods_no_sale', 'ods_purchased', 'ods_purchase_offer']
|
10
|
+
@environments = ['development', 'ci1', 'ci2', 'ba', 'uat', 'production']
|
11
|
+
|
12
|
+
haml :'/index'
|
13
|
+
end
|
14
|
+
|
15
|
+
post '/publish' do
|
16
|
+
@title = 'Published Simulcast Message'
|
17
|
+
@auction = params['auction'].upcase
|
18
|
+
@noop = params['noop']
|
19
|
+
|
20
|
+
@message_type = params['message_type']
|
21
|
+
@vin = params['vin']
|
22
|
+
@sale = params['sale']
|
23
|
+
@lane = params['lane']
|
24
|
+
@run = params['run']
|
25
|
+
@bid = params['bid']
|
26
|
+
|
27
|
+
@time = Time.now
|
28
|
+
@message_attributes = {
|
29
|
+
'vin' => @vin,
|
30
|
+
'sale' => @sale,
|
31
|
+
'lane' => @lane,
|
32
|
+
'run' => @run,
|
33
|
+
'bid' => @bid
|
34
|
+
}
|
35
|
+
|
36
|
+
logger = Logger.new(STDOUT)
|
37
|
+
config = ConfigLoader.load(logger, ENV['ENV'])['queues']
|
38
|
+
|
39
|
+
publisher = MessagePublisher.new(config, logger).connect
|
40
|
+
|
41
|
+
message = Message.new
|
42
|
+
message = MessageBuilder.build_from_form(@message_type, @auction, @message_attributes)
|
43
|
+
|
44
|
+
if @message_type == 'sold'
|
45
|
+
data_manager = DataManager.build(logger, @noop)
|
46
|
+
listing = data_manager.load_listing(message[:sale], message[:lane], message[:run])
|
47
|
+
data_manager.sell(listing, message[:bid])
|
48
|
+
end
|
49
|
+
|
50
|
+
require 'pry'; binding.pry
|
51
|
+
|
52
|
+
publisher.publish message
|
53
|
+
publisher.close_all_connections
|
54
|
+
|
55
|
+
haml :'/message'
|
56
|
+
end
|
57
|
+
|
58
|
+
post '/publish_ods' do
|
59
|
+
@title = 'Published ODS Message'
|
60
|
+
@auction = params['auction'].upcase
|
61
|
+
@message_type = params['message_type']
|
62
|
+
@lane = params['lane']
|
63
|
+
@message_attributes = {
|
64
|
+
'lane' => @lane
|
65
|
+
}
|
66
|
+
|
67
|
+
logger = Logger.new(STDOUT)
|
68
|
+
config = ConfigLoader.load(logger, ENV['ENV'])['queues']
|
69
|
+
|
70
|
+
|
71
|
+
message = MessageBuilder.build_from_form(@message_type, @auction, @message_attributes)
|
72
|
+
|
73
|
+
publisher = MessagePublisher.new(config, logger).connect
|
74
|
+
publisher.publish message
|
75
|
+
publisher.close_all_connections
|
76
|
+
|
77
|
+
haml :'/ods_message'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class DataManager
|
2
|
+
attr_reader :logger
|
3
|
+
|
4
|
+
def self.build(logger, noop)
|
5
|
+
data_manager = noop ? NullDataManager.new(logger) : self.new(logger)
|
6
|
+
data_manager.log_noop_message
|
7
|
+
data_manager
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(logger)
|
11
|
+
@logger = logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_lane(sale, lane)
|
15
|
+
DataFactory::As400::Car.where('SSALE# = ? AND SLANE# = ?', sale, lane).order('SRUN# ASC')
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_listing(sale, lane, run)
|
19
|
+
DataFactory::As400::Car.where('SSALE# = ? AND SLANE#= ? AND SRUN# = ?', sale, lane, run).limit(1).first
|
20
|
+
end
|
21
|
+
|
22
|
+
def sell(listing, price=nil)
|
23
|
+
price = rand(5_000) + 10_000 if price.nil?
|
24
|
+
listing.sale_code = 'SS'
|
25
|
+
listing.seller_price = price
|
26
|
+
listing.sifsle = ' '
|
27
|
+
listing.times_run = 1
|
28
|
+
|
29
|
+
listing.save!
|
30
|
+
|
31
|
+
FactoryGirl.create(:high_bid,
|
32
|
+
vehicle_unique_number: listing.vehicle_unique_number,
|
33
|
+
high_bid: price,
|
34
|
+
sale_date: Time.now.strftime('%Y%m%d').to_i)
|
35
|
+
|
36
|
+
logger.info 'Persisted vehicle sell to the AS400'
|
37
|
+
|
38
|
+
price
|
39
|
+
end
|
40
|
+
|
41
|
+
def log_noop_message
|
42
|
+
logger.warn 'NOOP is OFF: the AS400 will be updated with any necessary data.'
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class NullDataManager < DataManager
|
48
|
+
attr_reader :logger
|
49
|
+
|
50
|
+
def initialize(logger)
|
51
|
+
@logger = logger
|
52
|
+
end
|
53
|
+
|
54
|
+
def log_noop_message
|
55
|
+
logger.info 'NOOP is ON: only a message will be sent. The AS400 will not be updated.'
|
56
|
+
end
|
57
|
+
|
58
|
+
def sell(listing=nil, price=nil)
|
59
|
+
log_noop_message
|
60
|
+
end
|
61
|
+
|
62
|
+
def method_missing(*args, &block)
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SellerDashboardMessagePublisher
|
2
|
+
class Message
|
3
|
+
DEFAULT_OTHER_ATTRIBUTES = {
|
4
|
+
startrun: {
|
5
|
+
run_number: 10,
|
6
|
+
timestamp: Time.now
|
7
|
+
},
|
8
|
+
nosale: {
|
9
|
+
run_number: 10,
|
10
|
+
timestamp: Time.now
|
11
|
+
},
|
12
|
+
sold: {
|
13
|
+
run_number: 10,
|
14
|
+
bid: 12500,
|
15
|
+
timestamp: Time.now
|
16
|
+
},
|
17
|
+
vehchg: {
|
18
|
+
timestamp: Time.now
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
attr_reader :message_type, :message_attributes
|
23
|
+
|
24
|
+
def initialize(message_type = '', message_attributes = {})
|
25
|
+
@message_type = message_type
|
26
|
+
|
27
|
+
message_attributes.reject! { |_, value| value.nil? }
|
28
|
+
@message_attributes = DEFAULT_OTHER_ATTRIBUTES.fetch(message_type.to_sym, {})
|
29
|
+
.merge(message_attributes)
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](attribute)
|
33
|
+
message_attributes[attribute]
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_message_body
|
37
|
+
file = File.read(File.join(File.dirname(__FILE__), "../../messages/#{message_type}.xml.erb"))
|
38
|
+
ERB.new(file, nil, '<>').result(binding)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SellerDashboardMessagePublisher
|
2
|
+
class MessageBuilder
|
3
|
+
|
4
|
+
REQUIRED_ATTRIBUTES = {
|
5
|
+
startrun: [:vin, :lane, :run],
|
6
|
+
nosale: [:vin, :lane, :run],
|
7
|
+
sold: [:vin, :sale, :lane, :run, :bid],
|
8
|
+
vehchg: [:sale, :lane, :run],
|
9
|
+
ods_no_sale: [:lane],
|
10
|
+
ods_purchased: [:lane],
|
11
|
+
ods_purchase_offer: [:lane]
|
12
|
+
}
|
13
|
+
|
14
|
+
def self.build_from_form(message_type, auction, message_values)
|
15
|
+
message_attributes = REQUIRED_ATTRIBUTES[message_type.to_sym].inject({}) do |message_attributes, attribute|
|
16
|
+
message_attributes.merge(attribute => message_values[attribute.to_s])
|
17
|
+
end
|
18
|
+
Message.new(message_type, message_attributes.merge(auction: auction))
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'java'
|
2
|
+
|
3
|
+
module SellerDashboardMessagePublisher
|
4
|
+
class MessagePublisher
|
5
|
+
# FIXME: NameError: cannot load Java class javax.jms.Session
|
6
|
+
# ACK_MODE = Java::JavaxJms::Session.CLIENT_ACKNOWLEDGE
|
7
|
+
ACK_MODE = 2
|
8
|
+
|
9
|
+
attr_reader :config, :logger, :connection, :session, :producer, :ods_producer
|
10
|
+
|
11
|
+
def initialize(config, logger)
|
12
|
+
@config = config
|
13
|
+
@logger = logger
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect
|
17
|
+
factory = Java::ComTibcoTibjms::TibjmsQueueConnectionFactory.new(config['servers'].join(','))
|
18
|
+
@connection = factory.createQueueConnection(config['username'], config['password'])
|
19
|
+
@session = connection.createQueueSession(false, ACK_MODE)
|
20
|
+
|
21
|
+
queue = session.createQueue(config['name'])
|
22
|
+
ods_queue = session.createQueue(config['ods_name'])
|
23
|
+
|
24
|
+
@producer = session.createProducer(queue)
|
25
|
+
@ods_producer = session.createProducer(ods_queue)
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def assemble(message)
|
31
|
+
queue_message = session.createTextMessage(message.create_message_body)
|
32
|
+
queue_message.setStringProperty('AUCTION_ID', message[:auction])
|
33
|
+
queue_message.setStringProperty('MSG_TYPE', message_type_header_for(message.message_type))
|
34
|
+
|
35
|
+
logger.info "Publishing message #{queue_message}"
|
36
|
+
queue_message
|
37
|
+
end
|
38
|
+
|
39
|
+
def publish(message)
|
40
|
+
producer.send(assemble(message))
|
41
|
+
end
|
42
|
+
|
43
|
+
def publish_ods(message)
|
44
|
+
ods_producer.send(assemble(message))
|
45
|
+
end
|
46
|
+
|
47
|
+
def close_all_connections
|
48
|
+
logger.info 'Closing all connections'
|
49
|
+
producer.close
|
50
|
+
ods_producer.close
|
51
|
+
session.close
|
52
|
+
connection.stop
|
53
|
+
connection.close
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
NON_STANDARD_MESSAGE_TYPES = {
|
59
|
+
ods_no_sale: 'Seller Offering No Sale',
|
60
|
+
ods_purchased: 'Seller Offering Purchased',
|
61
|
+
ods_purchase_offer: 'Purchase Offer Placed'
|
62
|
+
}
|
63
|
+
def message_type_header_for(message_type)
|
64
|
+
NON_STANDARD_MESSAGE_TYPES.fetch(message_type.to_sym, message_type.to_s.upcase)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "seller_dashboard_message_publisher/version"
|
2
|
+
require "seller_dashboard_message_publisher/message"
|
3
|
+
require "seller_dashboard_message_publisher/message_builder"
|
4
|
+
require "seller_dashboard_message_publisher/message_publisher"
|
5
|
+
require "seller_dashboard_message_publisher/data_manager"
|
6
|
+
require_relative "../config/config_loader"
|
7
|
+
|
8
|
+
module SellerDashboardMessagePublisher
|
9
|
+
# Your code goes here...
|
10
|
+
autoload :App, 'seller_dashboard_message_publisher/app'
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seller_dashboard_message_publisher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
prerelease:
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- Ayanga Okpokowuruk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :runtime
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: haml
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
none: false
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
none: false
|
44
|
+
prerelease: false
|
45
|
+
type: :runtime
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activesupport
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
none: false
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
none: false
|
60
|
+
prerelease: false
|
61
|
+
type: :runtime
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pubnub
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
none: false
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
none: false
|
76
|
+
prerelease: false
|
77
|
+
type: :runtime
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: data_factory
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
none: false
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
none: false
|
92
|
+
prerelease: false
|
93
|
+
type: :runtime
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: bundler
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '1.9'
|
101
|
+
none: false
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ~>
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '1.9'
|
107
|
+
none: false
|
108
|
+
prerelease: false
|
109
|
+
type: :development
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ~>
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '10.0'
|
117
|
+
none: false
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ~>
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '10.0'
|
123
|
+
none: false
|
124
|
+
prerelease: false
|
125
|
+
type: :development
|
126
|
+
description: Testing tool to publish messages to a private Manheim queue (such as Tibco)
|
127
|
+
email:
|
128
|
+
- ayanga.okpokowuruk@manheim.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- lib/seller_dashboard_message_publisher.rb
|
134
|
+
- lib/seller_dashboard_message_publisher/app.rb
|
135
|
+
- lib/seller_dashboard_message_publisher/data_manager.rb
|
136
|
+
- lib/seller_dashboard_message_publisher/message.rb
|
137
|
+
- lib/seller_dashboard_message_publisher/message_builder.rb
|
138
|
+
- lib/seller_dashboard_message_publisher/message_publisher.rb
|
139
|
+
- lib/seller_dashboard_message_publisher/version.rb
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- bin/wrapper.sh
|
143
|
+
- README.md
|
144
|
+
homepage: http://github.ove.local/aokpokowur/seller_dashboard_message_publisher
|
145
|
+
licenses: []
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
version: '0'
|
157
|
+
hash: 2
|
158
|
+
none: false
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - '>='
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
version: '0'
|
166
|
+
hash: 2
|
167
|
+
none: false
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 1.8.24
|
171
|
+
signing_key:
|
172
|
+
specification_version: 3
|
173
|
+
summary: Seller Dashboard app to send test messages to a queue
|
174
|
+
test_files: []
|