A sender that sends events as JSON over UDP
.
Number of seconds to wait between retrying a blocked write
The pipeline to use for turning events into network data
The socket to send events over
Create a new UDP
sender
# File lib/observability/sender/udp.rb, line 36
def initialize( * )
@socket = UDPSocket.new
end
Send the specified event
.
# File lib/observability/sender/udp.rb, line 73
def send_event( data )
until data.empty?
bytes = self.socket.sendmsg_nonblock( data, 0, exception: false )
if bytes == :wait_writable
IO.select( nil, [self.socket], nil )
else
self.log.debug "Sent: %p" % [ data[0, bytes] ]
data[ 0, bytes ] = ''
end
end
end
Serialize each the given events
and return the results.
# File lib/observability/sender/udp.rb, line 67
def serialize_events( events )
return events.map( &SERIALIZE_PIPELINE )
end
Start sending queued events.
# File lib/observability/sender/udp.rb, line 51
def start
self.socket.connect( self.class.host, self.class.port )
super
end
Stop the sender's executor.
# File lib/observability/sender/udp.rb, line 59
def stop
super
self.socket.shutdown( :WR )
end