Class: AceMQ::AMQP::Patterns::Scheduler::Verbatim
- Inherits:
-
Object
- Object
- AceMQ::AMQP::Patterns::Scheduler::Verbatim
- Defined in:
- lib/acemq/amqp/patterns/scheduler.rb
Overview
Writes already-encoded bytes out unchanged, under the content type they were encoded as.
Publishing them through an ordinary codec would encode them a second time, and what arrives is JSON containing JSON. Publishing them with BytesCodec loses the content type, and what arrives cannot be decoded by the consumer that was waiting for it.
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
Instance Method Summary collapse
- #can_decode?(_content_type) ⇒ Boolean
- #decode(_body) ⇒ Object
- #encode(payload) ⇒ Object
-
#initialize(content_type) ⇒ Verbatim
constructor
A new instance of Verbatim.
Constructor Details
#initialize(content_type) ⇒ Verbatim
Returns a new instance of Verbatim.
137 138 139 140 |
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 137 def initialize(content_type) @content_type = content_type.to_s freeze end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
142 143 144 |
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 142 def content_type @content_type end |
Instance Method Details
#can_decode?(_content_type) ⇒ Boolean
154 |
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 154 def can_decode?(_content_type) = false |
#decode(_body) ⇒ Object
150 151 152 |
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 150 def decode(_body) raise DecodeError, "the scheduler only publishes" end |
#encode(payload) ⇒ Object
144 145 146 147 148 |
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 144 def encode(payload) return payload if payload.is_a?(String) raise EncodeError, "the scheduler moves bytes, not a #{payload.class}" end |