client

package module
v0.0.0-...-195f29a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2023 License: MPL-2.0 Imports: 7 Imported by: 13

README

Client Lib

The client module is to message exchange with SDS Handlers.

Terminology

Transmit – any message transfers between a client and handler.

Request – is the two transmits with the handler. Sending and receiving. It guarantees a delivery.

Submit – a one transmit with the handler. The client sends the message. Client doesn't wait for a reply.

Target – a handler to which a message is transmitted.

Rules

  • Client has options
    • timeout – option that halts sending after this period of time. Minimum value is 2 milliseconds.
    • attempt – option that repeats the message transmitting after timeout. Minimum one attempt.
  • Client must set correct message parts for asynchronous handlers for internal zeromq socket.

Implementation

Options

The default timeout is 10 Seconds. The default attempt is 5.

The Client.Timeout(time.Duration) method over-writes the timeout. The minimumTimeout is 2 milliseconds.

The Client.Attempt(uint8) method sets the attempt. The minimum attempt is 1.

Type

The type of the client is the opposite of the target type. Thus, when a client is defined, it's defined against the target to whom it will interact with.

The handlers use the clients for creating a managers. To avoid import cycling the clients are using the target's internal socket type.

For intercommunication SDS framework uses Zeromq sockets.

Concurrent

A client is concurrent with its message queue. A client is thread safe.

One client can send multiple messages at the same time.

// Thread 1
client1.Request(message)
// Thread 2
client1.Request(message)

Todo

Optimize the client passing to the handle functions as one child is passed to multiple handle func. We need to avoid passing from parent to the nested child tree.

Test the limits of the clients, and number of the threads. Maybe create a pool of client sockets and get one when it's available?

Todo

Create a library of the pool for available sockets. Then design the handle and client based on that.

Documentation

Overview

Package client defines client zmqSocket that can access to the client service.

Index

Constants

View Source
const (
	DefaultTimeout = time.Second * 100

	DefaultAttempt = uint8(5)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	// contains filtered or unexported fields
}

type Socket

type Socket struct {
	// contains filtered or unexported fields
}

A Socket is the structure that transmits the data to the handlers.

func New

func New(client *config.Client) (*Socket, error)

New client based on the configuration

func NewRaw

func NewRaw(target zmq.Type, url string) (*Socket, error)

NewRaw returns a new client that's connected to the given url. For it to work, the url must be provided with the protocol that is supported by zeromq. Example of valid urls:

  • tcp://localhost:6000

  • inproc://internal_thread

Invalid url:

  • http://example.com/ -- HTTP protocol is not supported

  • ./socket.pid -- File descriptors are not supported

func (*Socket) Attempt

func (socket *Socket) Attempt(attempt uint8) *Socket

Attempt update. If the attempt is less than minAttempt, then minAttempt is set

func (*Socket) Close

func (socket *Socket) Close() error

Close the zmqSocket free the port and resources.

func (*Socket) RawRequest

func (socket *Socket) RawRequest(raw string) ([]string, error)

func (*Socket) RawSubmit

func (socket *Socket) RawSubmit(raw string) error

RawSubmit sends the message to the destination, without waiting for the reply. If the socket has to wait for a reply, otherwise its blocking, then the RawSubmit will receive the message, but omit it.

func (*Socket) Request

func (socket *Socket) Request(req message.RequestInterface) (message.ReplyInterface, error)

Request sends the request message to the zmqSocket. Returns the message.Reply.Parameters in case of success.

Error is returned in other cases.

If the client service returned a failure message, it's converted into an error.

The zmqSocket type should be REQ or PUSH.

func (*Socket) SetMessageOperations

func (socket *Socket) SetMessageOperations(messageOps *message.Operations)

func (*Socket) Submit

func (socket *Socket) Submit(req message.RequestInterface) error

func (*Socket) Timeout

func (socket *Socket) Timeout(timeout time.Duration) *Socket

Timeout update. If the timeout is less than minTimeout, then minTimeout is set

type Transmit

type Transmit struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis
Package config is the utility function that keeps the client-server
Package config is the utility function that keeps the client-server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL