Sha256: 645cfd21ec2ea1d7393af305cf0562039ad812d8d9186ebb4bf9a8b8f3dd545f

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module Carrot::AMQP
  class Exchange
    attr_accessor :server, :type, :name, :opts, :key

    def initialize(server, type, name, opts = {})
      @server, @type, @name, @opts = server, type, name, opts
      @key = opts[:key]

      unless name == "amq.#{type}" or name == ''
        server.send_frame(
          Protocol::Exchange::Declare.new(
            { :exchange => name, :type => type, :nowait => true }.merge(opts)
          )
        )
      end
    end
    attr_reader :name, :type, :key

    def publish(data, opts = {})
      out = []

      out << Protocol::Basic::Publish.new(
        { :exchange => name, :routing_key => opts.delete(:key) || key }.merge(opts)
      )
      data = data.to_s
      out << Protocol::Header.new(
        Protocol::Basic,
        data.length, {
          :content_type  => 'application/octet-stream',
          :delivery_mode => (opts.delete(:persistent) ? 2 : 1),
          :priority      => 0 
        }.merge(opts)
      )
      out << Frame::Body.new(data)

      server.send_frame(*out)
    end

    def delete(opts = {})
      server.send_frame(
        Protocol::Exchange::Delete.new({ :exchange => name, :nowait => true }.merge(opts))
      )
    end

    def reset
      initialize(server, type, name, opts)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
famoseagle-carrot-0.3.0 lib/amqp/exchange.rb
famoseagle-carrot-0.4.0 lib/amqp/exchange.rb
famoseagle-carrot-0.5.0 lib/amqp/exchange.rb