You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.go 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package agent
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/mq"
  4. stgmq "gitlink.org.cn/cloudream/storage-common/pkgs/mq"
  5. )
  6. type Client struct {
  7. rabbitCli *mq.RabbitMQClient
  8. id int64
  9. }
  10. func NewClient(id int64, cfg *stgmq.Config) (*Client, error) {
  11. rabbitCli, err := mq.NewRabbitMQClient(cfg.MakeConnectingURL(), stgmq.MakeAgentQueueName(id), "")
  12. if err != nil {
  13. return nil, err
  14. }
  15. return &Client{
  16. rabbitCli: rabbitCli,
  17. id: id,
  18. }, nil
  19. }
  20. func (c *Client) Close() {
  21. c.rabbitCli.Close()
  22. }
  23. type PoolClient struct {
  24. *Client
  25. owner *Pool
  26. }
  27. func (c *PoolClient) Close() {
  28. c.owner.Release(c)
  29. }
  30. type Pool struct {
  31. mqcfg *stgmq.Config
  32. }
  33. func NewPool(mqcfg *stgmq.Config) *Pool {
  34. return &Pool{
  35. mqcfg: mqcfg,
  36. }
  37. }
  38. func (p *Pool) Acquire(id int64) (*PoolClient, error) {
  39. cli, err := NewClient(id, p.mqcfg)
  40. if err != nil {
  41. return nil, err
  42. }
  43. return &PoolClient{
  44. Client: cli,
  45. owner: p,
  46. }, nil
  47. }
  48. func (p *Pool) Release(cli *PoolClient) {
  49. cli.Client.Close()
  50. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。