Sha256: 06e4f89b9ab9ea4e5dafaa20044cc678788cb1cb771a551b709a527b241ab0f1

Contents?: true

Size: 966 Bytes

Versions: 18

Compression:

Stored size: 966 Bytes

Contents

#!/usr/bin/env ruby

require 'manageiq-messaging'
require_relative "common"

Thread::abort_on_exception = true

class ProducerConsumer < Common
  def run
    ManageIQ::Messaging::Client.open(q_options) do |client|
      puts "producer"
      5.times do |i|
        client.publish_message(
          :service  => 'ems_operation',
          :affinity => 'ems_amazon1',
          :message  => 'power_on',
          :payload  => {
            :ems_ref => 'u987',
            :id      => i.to_s,
          }
        )
      end
      puts "produced 5 messages"

      puts "consumer"
      client.subscribe_messages(:service => 'ems_operation', :affinity => 'ems_amazon1', :auto_ack => false) do |messages|
        messages.each do |msg|
          do_stuff(msg)
          msg.ack
        end
      end
      sleep(5)
      puts "consumed"
    end
  end

  def do_stuff(msg)
    puts "GOT MESSAGE: #{msg.message}: #{msg.payload}"
  end
end

ProducerConsumer.new.parse.run

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
manageiq-messaging-1.5.0 examples/message.rb
manageiq-messaging-1.4.3 examples/message.rb
manageiq-messaging-1.4.2 examples/message.rb
manageiq-messaging-1.4.1 examples/message.rb
manageiq-messaging-1.4.0 examples/message.rb
manageiq-messaging-1.3.0 examples/message.rb
manageiq-messaging-1.2.0 examples/message.rb
manageiq-messaging-1.1.2 examples/message.rb
manageiq-messaging-1.1.1 examples/message.rb
manageiq-messaging-1.1.0 examples/message.rb
manageiq-messaging-0.1.7 examples/message.rb
manageiq-messaging-1.0.3 examples/message.rb
manageiq-messaging-1.0.2 examples/message.rb
manageiq-messaging-1.0.1 examples/message.rb
manageiq-messaging-1.0.0 examples/message.rb
manageiq-messaging-0.1.6 examples/message.rb
manageiq-messaging-0.1.5 examples/message.rb
manageiq-messaging-0.1.4 examples/message.rb