Skip to content

jakubwro/NATS.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NATS client for Julia.

codecov

Description

NATS client for Julia.

This client is feature complete in terms of Core NATS protocol and most of JetStream API.

  • All NATS authentication methods
  • TLS support
  • Zero copy protocol parser

Performance is matching reference go implementation.

Compatibility

Julia

It was tested in julia 1.9 and 1.10

NATS

It was tested on NATS 2.10.

Quick examples

Start nats-server:

docker run -p 4222:4222 nats:latest

Publish subscribe

julia> using NATS

julia> nc = NATS.connect()
NATS.Connection(my_cluster cluster, CONNECTED, 0 subs, 0 unsubs)

julia> sub = subscribe(nc, "test_subject") do msg
                 @show payload(msg)
             end;

julia> publish(nc, "test_subject", "Hello.")

payload(msg) = "Hello."

julia> drain(nc, sub)

Request reply

Connecting to external service

> nats reply help.please 'OK, I CAN HELP!!!'

20:35:19 Listening on "help.please" in group "NATS-RPLY-22"
julia> using NATS

julia> nc = NATS.connect()
NATS.Connection(my_cluster cluster, CONNECTED, 0 subs, 0 unsubs)

julia> rep = @time NATS.request(nc, "help.please");
  0.003854 seconds (177 allocations: 76.359 KiB)

julia> payload(rep)
"OK, I CAN HELP!!!"

Reply to requests from julia

julia> using NATS

julia> nc = NATS.connect()
NATS.Connection(my_cluster cluster, CONNECTED, 0 subs, 0 unsubs)

julia> sub = reply(nc, "some.service") do msg
                 "This is response"
             end

julia> rep = @time NATS.request(nc, "some.service");
  0.002897 seconds (231 allocations: 143.078 KiB)

julia> payload(rep)
"This is response"

julia> drain(nc, sub)