Class: TorqueBox::Messaging::Topic

Inherits:
Destination show all
Defined in:
lib/torquebox/messaging/topic.rb

Constant Summary collapse

DEFAULT_SUBSCRIBER_NAME =
'subscriber-1'

Constants inherited from Destination

Destination::PRIORITY_MAP

Instance Attribute Summary

Attributes inherited from Destination

#connect_options, #connection_factory, #enumerable_options, #java_destination, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Destination

#_dump, _load, #each, #initialize, list, lookup, #normalize_options, #publish, #receive, #stop, #stop_sync, #wait_for_destination, wait_for_latch, with_destinationizer, #with_session

Constructor Details

This class inherits a constructor from TorqueBox::Messaging::Destination

Class Method Details

.start(name, options = {}) ⇒ Topic?

Creates the topic, starts and return a Topic object.

Parameters:

  • name

    The name of the topic

  • options (defaults to: {})

    Optional parameters (a Hash), including:

Options Hash (options):

  • :exported (Boolean)

    If the topic should be visible in remote JNDI lookups

Returns:

  • (Topic)

    if the service is created and started

  • (nil)

    if the service is not created in the specified time (30 s)



36
37
38
39
40
41
42
43
44
# File 'lib/torquebox/messaging/topic.rb', line 36

def start(name, options={})
  exported = options.fetch(:exported, false)

  with_destinationizer do |destinationizer|
    destinationizer.create_topic(name, exported)
  end

  new(name, options)
end

Instance Method Details

#to_sObject



60
61
62
# File 'lib/torquebox/messaging/topic.rb', line 60

def to_s
  "[Topic: #{super}]"
end

#unsubscribe(subscriber_name = DEFAULT_SUBSCRIBER_NAME, options = { }) ⇒ void

This method returns an undefined value.

Unsubscribes the selected subscriber from the topic

Parameters:

  • subscriber_name (defaults to: DEFAULT_SUBSCRIBER_NAME)

    The subscriber name to unsubscribe

  • options (defaults to: { })

    Optional parameters (a Hash)



52
53
54
55
56
57
58
# File 'lib/torquebox/messaging/topic.rb', line 52

def unsubscribe(subscriber_name = DEFAULT_SUBSCRIBER_NAME, options = { })
  wait_for_destination(options[:startup_timeout]) do
    with_session do |session|
      session.unsubscribe( subscriber_name )
    end
  end
end