XU XUv0.8.8
中文

API

#github.com/xulang-org/packages/nats

import: nats #github.com/xulang-org/packages/nats

counts: 8 fns, 17 methods, 4 types, 0 consts, 0 ifaces

NATS high-performance cloud-native messaging driver for Xu. Features Standard NATS text protocol implementation in 100% pure Xu. High-throughput publish/subscribe (PUB/SUB). Queue Groups (distributed load-balanced worker queues). Request-Reply RPC pattern with dynamic inbox routing. Automatic PING/PONG heartbeat management.

github.com/xulang-org/packages · 0.1.1 · Install and use

open

XuAPI
pub fn open(addr string) Client

Purpose

NATS high-performance cloud-native messaging driver for Xu. Features Standard NATS text protocol implementation in 100% pure Xu. High-throughput publish/subscribe (PUB/SUB). Queue Groups (distributed load-balanced worker queues). Request-Reply RPC pattern with dynamic inbox routing. Automatic PING/PONG heartbeat management. Throws on failure.

Parameters

addr string
address (string)

Returns

Client — a value of this type

open_pool

XuAPI
pub fn open_pool(addr string, max_idle int) Pool

Purpose

Open pool.

Parameters

addr string
address (string)
max_idle int
max_idle (int)

Returns

Pool — a value of this type

struct Client

XuAPI
pub struct Client {
    pub fd int
    pub buf string
    pub addr string
    pub next_sid int
    pub server_info string
}

Purpose

Public struct `Client`.

Parameters

fd int
file descriptor
buf string
buffer
addr string
address
next_sid int
field (int)
server_info string
field (string)

(&mut Client) read_line

XuAPI
pub fn (c &mut Client) read_line() string

Purpose

Method on `&mut Client`: read line. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)

Returns

string — result string

(&mut Client) read_bytes

XuAPI
pub fn (c &mut Client) read_bytes(n int) string

Purpose

Method on `&mut Client`: read through delim (inclusive). Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
n int
count, length, or limit (int)

Returns

string — result string

(&mut Client) write_raw

XuAPI
pub fn (c &mut Client) write_raw(data string) int

Purpose

Method on `&mut Client`: write raw. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
data string
data (string)

Returns

int — a value of this type

connect

XuAPI
pub fn connect(addr string) Client

Purpose

connect; returns Client.

Parameters

addr string
address (string)

Returns

Client — a value of this type

connect_auth

XuAPI
pub fn connect_auth(addr string, user string, pass string) Client

Purpose

Connect auth. Throws on failure.

Parameters

addr string
address (string)
user string
user (string)
pass string
pass (string)

Returns

Client — a value of this type

(&mut Client) ping

XuAPI
pub fn (c &mut Client) ping() bool

Purpose

Call `ping` on `&mut Client`. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)

Returns

bool — true or false

(&mut Client) publish

XuAPI
pub fn (c &mut Client) publish(subject string, data string) int

Purpose

Call `publish` on `&mut Client`. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
subject string
subject (string)
data string
data (string)

Returns

int — a value of this type

(&mut Client) publish_request

XuAPI
pub fn (c &mut Client) publish_request(subject string, reply_to string, data string) int

Purpose

Method on `&mut Client`: publish request. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
subject string
subject (string)
reply_to string
reply_to (string)
data string
data (string)

Returns

int — a value of this type

(&mut Client) subscribe

XuAPI
pub fn (c &mut Client) subscribe(subject string) Subscription

Purpose

Call `subscribe` on `&mut Client`. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
subject string
subject (string)

Returns

Subscription — a value of this type

(&mut Client) queue_subscribe

XuAPI
pub fn (c &mut Client) queue_subscribe(subject string, queue_group string) Subscription

Purpose

Method on `&mut Client`: queue subscribe. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
subject string
subject (string)
queue_group string
queue_group (string)

Returns

Subscription — a value of this type

(&mut Client) unsubscribe

XuAPI
pub fn (c &mut Client) unsubscribe(sub Subscription) int

