doc.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. Package messages provides information and interaction with the messages through
  3. the OpenStack Messaging(Zaqar) service.
  4. Example to List Messages
  5. listOpts := messages.ListOpts{
  6. Limit: 10,
  7. }
  8. queueName := "my_queue"
  9. pager := messages.List(client, queueName, listOpts)
  10. err = pager.EachPage(func(page pagination.Page) (bool, error) {
  11. allMessages, err := queues.ExtractQueues(page)
  12. if err != nil {
  13. panic(err)
  14. }
  15. for _, message := range allMessages {
  16. fmt.Printf("%+v\n", message)
  17. }
  18. return true, nil
  19. })
  20. Example to Create Messages
  21. queueName = "my_queue"
  22. createOpts := messages.CreateOpts{
  23. Messages: []messages.Messages{
  24. {
  25. TTL: 300,
  26. Delay: 20,
  27. Body: map[string]interface{}{
  28. "event": "BackupStarted",
  29. "backup_id": "c378813c-3f0b-11e2-ad92-7823d2b0f3ce",
  30. },
  31. },
  32. {
  33. Body: map[string]interface{}{
  34. "event": "BackupProgress",
  35. "current_bytes": "0",
  36. "total_bytes": "99614720",
  37. },
  38. },
  39. },
  40. }
  41. resources, err := messages.Create(client, queueName, createOpts).Extract()
  42. if err != nil {
  43. panic(err)
  44. }
  45. Example to Get a set of Messages
  46. queueName := "my_queue"
  47. getMessageOpts := messages.GetMessagesOpts{
  48. IDs: "123456",
  49. }
  50. messagesList, err := messages.GetMessages(client, createdQueueName, getMessageOpts).Extract()
  51. if err != nil {
  52. panic(err)
  53. }
  54. Example to get a singular Message
  55. queueName := "my_queue"
  56. messageID := "123456"
  57. message, err := messages.Get(client, queueName, messageID).Extract()
  58. if err != nil {
  59. panic(err)
  60. }
  61. Example to Delete a set of Messages
  62. queueName := "my_queue"
  63. deleteMessagesOpts := messages.DeleteMessagesOpts{
  64. IDs: []string{"9988776655"},
  65. }
  66. err := messages.DeleteMessages(client, queueName, deleteMessagesOpts).ExtractErr()
  67. if err != nil {
  68. panic(err)
  69. }
  70. Example to Pop a set of Messages
  71. queueName := "my_queue"
  72. popMessagesOpts := messages.PopMessagesOpts{
  73. Pop: 5,
  74. }
  75. resources, err := messages.PopMessages(client, queueName, popMessagesOpts).Extract()
  76. if err != nil {
  77. panic(err)
  78. }
  79. Example to Delete a singular Message
  80. clientID := "3381af92-2b9e-11e3-b191-71861300734d"
  81. queueName := "my_queue"
  82. messageID := "123456"
  83. deleteOpts := messages.DeleteOpts{
  84. ClaimID: "12345",
  85. }
  86. err := messages.Delete(client), queueName, messageID, deleteOpts).ExtractErr()
  87. if err != nil {
  88. panic(err)
  89. }
  90. */
  91. package messages