File: header.rb

package info (click to toggle)
ruby-amqp 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,508 kB
  • sloc: ruby: 8,272; sh: 11; makefile: 10
file content (123 lines) | stat: -rw-r--r-- 2,603 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# encoding: utf-8

module AMQP
  # Message metadata (aka envelope).
  class Header

    #
    # API
    #

    # @api public
    # @return [AMQP::Channel]
    attr_reader :channel

    # AMQP method frame this header is associated with.
    # Carries additional information that varies between AMQP methods.
    #
    # @api public
    # @return [AMQ::Protocol::Method]
    attr_reader :method

    # AMQP message attributes
    # @return [Hash]
    attr_reader :attributes

    # @api public
    def initialize(channel, method, attributes)
      @channel, @method, @attributes = channel, method, attributes
    end

    # Acknowledges the receipt of this message with the server.
    # @param [Boolean] multiple Whether or not to acknowledge multiple messages
    # @api public
    def ack(multiple = false)
      @channel.acknowledge(@method.delivery_tag, multiple)
    end

    # Reject this message.
    # @option opts [Hash] :requeue (false) Whether message should be requeued.
    # @api public
    def reject(opts = {})
      @channel.reject(@method.delivery_tag, opts.fetch(:requeue, false))
    end

    # @return [Hash] AMQP message header w/o method-specific information.
    # @api public
    def to_hash
      @attributes
    end # to_hash

    def delivery_tag
      @method.delivery_tag
    end # delivery_tag

    def consumer_tag
      @method.consumer_tag
    end # consumer_tag

    def redelivered
      @method.redelivered
    end # redelivered

    def redelivered?
      @method.redelivered
    end # redelivered?

    def exchange
      @method.exchange
    end # exchange

    # @deprecated
    def header
      @attributes
    end # header

    def headers
      @attributes[:headers]
    end # headers

    def delivery_mode
      @attributes[:delivery_mode]
    end # delivery_mode

    def content_type
      @attributes[:content_type]
    end # content_type

    def timestamp
      @attributes[:timestamp]
    end # timestamp

    def type
      @attributes[:type]
    end # type

    def priority
      @attributes[:priority]
    end # priority

    def reply_to
      @attributes[:reply_to]
    end # reply_to

    def correlation_id
      @attributes[:correlation_id]
    end # correlation_id

    def message_id
      @attributes[:message_id]
    end # message_id


    # Returns AMQP message attributes.
    # @api public
    def method_missing(meth, *args, &blk)
      if @attributes && args.empty? && blk.nil? && @attributes.has_key?(meth)
        @attributes[meth]
      else
        @method.__send__(meth, *args, &blk)
      end
    end
  end # Header
end # AMQP