Method: NATS#publish

Defined in:
lib/nats/client.rb

#publish(subject, msg = EMPTY_MSG, opt_reply = nil, &blk) ⇒ Object

Publish a message to a given subject, with optional reply subject and completion block

Parameters:

  • subject (String)
  • msg (Object, #to_s) (defaults to: EMPTY_MSG)
  • opt_reply (String) (defaults to: nil)
  • blk, (Block)

    closure called when publish has been processed by the server.


505
506
507
508
509
510
511
512
513
514
515
# File 'lib/nats/client.rb', line 505

def publish(subject, msg=EMPTY_MSG, opt_reply=nil, &blk)
  return unless subject and not @drained_subs
  msg = msg.to_s

  # Accounting
  @msgs_sent += 1
  @bytes_sent += msg.bytesize if msg

  send_command("PUB #{subject} #{opt_reply} #{msg.bytesize}#{CR_LF}#{msg}#{CR_LF}")
  queue_server_rt(&blk) if blk
end