PHP Class Nats\Connection

Show file Open project: repejota/phpnats

Public Methods

Method Description
__construct ( ConnectionOptions $options = null ) Constructor.
close ( ) : void Close will close the connection to the server.
connect ( float $timeout = null ) : void Connect to server.
getSubscriptions ( ) : array Return subscriptions list.
isConnected ( ) : boolean Checks if the client is connected to a server.
ping ( ) : void Sends PING message.
pingsCount ( ) : integer Return the number of pings.
publish ( string $subject, string $payload = null ) : void Publish publishes the data argument to the given subject.
pubsCount ( ) : integer Return the number of messages published.
queueSubscribe ( string $subject, string $queue, Closure $callback ) : string Subscribes to an specific event given a subject and a queue.
reconnect ( ) : void Reconnects to the server.
reconnectsCount ( ) : integer Return the number of reconnects to the server.
request ( string $subject, string $payload, mixed $callback, integer $wait = 1 ) : void Request does a request and executes a callback with the response.
setChunkSize ( integer $chunkSize ) : void
setStreamTimeout ( float $seconds ) : boolean Set Stream Timeout.
streamSocket ( ) : resource
subscribe ( string $subject, Closure $callback ) : string Subscribes to an specific event given a subject.
subscriptionsCount ( ) : integer Return the number of subscriptions available.
unsubscribe ( string $sid ) : void Unsubscribe from a event given a subject.
wait ( integer $quantity ) : resource Waits for messages.

Private Methods

Method Description
getStream ( string $address, float $timeout ) : resource Returns an stream socket to the desired server.
handleMSG ( string $line ) : void Handles MSG command.
handlePING ( ) : void Handles PING command.
receive ( integer $len = null ) : string Receives a message thought the stream.
send ( string $payload ) : void Sends data thought the stream.

Method Details

__construct() public method

Constructor.
public __construct ( ConnectionOptions $options = null )
$options ConnectionOptions Connection options object.

close() public method

Close will close the connection to the server.
public close ( ) : void
return void

connect() public method

Connect to server.
public connect ( float $timeout = null ) : void
$timeout float Number of seconds until the connect() system call should timeout.
return void

getSubscriptions() public method

Return subscriptions list.
public getSubscriptions ( ) : array
return array list of subscription ids

isConnected() public method

Checks if the client is connected to a server.
public isConnected ( ) : boolean
return boolean

ping() public method

Sends PING message.
public ping ( ) : void
return void

pingsCount() public method

Return the number of pings.
public pingsCount ( ) : integer
return integer Number of pings

publish() public method

Publish publishes the data argument to the given subject.
public publish ( string $subject, string $payload = null ) : void
$subject string Message topic.
$payload string Message data.
return void

pubsCount() public method

Return the number of messages published.
public pubsCount ( ) : integer
return integer number of messages published

queueSubscribe() public method

Subscribes to an specific event given a subject and a queue.
public queueSubscribe ( string $subject, string $queue, Closure $callback ) : string
$subject string Message topic.
$queue string Queue name.
$callback Closure Closure to be executed as callback.
return string

reconnect() public method

Reconnects to the server.
public reconnect ( ) : void
return void

reconnectsCount() public method

Return the number of reconnects to the server.
public reconnectsCount ( ) : integer
return integer number of reconnects

request() public method

Request does a request and executes a callback with the response.
public request ( string $subject, string $payload, mixed $callback, integer $wait = 1 ) : void
$subject string Message topic.
$payload string Message data.
$callback mixed Closure to be executed as callback.
$wait integer Number of messages to wait for.
return void

setChunkSize() public method

public setChunkSize ( integer $chunkSize ) : void
$chunkSize integer Set byte chunk len to read when reading from wire.
return void

setStreamTimeout() public method

Set Stream Timeout.
public setStreamTimeout ( float $seconds ) : boolean
$seconds float Before timeout on stream.
return boolean

streamSocket() public method

public streamSocket ( ) : resource
return resource

subscribe() public method

Subscribes to an specific event given a subject.
public subscribe ( string $subject, Closure $callback ) : string
$subject string Message topic.
$callback Closure Closure to be executed as callback.
return string

subscriptionsCount() public method

Return the number of subscriptions available.
public subscriptionsCount ( ) : integer
return integer number of subscription

unsubscribe() public method

Unsubscribe from a event given a subject.
public unsubscribe ( string $sid ) : void
$sid string Subscription ID.
return void

wait() public method

Waits for messages.
public wait ( integer $quantity ) : resource
$quantity integer Number of messages to wait for.
return resource $connection Connection object