Class: Hutch::Publisher
- Inherits:
-
Object
- Object
- Hutch::Publisher
- Includes:
- Logging
- Defined in:
- lib/hutch/publisher.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
Instance Method Summary collapse
-
#initialize(connection, channel, exchange, config = Hutch::Config) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(routing_key, message, properties = {}, options = {}) ⇒ Object
Methods included from Logging
#logger, logger, logger=, setup_logger
Constructor Details
#initialize(connection, channel, exchange, config = Hutch::Config) ⇒ Publisher
Returns a new instance of Publisher.
10 11 12 13 14 15 |
# File 'lib/hutch/publisher.rb', line 10 def initialize(connection, channel, exchange, config = Hutch::Config) @connection = connection @channel = channel @exchange = exchange @config = config end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
8 9 10 |
# File 'lib/hutch/publisher.rb', line 8 def channel @channel end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/hutch/publisher.rb', line 8 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/hutch/publisher.rb', line 8 def connection @connection end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
8 9 10 |
# File 'lib/hutch/publisher.rb', line 8 def exchange @exchange end |
Instance Method Details
#publish(routing_key, message, properties = {}, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hutch/publisher.rb', line 17 def publish(routing_key, , properties = {}, = {}) ensure_connection!(routing_key, ) serializer = [:serializer] || config[:serializer] non_overridable_properties = { routing_key: routing_key, timestamp: connection., content_type: serializer.content_type, } properties[:message_id] ||= generate_id payload = serializer.encode() log_publication(serializer, payload, routing_key) response = exchange.publish(payload, {persistent: true}. merge(properties). merge(global_properties). merge(non_overridable_properties)) channel.wait_for_confirms if config[:force_publisher_confirms] response end |