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 867 B

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.RabbitMQTransport
  8. id int64
  9. }
  10. func NewClient(id int64, cfg *stgmq.Config) (*Client, error) {
  11. rabbitCli, err := mq.NewRabbitMQTransport(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 Pool interface {
  24. Acquire(id int64) (*Client, error)
  25. Release(cli *Client)
  26. }
  27. type pool struct {
  28. mqcfg *stgmq.Config
  29. }
  30. func NewPool(mqcfg *stgmq.Config) Pool {
  31. return &pool{
  32. mqcfg: mqcfg,
  33. }
  34. }
  35. func (p *pool) Acquire(id int64) (*Client, error) {
  36. return NewClient(id, p.mqcfg)
  37. }
  38. func (p *pool) Release(cli *Client) {
  39. cli.Close()
  40. }

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