Develop #3

Merged
trunglt251292 merged 3 commits from develop into master 2022-04-19 02:58:27 +00:00
3 changed files with 12 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package natsio package natsio
import "time"
// Config ... // Config ...
type Config struct { type Config struct {
// Connect url // Connect url
@ -13,6 +15,9 @@ type Config struct {
// TLS config // TLS config
TLS *TLSConfig TLS *TLSConfig
// RequestTimeout
RequestTimeout time.Duration
} }
// TLSConfig ... // TLSConfig ...

View File

@ -3,7 +3,6 @@ package natsio
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/logrusorgru/aurora" "github.com/logrusorgru/aurora"
"github.com/nats-io/nats.go" "github.com/nats-io/nats.go"
) )
@ -11,6 +10,7 @@ import (
// Server ... // Server ...
type Server struct { type Server struct {
instance *nats.Conn instance *nats.Conn
Config Config
} }
// JetStream ... // JetStream ...
@ -53,6 +53,7 @@ func Connect(cfg Config) error {
// Set client // Set client
natsServer.instance = nc natsServer.instance = nc
natsServer.Config = cfg
// Create jet stream context // Create jet stream context
js, err := nc.JetStream(nats.PublishAsyncMaxPending(256)) js, err := nc.JetStream(nats.PublishAsyncMaxPending(256))

View File

@ -13,7 +13,11 @@ const requestTimeout = 10 * time.Second
// Request ... // Request ...
func (sv Server) Request(subject string, payload []byte) (*nats.Msg, error) { func (sv Server) Request(subject string, payload []byte) (*nats.Msg, error) {
return sv.instance.Request(subject, payload, requestTimeout) timeout := requestTimeout
if sv.Config.RequestTimeout > 0 {
timeout = sv.Config.RequestTimeout
}
return sv.instance.Request(subject, payload, timeout)
} }
// Reply ... // Reply ...