Purpose

Call `unsubscribe` on `&mut Client`. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
sub Subscription
substring (Subscription)

Returns

int — a value of this type

(&mut Client) next_msg

XuAPI
pub fn (c &mut Client) next_msg() Message

Purpose

Method on `&mut Client`: next msg. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)

Returns

Message — a value of this type

(&mut Client) request

XuAPI
pub fn (c &mut Client) request(subject string, data string) Message

Purpose

Call `request` on `&mut Client`. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
subject string
subject (string)
data string
data (string)

Returns

Message — a value of this type

(&mut Client) close

XuAPI
pub fn (c &mut Client) close() int

Purpose

Method on `&mut Client`: close the resource.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)

Returns

int — a value of this type

struct Message

XuAPI
pub struct Message {
    pub subject string
    pub sid string
    pub reply_to string
    pub data string
}

Purpose

Public struct `Message`.

Parameters

subject string
field (string)
sid string
field (string)
reply_to string
field (string)
data string
data

new_msg

XuAPI
pub fn new_msg(subject string, sid string, reply_to string, data string) Message

Purpose

Construct msg.

Parameters

subject string
subject (string)
sid string
sid (string)
reply_to string
reply_to (string)
data string
data (string)

Returns

Message — a value of this type

struct Pool

XuAPI
pub struct Pool {
    pub url string
    pub auth_user string
    pub auth_pass string
    pub idle chan int
    pub max_idle int
}

Purpose

Connection Pool for NATS messaging system. Uses channel of socket file descriptors for lightweight and high-throughput pooling.

Parameters

url string
field (string)
auth_user string
field (string)
auth_pass string
field (string)
idle chan int
field (channel; type chan int)
max_idle int
field (int)

new_pool

XuAPI
pub fn new_pool(url string, max_idle int) Pool

Purpose

Construct pool.

Parameters

url string
url (string)
max_idle int
max_idle (int)

Returns

Pool — a value of this type

new_pool_auth

XuAPI
pub fn new_pool_auth(url string, user string, pass string, max_idle int) Pool

Purpose

Construct pool auth.

Parameters

url string
url (string)
user string
user (string)
pass string
pass (string)
max_idle int
max_idle (int)

Returns

Pool — a value of this type

(&Pool) get

XuAPI
pub fn (p &Pool) get() Client

Purpose

Call `get` on `&Pool`. Throws on failure.

Parameters

p &Pool
receiver &Pool (borrow)

Returns

Client — a value of this type

(&Pool) put_conn

XuAPI
pub fn (p &Pool) put_conn(fd int)

Purpose

Method on `&Pool`: put connection.

Parameters

p &Pool
receiver &Pool (borrow)
fd int
file descriptor (int)

(&Pool) put

XuAPI
pub fn (p &Pool) put(c Client)

Purpose

Call `put` on `&Pool`.

Parameters

p &Pool
receiver &Pool (borrow)
c Client
byte or character code (Client)

(&Pool) publish

XuAPI
pub fn (p &Pool) publish(subject string, data string) int

Purpose

Call `publish` on `&Pool`. Throws on failure.

Parameters

p &Pool
receiver &Pool (borrow)
subject string
subject (string)
data string
data (string)

Returns

int — a value of this type

(&Pool) close

XuAPI
pub fn (p &Pool) close()

Purpose

Method on `&Pool`: close the resource.

Parameters

p &Pool
receiver &Pool (borrow)

struct Subscription

XuAPI
pub struct Subscription {
    pub sid string
    pub subject string
    pub queue_group string
}

Purpose

Public struct `Subscription`.

Parameters

sid string
field (string)
subject string
field (string)
queue_group string
field (string)

new_sub

XuAPI
pub fn new_sub(sid string, subject string, queue_group string) Subscription

Purpose

Construct sub.

Parameters

sid string
sid (string)
subject string
subject (string)
queue_group string
queue_group (string)

Returns

Subscription — a value of this type