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
- type Option
- type Socket
- func (socket *Socket) Attempt(attempt uint8) *Socket
- func (socket *Socket) Close() error
- func (socket *Socket) RawRequest(raw string) ([]string, error)
- func (socket *Socket) RawSubmit(raw string) error
- func (socket *Socket) Request(req message.RequestInterface) (message.ReplyInterface, error)
- func (socket *Socket) SetMessageOperations(messageOps *message.Operations)
- func (socket *Socket) Submit(req message.RequestInterface) error
- func (socket *Socket) Timeout(timeout time.Duration) *Socket
- type Transmit
Constants ¶
const ( DefaultTimeout = time.Second * 100 DefaultAttempt = uint8(5) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
A Socket is the structure that transmits the data to the handlers.
func NewRaw ¶
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 ¶
Attempt update. If the attempt is less than minAttempt, then minAttempt is set
func (*Socket) RawSubmit ¶
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)