NSQ.Connection (elixir_nsq v1.2.0)

Sets up a TCP connection to NSQD. Both consumers and producers use this.

Summary

Types

A tuple with a string ID (used to target the connection in NSQ.Connection.Supervisor) and a PID of the connection.

A tuple with a host and a port.

A map, but we can be more specific by asserting some entries that should be set for a connection's state map.

Functions

Returns a specification to start this module under a supervisor.

Calls the command and waits for a response. If a command shouldn't have a response, use cmd_noresponse.

Calls the command but doesn't expect any response. This is important if the NSQ command does not in fact generate a response. If you use cmd and a response is sent, it will live forever in the command queue.

Callback implementation for GenServer.init/1.

Types

Link to this type

connection()

@type connection() :: {String.t(), pid()}

A tuple with a string ID (used to target the connection in NSQ.Connection.Supervisor) and a PID of the connection.

Link to this type

host_with_port()

@type host_with_port() :: {String.t(), integer()}

A tuple with a host and a port.

@type state() :: %{parent: pid(), config: NSQ.Config.t(), nsqd: host_with_port()}

A map, but we can be more specific by asserting some entries that should be set for a connection's state map.

Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

close(conn, conn_state \\ nil)

@spec close(pid(), state()) :: any()
Link to this function

cmd(conn_pid, cmd, timeout \\ 5000)

@spec cmd(pid(), tuple(), integer()) :: {:ok, binary()} | {:error, String.t()}

Calls the command and waits for a response. If a command shouldn't have a response, use cmd_noresponse.

Link to this function

cmd_noresponse(conn, cmd)

@spec cmd_noresponse(pid(), tuple()) :: {:ok, reference()} | {:queued, :nosocket}

Calls the command but doesn't expect any response. This is important if the NSQ command does not in fact generate a response. If you use cmd and a response is sent, it will live forever in the command queue.

@spec get_state(pid()) :: {:ok, state()}
@spec get_state(connection()) :: {:ok, state()}
Link to this function

init(conn_state)

@spec init(state()) :: {:ok, state()}

Callback implementation for GenServer.init/1.

Link to this function

start_link(arg)

@spec start_link(
  {pid() | host_with_port() | NSQ.Config.t() | String.t() | String.t() | pid()}
) ::
  {:ok, pid()}
@spec start_link(
  {pid()
   | host_with_port()
   | NSQ.Config.t()
   | String.t()
   | String.t()
   | pid()
   | list()}
) ::
  {:ok, pid()}