Documentation ¶
Overview ¶
Package rpcmq implements an RPC protocol over AMQP.
Client/Server initialization
It is important to note that both clients and servers must be initialized before being used. Also, any configuration parameter (TLSConfig, Parallel, Prefetch, RateLimit and DeliveryMode) should be set up before calling Init().
SSL/TLS
When connecting to the broker via amqps protocol, the TLS configuration can be set up using the TLSConfig parameter present in the Client and Server objects. For more information, see the documentation of the package "crypto/tls".
Index ¶
Constants ¶
const ( // Persistent delivery mode means that messages will be restored to // durable queues during server restart. Persistent = DeliveryMode(amqp.Persistent) // Transient delivery mode means higher throughput but messages will // not be restored on broker restart. Transient = DeliveryMode(amqp.Transient) )
Delivery modes.
Variables ¶
var Log *log.Logger
Log is the logger used to register warnings and info messages. If it is nil, no messages will be logged.
var RetrySleep = 2 * time.Second
RetrySleep is the time between retries if the connection with the broker is lost.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // DeliveryMode allows to configure the delivery mode followed by the // broker. The default mode is Persistent. DeliveryMode DeliveryMode // TLSConfig allows to configure the TLS parameters used to connect to // the broker via amqps. TLSConfig *tls.Config // contains filtered or unexported fields }
A Client is an RPC client, which is used to invoke remote procedures.
func NewClient ¶
NewClient returns a reference to a Client object. The paremeter uri is the network address of the broker and msgsQueue/repliesQueue are the names of queues that will be created to exchange the messages between clients and servers. On the other hand, the parameters exchange and kind determine the type of exchange that will be created. In fanout mode the queue name is ignored, so each queue has its own unique id.
func (*Client) Call ¶
Call invokes the remote procedure specified by the parameter method, being the parameter data the input passed to it. On the other hand, ttl is the time that this task will remain in the queue before being considered dead. The returned id can be used to identify the result corresponding to each invokation. If ttl is 0, the message will not expire.
func (*Client) Init ¶
Init initializes the Client object. It establishes the connection with the broker, creating a channel and the queues that will be used under the hood.
type Function ¶
Function declares the signature of the methods that can be registered by an RPC server. The id parameter contains the uuid of the task being executed.
type Result ¶
A Result contains the data returned by the invoked procedure or an error message, in case that it finished with error. The UUID allows to link the result with the procedure call.
type Server ¶
type Server struct { // DeliveryMode allows to configure the delivery mode followed by the // broker. The default mode is Persistent. DeliveryMode DeliveryMode // Parallel allows to define the number of methods to be run in // parallel. Parallel int // Prefetch allows to define the number of tasks to be "cached". Prefetch int // RateLimit allows to define a limit of deliveries handled per second. RateLimit time.Duration // TLSConfig allows to configure the TLS parameters used to connect to // the broker via amqps. TLSConfig *tls.Config // contains filtered or unexported fields }
A Server is an RPC sever, which is used to register the methods than can be invoked remotely.
func NewServer ¶
NewServer returns a reference to a Server object. The paremeter uri is the network address of the broker and msgsQueue is the name of queue that will be created to exchange the messages between clients and servers. On the other hand, the parameters exchange and kind determine the type of exchange that will be created. In fanout mode the queue name is ignored, so each queue has its own unique id.
func (*Server) Init ¶
Init initializes the Server object. It establishes the connection with the broker, creating a channel and the queues that will be used under the hood.