Class: ReliableMsg::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/reliable-msg/client.rb

Overview

Base class for both Queue and Topic client APIs.

Direct Known Subclasses

Topic

Constant Summary collapse

ERROR_INVALID_SELECTOR =

:nodoc:

"Selector must be message identifier (String), set of header name/value pairs (Hash), Selector object, or nil"
ERROR_INVALID_TX_TIMEOUT =

:nodoc:

"Invalid transaction timeout: must be a non-zero positive integer"
ERROR_INVALID_CONNECT_COUNT =

:nodoc:

"Invalid connection count: must be a non-zero positive integer"
ERROR_SELECTOR_VALUE_OR_BLOCK =

:nodoc:

"You can either pass a Selector object, or use a block"
ERROR_INVALID_INIT_OPTION =

:nodoc:

"Unrecognized initialization option %s"
DRB_PORT =

The default DRb port used to connect to the queue manager.

6438
DEFAULT_DRB_URI =

:nodoc:

"druby://localhost:#{DRB_PORT}"
DEFAULT_CONNECT_RETRY =

Number of times to retry a connecting to the queue manager.

5
DEFAULT_TX_TIMEOUT =

Default transaction timeout.

120
THREAD_CURRENT_TX =

Thread.current entry for queue transaction.

:reliable_msg_tx
DLQ =

The name of the dead letter queue (DLQ). Messages that expire or fail to process are automatically sent to the dead letter queue.

DEAD_LETTER_QUEUE = "$dlq"
@@drb_uri =

DRb URI for queue manager. You can override this to change the URI globally, for all Queue objects that are not instantiated with an alternative URI.

DEFAULT_DRB_URI
@@qm =

Reference to the local queue manager. Defaults to a DRb object, unless the queue manager is running locally.

nil
@@qm_cache =

Cache of queue managers referenced by their URI.

{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.selector(&block) ⇒ Object

Create and return a new selector based on the block expression. Same as Selector.new. For example:

selector = Queue.selector { priority >= 2 and received > Time.new.to_i - 60 }

Raises:

  • (ArgumentError)


95
96
97
98
# File 'lib/reliable-msg/client.rb', line 95

def self.selector &block
    raise ArgumentError, ERROR_NO_SELECTOR_BLOCK unless block
    Selector.new &block
end

Instance Method Details

#connect_countObject

Returns the number of connection attempts, before operations fail.



77
78
79
# File 'lib/reliable-msg/client.rb', line 77

def connect_count
    @connect_count || DEFAULT_CONNECT_RETRY
end

#connect_count=(count) ⇒ Object

Sets the number of connection attempts, before operations fail. The minimum is one. Use nil to restore the default connection count.



83
84
85
86
87
88
89
90
# File 'lib/reliable-msg/client.rb', line 83

def connect_count= count
    if count
        raise ArgumentError, ERROR_INVALID_CONNECT_COUNT unless count.instance_of?(Integer) and count > 0
        @connect_count = count
    else
        @connect_count = nil
    end
end

#selector(&block) ⇒ Object

Create and return a new selector based on the block expression. Same as Selector.new. For example:

selector = Queue.selector { priority >= 2 and received > Time.new.to_i - 60 }

Raises:

  • (ArgumentError)


103
104
105
106
# File 'lib/reliable-msg/client.rb', line 103

def selector & block
    raise ArgumentError, ERROR_NO_SELECTOR_BLOCK unless block
    Selector.new &block
end

#tx_timeoutObject

Returns the transaction timeout (in seconds).



61
62
63
# File 'lib/reliable-msg/client.rb', line 61

def tx_timeout
    @tx_timeout || DEFAULT_TX_TIMEOUT
end

#tx_timeout=(timeout) ⇒ Object

Sets the transaction timeout (in seconds). Affects future transactions started by Queue.get. Use nil to restore the default timeout.



67
68
69
70
71
72
73
74
# File 'lib/reliable-msg/client.rb', line 67

def tx_timeout= timeout
    if timeout
        raise ArgumentError, ERROR_INVALID_TX_TIMEOUT unless timeout.instance_of?(Integer) and timeout > 0
        @tx_timeout = timeout
    else
        @tx_timeout = nil
    end
end