Class: CrystalMQ::Producer

Inherits:
Object
  • Object
show all
Defined in:
lib/crystalmq.rb

Defined Under Namespace

Classes: ProducerPayload

Instance Method Summary collapse

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_socketObject



101
102
103
104
# File 'lib/crystalmq.rb', line 101

def connect_socket
  @socket = TCPSocket.new(@host, 1234)
  @socket.sync = true
end

#terminateObject



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(message)
  @socket.write(ProducerPayload.new(@topic, message).to_msgpack)
rescue StandardError
  connect_socket
  retry
end