Class: CrystalMQ::Producer
- Inherits:
-
Object
- Object
- CrystalMQ::Producer
- Defined in:
- lib/crystalmq.rb
Defined Under Namespace
Classes: ProducerPayload
Instance Method Summary collapse
- #connect_socket ⇒ Object
-
#initialize(host, topic) ⇒ Producer
constructor
A new instance of Producer.
- #terminate ⇒ Object
- #write(message) ⇒ Object
Constructor Details
#initialize(host, topic) ⇒ Producer
Returns a new instance of Producer.
92 93 94 95 96 97 98 99 |
# File 'lib/crystalmq.rb', line 92 def initialize(host, topic) @host = host @topic = topic connect_socket rescue StandardError connect_socket retry end |
Instance Method Details
#connect_socket ⇒ Object
101 102 103 104 |
# File 'lib/crystalmq.rb', line 101 def connect_socket @socket = TCPSocket.new(@host, 1234) @socket.sync = true end |
#terminate ⇒ Object
113 114 115 |
# File 'lib/crystalmq.rb', line 113 def terminate @socket.close end |
#write(message) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/crystalmq.rb', line 106 def write() @socket.write(ProducerPayload.new(@topic, ).to_msgpack) rescue StandardError connect_socket retry end |