Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubwro committed Oct 2, 2023
1 parent 3029f0c commit d08e5d8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 65 deletions.
66 changes: 64 additions & 2 deletions src/NATS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,75 @@ using BufferedStreams

import Base: show, convert, close

include("init.jl")
include("consts.jl")
const NATS_CLIENT_VERSION = "0.1.0"
const NATS_CLIENT_LANG = "julia"
const NATS_HOST = get(ENV, "NATS_HOST", "localhost")
const NATS_PORT = parse(Int, get(ENV, "NATS_PORT", "4222"))
const ERROR_THROTTLING_SECONDS = 5
const DEFAULT_CONNECT_ARGS = (
verbose= false,
pedantic = false,
tls_required = false,
auth_token = nothing,
user = nothing,
pass = nothing,
name = nothing,
lang = NATS_CLIENT_LANG,
version = NATS_CLIENT_VERSION,
protocol = nothing,
echo = nothing,
sig = nothing,
jwt = nothing,
no_responders = true,
headers = true,
nkey = nothing
)
const OUTBOX_SIZE = 10000000
const SOCKET_CONNECT_DELAYS = Base.ExponentialBackOff(n=1000, first_delay=0.5, max_delay=1)
const SUBSCRIPTION_CHANNEL_SIZE = 10000

const MIME_PROTOCOL = MIME"application/nats"
const MIME_PAYLOAD = MIME"application/nats-payload"
const MIME_HEADERS = MIME"application/nats-headers"

include("protocol/protocol.jl")
include("connection/connection.jl")
include("pubsub/pubsub.jl")
include("reqreply/reqreply.jl")

function __init__()
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs
if exc.f == convert && length(argtypes) > 1
# TODO: check if 2nd arg is Msg of Hmsg
print(io, """
To use `$(argtypes[1])` as parameter of subscription handler apropriate conversion from `$(argtypes[2])` must be provided.
```
import Base: convert
function convert(::Type{$(argtypes[1])}, msg::Union{NATS.Msg, NATS.HMsg})
# Implement conversion logic here.
end
```
""")
elseif exc.f == show
print(io, """
Object of type `$(argtypes[3])` cannot be serialized into payload.
```
import Base: show
function Base.show(io::IO, NATS.MIME_PROTOCOL, x::$(argtypes[3]))
# Write content to `io` here.
end
```
""")
end
end
end

export connect, ping, publish, subscribe, unsubscribe, payload, request, reply, header, headers, drain, isdrained

end
31 changes: 0 additions & 31 deletions src/consts.jl

This file was deleted.

32 changes: 0 additions & 32 deletions src/init.jl

This file was deleted.

0 comments on commit d08e5d8

Please sign in to comment.