Class: ActiveMessaging::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/activemessaging/gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(destination, processor_class, subscribe_headers = {}) ⇒ Subscription

Returns a new instance of Subscription.



385
386
387
388
# File 'lib/activemessaging/gateway.rb', line 385

def initialize(destination, processor_class, subscribe_headers = {})
  @destination, @processor_class, @subscribe_headers = destination, processor_class, subscribe_headers
  subscribe_headers['id'] = processor_class.name.underscore unless subscribe_headers.key? 'id'
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



383
384
385
# File 'lib/activemessaging/gateway.rb', line 383

def destination
  @destination
end

#processor_classObject

Returns the value of attribute processor_class.



383
384
385
# File 'lib/activemessaging/gateway.rb', line 383

def processor_class
  @processor_class
end

#subscribe_headersObject

Returns the value of attribute subscribe_headers.



383
384
385
# File 'lib/activemessaging/gateway.rb', line 383

def subscribe_headers
  @subscribe_headers
end

Instance Method Details

#subscribeObject



390
391
392
393
# File 'lib/activemessaging/gateway.rb', line 390

def subscribe
  ActiveMessaging.logger.error "=> Subscribing to #{destination.value} (processed by #{processor_class})"
  Gateway.connection(@destination.broker_name).subscribe(@destination.value, subscribe_headers) 
end

#unsubscribeObject



395
396
397
398
# File 'lib/activemessaging/gateway.rb', line 395

def unsubscribe
  ActiveMessaging.logger.error "=> Unsubscribing from #{destination.value} (processed by #{processor_class})"
  Gateway.connection(destination.broker_name).unsubscribe(destination.value, subscribe_headers)
end