zmqworker

package
v0.0.0-...-a8b7cda Latest Latest
Warning

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

Go to latest
Published: May 3, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Worker

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

Worker listens for requests and invokes registered goroutines when called.

func New

func New(address string, count int) *Worker

New creates a new worker bound to address that will run at most count functions at a time. If count == 0, it will default to runtime.NumCPU().

func (*Worker) ConvertValue

func (w *Worker) ConvertValue(inputType reflect.Type, input interface{}) (output interface{}, err error)

ConvertValue is a convenience method for converting a received interface{} to a specified type. It may be used e.g. when a JSON request is parsed to a map[string]interface{} and you want to turn it into a struct.

func (*Worker) MakeWorkerFunction

func (w *Worker) MakeWorkerFunction(workerFunction interface{}) gototo.WorkerFunction

func (*Worker) Quit

func (w *Worker) Quit()

Quit stops the worker

func (*Worker) RegisterWorkerFunction

func (w *Worker) RegisterWorkerFunction(name string, workerFunction gototo.WorkerFunction)

RegisterWorkerFunction adds a new worker function that will be invoked when requests are received with the named method.

func (*Worker) Run

func (w *Worker) Run() (err error)

Run runs the worker synchronously

func (*Worker) SetConvertTypeDecoderConfig

func (w *Worker) SetConvertTypeDecoderConfig(config *gototo.DecoderConfig)

SetConvertTypeDecoderConfig sets the mapstructure config to use when decoding. if set, it takes precidence over SetConvertTypeTagName

func (*Worker) SetConvertTypeTagName

func (w *Worker) SetConvertTypeTagName(tagName string)

SetConvertTypeTagName sets the tag name to use to find field information when converting request parameters to custom types. By default this is "json"

func (*Worker) SetLogMetrics

func (w *Worker) SetLogMetrics(logMetrics bool)

SetLogMetrics enables or disables metric logging

func (*Worker) SetMarshalFunction

func (w *Worker) SetMarshalFunction(marshal gototo.MarshalFunction)

func (*Worker) SetUnmarshalFunction

func (w *Worker) SetUnmarshalFunction(unmarshal gototo.UnmarshalFunction)

func (*Worker) Start

func (w *Worker) Start() (err error)

Start runs the worker in a new go routine

func (*Worker) Stop

func (w *Worker) Stop()

Stop stops the worker and waits until it is completely shutdown

func (*Worker) Wait

func (w *Worker) Wait()

Wait waits for the worker to completely shutdown

type WorkerConnection

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

WorkerConnection is used to make RPCs to remote workers. If multiple workers are connected, requests will be round-robin load balanced between them.

func NewConnection

func NewConnection(endpoints ...string) *WorkerConnection

NewConnection creates a new WorkerConnection and optionally prepares it to connect to one or more endpoints.

func (*WorkerConnection) Call

func (c *WorkerConnection) Call(method string, parameters interface{}) (response interface{}, err error)

Call calls a method on a worker and blocks until it receives a response. Use RegisterResponseType to automatically convert responses into the correct type. Use RegisterDefaultOptions to set a RequestOptions to use with a given method.

func (*WorkerConnection) CallWithOptions

func (c *WorkerConnection) CallWithOptions(method string, parameters interface{}, options *gototo.RequestOptions) (response interface{}, err error)

CallWithOptions calls a method on a worker and blocks until it receives a response. Use RegisterResponseType to automatically convert responses into the correct type. This method is like Call but allows the caller to specify RequestOptions.

func (*WorkerConnection) Connect

func (c *WorkerConnection) Connect(endpoint string) error

Connect connects to a new endpoint

func (*WorkerConnection) ConvertValue

func (c *WorkerConnection) ConvertValue(inputType reflect.Type, input interface{}) (output interface{}, err error)

ConvertValue is a convenience method for converting a received interface{} to a specified type. It may be used e.g. when a JSON response is parsed to a map[string]interface{} and you want to turn it into a struct.

func (*WorkerConnection) Disconnect

func (c *WorkerConnection) Disconnect(endpoint string) error

Disconnect disconnects from an existing endpoint

func (*WorkerConnection) GetEndpoints

func (c *WorkerConnection) GetEndpoints() (endpoints []string)

GetEndpoints returns all endpoints that the WorkerConnection is connected to.

func (*WorkerConnection) PendingRequestCount

func (c *WorkerConnection) PendingRequestCount() int

PendingRequestCount returns the number of requests currently awaiting responses

func (*WorkerConnection) RegisterDefaultOptions

func (c *WorkerConnection) RegisterDefaultOptions(method string, options *gototo.RequestOptions)

RegisterDefaultOptions sets the options that will be used whenever Call is used for a given method. This does not affect CallWithOptions.

func (*WorkerConnection) RegisterResponseType

func (c *WorkerConnection) RegisterResponseType(method string, i interface{}, wrappedInResponse bool)

RegisterResponseType ensures that responses from calls to the named method are converted to the proper type before being returned to the caller. If wrappedInResponse is true then the response will be parsed into a Response struct before reading the result from Response.Result and any error from the Response will be returned as an *ResponseError from the ConverterFunction.

func (*WorkerConnection) SetConvertTypeDecoderConfig

func (c *WorkerConnection) SetConvertTypeDecoderConfig(config *gototo.DecoderConfig)

SetConvertTypeDecoderConfig sets the config to use when decoding. if set, it takes precidence over SetConvertTypeTagName

func (*WorkerConnection) SetConvertTypeTagName

func (c *WorkerConnection) SetConvertTypeTagName(tagName string)

SetConvertTypeTagName sets the tag name to use to find field information when converting request parameters to custom types. By default this is "json"

func (*WorkerConnection) SetEndpoints

func (c *WorkerConnection) SetEndpoints(endpoint ...string) error

SetEndpoints connects to any new endpoints contained in the supplied list and disconnects from any current endpoints not in the list.

func (*WorkerConnection) SetMarshalFunction

func (c *WorkerConnection) SetMarshalFunction(marshal gototo.ClientMarshalFunction)

SetMarshalFunction sets the function used to marshal requests for transmission.

func (*WorkerConnection) SetUnmarshalFunction

func (c *WorkerConnection) SetUnmarshalFunction(unmarshal gototo.ClientUnmarshalFunction)

SetUnmarshalFunction sets the function used to unmarshal responses.

func (*WorkerConnection) Start

func (c *WorkerConnection) Start() (err error)

func (*WorkerConnection) Stop

func (c *WorkerConnection) Stop()

Stop stops the worker connection and waits until it is completely shutdown

Jump to

Keyboard shortcuts

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