Documentation ¶
Index ¶
- Constants
- type Client
- func (c *Client) AddFriendship(ctx context.Context, p1, p2 int64) error
- func (c *Client) AddPerson(ctx context.Context, name string) (int64, error)
- func (c *Client) Close() error
- func (c *Client) GetAll(ctx context.Context) ([]internal.Friendship, error)
- func (c *Client) GetDepth(ctx context.Context, id1, id2 int64) (int, error)
- func (c *Client) GetFriendship(ctx context.Context, id int64) (internal.Friendship, error)
- func (c *Client) GetPerson(ctx context.Context, id int64) (*internal.Person, error)
- func (c *Client) RemovePerson(ctx context.Context, id int64) error
- func (c *Client) StartListenAttached(ctx context.Context, last bool) (<-chan *Message, error)
- func (c *Client) StartListenDetached(ctx context.Context) (<-chan *Message, error)
- type ClientConfig
- type ConsumerConfig
- type Message
Constants ¶
const ( DefaultTimeout = time.Second * 5 DefaultURL = "http://localhost:8080" )
const DefaultBrokerURL = "amqp://guest:guest@localhost:5672"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the interface between the user and the relationer server.
func New ¶
func New(conf *ClientConfig) *Client
New creates a new relationer client with the provided config.
To use the default config run
client.New(nil)
func (*Client) AddFriendship ¶
AddFriendship creates a new friendship (one-way) between p1 and p2.
func (*Client) Close ¶
Close tears any possible amqp connections and consumers taking with it all the registered channels (recievers).
func (*Client) GetFriendship ¶
GetFriendship gets the friendships (relationships) the person with id: id has.
func (*Client) RemovePerson ¶
RemovePerson removes person with id: id.
func (*Client) StartListenAttached ¶
StartListenAttached will attach to an existing connection if possible, only scenario where it will create a new connection is when the connection pool is empty.
Canceling the context will end up in one of these cases:
1) When a new connection is created by StartListenAttached cancelling the context passed to the function call will destroy the connection only when there are no more recievers attached to it.
2) When the reciever is attached to an existing connection cancelling the context will just remove the reciever without killing the connection, the only way that connection can be killed is if the root reciever (reciever created with StartListenDetached) is killed or an error happens in the connection.
Grouping - group multiple recievers to one root reciever (controlled):
call (*Client).StartListenDetached(ctx) followed by synchronised (*Client).StartListenAttached(ctx, true) , these followed calls will skip the round-robin like load balancer algorithm and attach all the recievers to the last consumer (created by (*Client).StartListenDetached(ctx)) giving you grouped consumer.
Attention: A recv attached to a connection can be closed at any time! You can bundle up recievers with syncronised calls to the client making one root reciever and many dependant recievers.
func (*Client) StartListenDetached ¶
StartListenDetached will start a separate connection to the message-broker (rabbitmq) and subscribe the recieving channel to it.
canceling the context provided to this function call will destroy the whole rabbitmq connection taking away with it the initial subscribed channel and any other attached channels with
StartListenAttached()
this way of listening to the messages is recommanded as separate connections for each recieving channel will make recievers more safe and independant.
type ClientConfig ¶
type ClientConfig struct { // The relationer server URL - default: http://localhost:8080 URL string // The http client used by the REST client - defualt: http client with 5 second timeout Client *http.Client // The consumer factory configuration used by the client to generate all consumers. ConsumerConfig *ConsumerConfig }
ClientConfig represents the configurable fields.
type ConsumerConfig ¶
type ConsumerConfig struct { // The URL of the broker (rabbitmq) - default: amqp://guest:guest@localhost:5672 URL string // Binding keys to the exchange - defualt: # (all) BindingKeys []string // Used as timeout to check the health of current connection. (reconnect if needed or close conn) Pulse time.Duration }
ConsumerConfig is used for the creation of consumers, each client has one consumer config which is used to create all consumers via the: StartListenDetached and StartListenAttached methods.