Class: JSparrow::Interactors::Listener
- Inherits:
-
Object
- Object
- JSparrow::Interactors::Listener
- Includes:
- MessageListener
- Defined in:
- lib/interaction/listener.rb
Overview
Message listener.
Class Method Summary collapse
-
.listen_to(destination) ⇒ Object
Name (configured in connection setup) of JMS destination to listen to.
-
.receive_only_in_criteria(criteria = {:selector => ''}) ⇒ Object
Selector criteria to receive the messages, following the JMS pattern.
Instance Method Summary collapse
-
#initialize(connection) ⇒ Listener
constructor
A new instance of Listener.
- #is_listening? ⇒ Boolean
-
#on_message(received_message) ⇒ Object
It’s part of JMS Listener interface.
-
#on_receive_message(received_message) ⇒ Object
Callback mathod to receive enriched messages.
- #start_listening ⇒ Object
- #stop_listening ⇒ Object
Constructor Details
#initialize(connection) ⇒ Listener
Returns a new instance of Listener.
52 53 54 |
# File 'lib/interaction/listener.rb', line 52 def initialize(connection) @connection = connection end |
Class Method Details
.listen_to(destination) ⇒ Object
Name (configured in connection setup) of JMS destination to listen to.
Must be used by subclasses to configure destination.
listen_to :queue => :registered_name_of_queue listen_to :topic => :registered_name_of_topic
26 27 28 |
# File 'lib/interaction/listener.rb', line 26 def listen_to(destination) configure(:listen_to_destination, destination) end |
.receive_only_in_criteria(criteria = {:selector => ''}) ⇒ Object
Selector criteria to receive the messages, following the JMS pattern.
Should be used by subclasses when want to set criterias to message selection.
receive_only_in_criteria :selector => “recipient = ‘jsparrow-spec’ and to_listener = ‘TestQueueListener’”
37 38 39 |
# File 'lib/interaction/listener.rb', line 37 def receive_only_in_criteria(criteria = {:selector => ''}) configure(:criteria_to_receiving, criteria) end |
Instance Method Details
#is_listening? ⇒ Boolean
56 57 58 |
# File 'lib/interaction/listener.rb', line 56 def is_listening? @connection.is_opened? end |
#on_message(received_message) ⇒ Object
It’s part of JMS Listener interface. Shouldn’t be overrided by subclasses.
86 87 88 89 90 91 92 |
# File 'lib/interaction/listener.rb', line 86 def () class << include JMS::Message::TypingMethods end () end |
#on_receive_message(received_message) ⇒ Object
Callback mathod to receive enriched messages.
Must be overrided by subclasses.
99 100 101 |
# File 'lib/interaction/listener.rb', line 99 def () raise Error::AbstractMethodError.new(self.class.superclass, 'on_receive_message') end |
#start_listening ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/interaction/listener.rb', line 60 def start_listening @connection.open connection_factory, destination = lookup_resources selector = criteria_to_receiving[:selector] if respond_to? :criteria_to_receiving @listening_connection = connection_factory.create_connection session = @listening_connection.create_session(false, Session::AUTO_ACKNOWLEDGE) consumer = session.create_consumer(destination, selector) consumer. = self @listening_connection.start end |
#stop_listening ⇒ Object
77 78 79 80 81 |
# File 'lib/interaction/listener.rb', line 77 def stop_listening @listening_connection.close @connection.close end |