Class: HornetQ::Client::ServerPattern
- Inherits:
-
Object
- Object
- HornetQ::Client::ServerPattern
- Defined in:
- lib/hornetq/client/server_pattern.rb
Overview
Create a Server following the ServerPattern for receiving requests and replying to arbitrary queues Create an instance of this class per thread
Instance Method Summary collapse
-
#close ⇒ Object
Close out resources.
-
#initialize(session, request_queue, timeout) ⇒ ServerPattern
constructor
A new instance of ServerPattern.
-
#reply(request_message, reply_message) ⇒ Object
Send a reply to the received request message request: is the message received reply: is the message to send to the client.
- #run(&block) ⇒ Object
Constructor Details
#initialize(session, request_queue, timeout) ⇒ ServerPattern
Returns a new instance of ServerPattern.
6 7 8 9 10 11 |
# File 'lib/hornetq/client/server_pattern.rb', line 6 def initialize(session, request_queue, timeout) @session = session @consumer = session.create_consumer(request_queue) @producer = session.create_producer @timeout = timeout end |
Instance Method Details
#close ⇒ Object
Close out resources
47 48 49 50 |
# File 'lib/hornetq/client/server_pattern.rb', line 47 def close @consumer.close if @consumer @producer.close if @producer end |
#reply(request_message, reply_message) ⇒ Object
Send a reply to the received request message
request: is the message received
reply: is the message to send to the client
Note: A reply is only sent if it is a request message. This means that
the must have a property named Java::OrgHornetqCoreClientImpl::ClientMessageImpl::REPLYTO_HEADER_NAME
containing the name of the address to which the response should be sent
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hornetq/client/server_pattern.rb', line 32 def reply(, ) if .request? # Reply should have same durability as request .durable = .durable? # Send request message id back in reply message for correlation purposes .user_id = .user_id #TODO: Also need to include other attributes such as Expiry # Send to Reply to address supplied by the caller @producer.send(.reply_to_address, ) #puts "Sent reply to #{reply_to.to_s}: #{reply_message.inspect}" end .acknowledge end |
#run(&block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hornetq/client/server_pattern.rb', line 13 def run(&block) while = @consumer.receive(@timeout) # Block should return a message reply object, pass in request # TODO: ensure.. = block.call() # Send a reply? reply(, ) if .request? .acknowledge end end |