Sha256: 243403979812f9ad96d2caff2f89704930d6a261f8e6fa86edabe13a905e2467

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

################################################################################
#  Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
################################################################################

#
# Example : files_to_q : Place all files in a directory to a queue
#          Each file is written as a separate message
#
require 'find'
require 'yaml'
require 'wmq/wmq'

# Call program passing environment name as first parameter
#   The environment corresponds to an entry in the config file
env = ARGV[0] || raise("Command line argument 'environment' is required")
config = YAML::load_file('files_to_q.cfg')[env]

message = WMQ::Message.new
message.descriptor = config['descriptor'] || {}
tstart = Time.now
counter = 0
WMQ::QueueManager.connect(config['qmgr_options']) do |qmgr|
  qmgr.open_queue({:mode=>:output}.merge(config['output_queue'])) do |queue|
    Find.find(config['source_directory']) do |path|
      unless FileTest.directory?(path)
        printf("%5d: #{path}\n",counter = counter + 1)
        message.data = File.read(path)
        queue.put({:message => message}.merge(config['put_options']))
      end
    end
  end
end
duration = Time.now - tstart
printf "Processed #{counter} messages in %.3f seconds. Average: %.3f messages/second\n", duration, counter/duration

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubywmq-0.3.0-i386-mswin32-mq6 examples/files_to_q.rb
rubywmq-0.3.0-i386-mswin32-mq5.3 examples/files_to_q.rb