redriver.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. package redriver
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "io"
  8. "log"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "github.com/aws/aws-sdk-go-v2/aws"
  13. "github.com/aws/aws-sdk-go-v2/service/sqs"
  14. "github.com/aws/aws-sdk-go-v2/service/sqs/types"
  15. "github.com/fgm/izidic"
  16. "code.osinet.fr/fgm/sqs_demo/back/services"
  17. )
  18. const (
  19. // BatchMax defines the maximum number of message usable in a batch operation, including redriving.
  20. BatchMax = 10
  21. // MessageSystemAttributeNameDeadLetterQueueSourceArn is an undocumented
  22. // types.Message attribute, used by the SQS console to support redrive.
  23. MessageSystemAttributeNameDeadLetterQueueSourceArn types.MessageSystemAttributeName = "DeadLetterQueueSourceArn"
  24. )
  25. var (
  26. ErrBatchTooBig = fmt.Errorf("operation requested on more than %d items", BatchMax)
  27. )
  28. type ItemsKeys struct {
  29. MessageID string
  30. ReceiptHandle string
  31. }
  32. type QueueRedrivePolicies struct {
  33. *QueueInfoAttributesRedrivePolicy
  34. *QueueInfoAttributesRedriveAllowPolicy
  35. }
  36. // Redriver is a redrive-oriented facade in front of the sqs.Client API.
  37. type Redriver interface {
  38. ListQueues(ctx context.Context, prefix string) (QueueUrls []string, err error)
  39. GetRedrivePolicies(ctx context.Context, qName string) (*QueueRedrivePolicies, error)
  40. GetQueueInfo(ctx context.Context, qName string) (*QueueInfo, error)
  41. GetQueueItems(ctx context.Context, qName string) ([]Message, error)
  42. DeleteItems(ctx context.Context, qName string, itemsIDs []ItemsKeys) error
  43. Purge(ctx context.Context, qName string) error
  44. RedriveItems(ctx context.Context, qName string, messages []Message) error
  45. }
  46. type redriver struct {
  47. VTO int32
  48. Wait int32
  49. io.Writer
  50. *sqs.Client
  51. }
  52. func (r *redriver) ListQueues(ctx context.Context, prefix string) (QueueUrls []string, err error) {
  53. // TODO implement pagination for the day we need more than 1000 queues to be reported.
  54. lqi := &sqs.ListQueuesInput{
  55. MaxResults: aws.Int32(1000),
  56. NextToken: nil,
  57. QueueNamePrefix: aws.String(prefix),
  58. }
  59. lqo, err := r.Client.ListQueues(ctx, lqi)
  60. if err != nil {
  61. return nil, fmt.Errorf("listing queues: %w", err)
  62. }
  63. return lqo.QueueUrls, nil
  64. }
  65. func (*redriver) parseQueueInfoRedrivePolicies(qName string, qao sqs.GetQueueAttributesOutput) (*QueueRedrivePolicies, error) {
  66. var qrp QueueRedrivePolicies
  67. srp := qao.Attributes[string(types.QueueAttributeNameRedrivePolicy)]
  68. if srp != "" {
  69. rp := QueueInfoAttributesRedrivePolicy{}
  70. if err := json.Unmarshal([]byte(srp), &rp); err != nil {
  71. return nil, fmt.Errorf(
  72. "failed parsing redrive policy for queue %q %w", qName, err)
  73. }
  74. if _, err := URLFromARNString(rp.DeadLetterTargetARN); err != nil {
  75. return nil, fmt.Errorf(
  76. "failed converting queue %q ARN to URL: %w", qName, err)
  77. }
  78. qrp.QueueInfoAttributesRedrivePolicy = &rp
  79. }
  80. srap := qao.Attributes[string(types.QueueAttributeNameRedriveAllowPolicy)]
  81. if srap != "" {
  82. rap := QueueInfoAttributesRedriveAllowPolicy{}
  83. if err := json.Unmarshal([]byte(srap), &rap); err != nil {
  84. return nil, fmt.Errorf(
  85. "failed parsing redrive allow policy for queue %q %w", qName, err)
  86. }
  87. for _, src := range rap.SourceQueueARNs {
  88. if _, err := URLFromARNString(src); err != nil {
  89. return nil, fmt.Errorf(
  90. "failed converting queue %q ARN to URL: %w", qName, err)
  91. }
  92. }
  93. qrp.QueueInfoAttributesRedriveAllowPolicy = &rap
  94. }
  95. return &qrp, nil
  96. }
  97. func (r *redriver) GetRedrivePolicies(ctx context.Context, qName string) (policies *QueueRedrivePolicies, err error) {
  98. qui := &sqs.GetQueueUrlInput{QueueName: &qName}
  99. qu, err := r.GetQueueUrl(ctx, qui)
  100. if err != nil {
  101. return nil, fmt.Errorf("failed getting URL for queue %q: %w", qName, err)
  102. }
  103. qai := &sqs.GetQueueAttributesInput{
  104. QueueUrl: qu.QueueUrl,
  105. AttributeNames: []types.QueueAttributeName{
  106. types.QueueAttributeNameRedrivePolicy,
  107. types.QueueAttributeNameRedriveAllowPolicy,
  108. },
  109. }
  110. qao, err := r.Client.GetQueueAttributes(ctx, qai)
  111. if err != nil {
  112. return nil, fmt.Errorf("failed getting DLQ policies for queue %q: %w", qName, err)
  113. }
  114. if qao == nil {
  115. return nil, fmt.Errorf("redrive policy info for queue %q is empty", qName)
  116. }
  117. qrp, err := r.parseQueueInfoRedrivePolicies(qName, *qao)
  118. if err != nil {
  119. return nil, fmt.Errorf("failed parsing redrive policy for queue %q: %w", qName, err)
  120. }
  121. if qrp == nil {
  122. return nil, nil // Queue has no DLQ: this is not an error
  123. }
  124. return qrp, nil
  125. }
  126. func (r *redriver) GetQueueInfo(ctx context.Context, qName string) (*QueueInfo, error) {
  127. qui := &sqs.GetQueueUrlInput{QueueName: &qName}
  128. qu, err := r.GetQueueUrl(ctx, qui)
  129. if err != nil {
  130. return nil, fmt.Errorf("failed getting URL for queue %q: %w", qName, err)
  131. }
  132. if qu.QueueUrl == nil {
  133. return nil, fmt.Errorf("URL for queue %q is empty", qName)
  134. }
  135. qai := &sqs.GetQueueAttributesInput{
  136. QueueUrl: qu.QueueUrl,
  137. AttributeNames: []types.QueueAttributeName{types.QueueAttributeNameAll},
  138. }
  139. qao, err := r.Client.GetQueueAttributes(ctx, qai)
  140. if err != nil {
  141. return nil, fmt.Errorf("failed getting all attributes for queue %q: %w", qName, err)
  142. }
  143. if qao == nil {
  144. return nil, fmt.Errorf("no attributes returned for queue %q", qName)
  145. }
  146. qi, err := r.parseQueueInfoAttributes(qName, qu, qao)
  147. if err != nil {
  148. return nil, err
  149. }
  150. return qi, err
  151. }
  152. func (r *redriver) parseQueueInfoAttributes(qName string, qu *sqs.GetQueueUrlOutput, qao *sqs.GetQueueAttributesOutput) (*QueueInfo, error) {
  153. var (
  154. qi *QueueInfo
  155. errCount int
  156. anom, anomd, anomnv int64
  157. created, changed int64 // timestamps
  158. delay, max, retention, vto, wait int64
  159. )
  160. u := *qu.QueueUrl
  161. a, err := ARNFromURL(u)
  162. if err != nil {
  163. return nil, fmt.Errorf("ARN for queue %q cannot be parsed from URL %q: %w", qName, u, err)
  164. }
  165. for _, field := range []struct {
  166. name types.QueueAttributeName
  167. value *int64
  168. sDef string
  169. def int64
  170. }{
  171. {types.QueueAttributeNameApproximateNumberOfMessages, &anom, "-1", -1},
  172. {types.QueueAttributeNameApproximateNumberOfMessagesDelayed, &anomd, "-1", -1},
  173. {types.QueueAttributeNameApproximateNumberOfMessagesNotVisible, &anomnv, "-1", -1},
  174. {types.QueueAttributeNameCreatedTimestamp, &created, "0", 0},
  175. {types.QueueAttributeNameDelaySeconds, &delay, "-1", -1},
  176. {types.QueueAttributeNameLastModifiedTimestamp, &changed, "0", 0},
  177. {types.QueueAttributeNameMaximumMessageSize, &max, "262144", 1 << (8 + 10)}, // 256ko
  178. {types.QueueAttributeNameMessageRetentionPeriod, &max, "1209600", 14 * 24 * 60 * 60}, // 2 weeks
  179. {types.QueueAttributeNameReceiveMessageWaitTimeSeconds, &wait, "0", 0}, // short polling
  180. {types.QueueAttributeNameVisibilityTimeout, &vto, "0", 0}, // short polling
  181. } {
  182. s, ok := qao.Attributes[string(field.name)]
  183. if !ok {
  184. errCount++
  185. s = field.sDef
  186. }
  187. n, err := strconv.Atoi(s)
  188. if err != nil {
  189. errCount++
  190. }
  191. *field.value = int64(n)
  192. }
  193. qrp, err := r.parseQueueInfoRedrivePolicies(qName, *qao)
  194. if err != nil {
  195. return nil, fmt.Errorf("failed parsing redrive policy for queue %q: %w", qName, err)
  196. }
  197. qi = &QueueInfo{
  198. Name: qName,
  199. URL: u,
  200. Attributes: &QueueInfoAttributes{
  201. ApproximateNumberOfMessages: anom,
  202. ApproximateNumberOfMessagesDelayed: anomd,
  203. ApproximateNumberOfMessagesNotVisible: anomnv,
  204. CreatedTimestamp: created,
  205. DelaySeconds: delay,
  206. LastModifiedTimestamp: changed,
  207. MaximumMessageSize: max,
  208. MessageRetentionPeriod: retention,
  209. QueueARN: a.String(),
  210. ReceiveMessageWaitTimeSeconds: wait,
  211. VisibilityTimeout: vto,
  212. RedrivePolicy: qrp.QueueInfoAttributesRedrivePolicy,
  213. RedriveAllowPolicy: qrp.QueueInfoAttributesRedriveAllowPolicy,
  214. },
  215. }
  216. return qi, nil
  217. }
  218. func (*redriver) parseReceivedAttributes(msg types.Message) (*SystemMessageAttributes, error) {
  219. var (
  220. afrt, arc, sent int64
  221. errCount int
  222. err error
  223. )
  224. for _, field := range []struct {
  225. name types.MessageSystemAttributeName
  226. value *int64
  227. sDef string
  228. def int64
  229. }{
  230. {types.MessageSystemAttributeNameApproximateFirstReceiveTimestamp, &afrt, "0", 0},
  231. {types.MessageSystemAttributeNameApproximateReceiveCount, &arc, "0", 0},
  232. {types.MessageSystemAttributeNameSentTimestamp, &sent, "0", 0},
  233. } {
  234. s, ok := msg.Attributes[string(field.name)]
  235. if !ok {
  236. errCount++
  237. s = field.sDef
  238. }
  239. n, err := strconv.Atoi(s)
  240. if err != nil {
  241. errCount++
  242. }
  243. *field.value = int64(n)
  244. }
  245. ma := SystemMessageAttributes{
  246. ApproximateFirstReceiveTimestamp: afrt,
  247. ApproximateReceiveCount: arc,
  248. DeadLetterQueueSourceARN: msg.Attributes[string(MessageSystemAttributeNameDeadLetterQueueSourceArn)],
  249. SenderId: msg.Attributes[string(types.MessageSystemAttributeNameSenderId)],
  250. SentTimestamp: sent,
  251. }
  252. if errCount > 0 {
  253. err = fmt.Errorf("encounted %d errors parsing system message attributes", errCount)
  254. return nil, err
  255. }
  256. return &ma, nil
  257. }
  258. func (r *redriver) GetQueueItems(ctx context.Context, qName string) ([]Message, error) {
  259. qui := &sqs.GetQueueUrlInput{QueueName: &qName}
  260. qu, err := r.GetQueueUrl(ctx, qui)
  261. if err != nil {
  262. return nil, fmt.Errorf("failed getting URL for queue %q: %w", qName, err)
  263. }
  264. if qu.QueueUrl == nil {
  265. return nil, fmt.Errorf("URL for queue %q is empty", qName)
  266. }
  267. rmi := sqs.ReceiveMessageInput{
  268. QueueUrl: qu.QueueUrl,
  269. AttributeNames: []types.QueueAttributeName{types.QueueAttributeNameAll},
  270. MaxNumberOfMessages: 10,
  271. MessageAttributeNames: []string{".*"},
  272. VisibilityTimeout: 0,
  273. WaitTimeSeconds: r.Wait,
  274. }
  275. t0 := time.Now()
  276. rmo, err := r.Client.ReceiveMessage(ctx, &rmi)
  277. d := time.Since(t0)
  278. if err != nil {
  279. return nil, fmt.Errorf("after %v, failed receiving messages for queue %q: %w",
  280. d, qName, err)
  281. }
  282. ms := make([]Message, 0, len(rmo.Messages))
  283. for _, m := range rmo.Messages {
  284. ma, err := r.parseReceivedAttributes(m)
  285. if err != nil {
  286. return nil, err
  287. }
  288. for _, field := range []struct {
  289. name string
  290. value any
  291. }{
  292. {"body", m.Body},
  293. {"md5 of body", m.MD5OfBody},
  294. {"md5 of message attributes", m.MD5OfMessageAttributes},
  295. {"message ID", m.MessageId},
  296. {"receipt handle", m.ReceiptHandle},
  297. } {
  298. if field.value == nil {
  299. return nil, fmt.Errorf("missing field %s on message", field.name)
  300. }
  301. }
  302. j, err := JSONableFromMessageAttributeValues(m.MessageAttributes)
  303. if err != nil {
  304. return nil, fmt.Errorf("failed decoding message boby: %w", err)
  305. }
  306. m2 := Message{
  307. Attributes: ma,
  308. MessageAttributes: j,
  309. }
  310. for _, pair := range []struct{ dest, src *string }{
  311. {&m2.Body, m.Body},
  312. {&m2.Md5OfBody, m.MD5OfBody},
  313. {&m2.Md5OfMessageAttributes, m.MD5OfMessageAttributes},
  314. {&m2.MessageId, m.MessageId},
  315. {&m2.ReceiptHandle, m.ReceiptHandle},
  316. } {
  317. if pair.src != nil {
  318. *pair.dest = *pair.src
  319. }
  320. }
  321. ms = append(ms, m2)
  322. }
  323. return ms, err
  324. }
  325. func (r *redriver) DeleteItems(ctx context.Context, qName string, keys []ItemsKeys) error {
  326. qui := &sqs.GetQueueUrlInput{QueueName: &qName}
  327. qu, err := r.GetQueueUrl(ctx, qui)
  328. if err != nil {
  329. return fmt.Errorf("failed getting URL for queue %q: %w", qName, err)
  330. }
  331. entries := make([]types.DeleteMessageBatchRequestEntry, len(keys))
  332. for i := 0; i < len(keys); i++ {
  333. entries[i] = types.DeleteMessageBatchRequestEntry{
  334. Id: aws.String(keys[i].MessageID),
  335. ReceiptHandle: aws.String(keys[i].ReceiptHandle),
  336. }
  337. }
  338. dmi := sqs.DeleteMessageBatchInput{
  339. Entries: entries,
  340. QueueUrl: qu.QueueUrl,
  341. }
  342. dmo, err := r.DeleteMessageBatch(ctx, &dmi)
  343. if err != nil {
  344. return fmt.Errorf("failed deleting %d items from queue %q: %v",
  345. len(keys), qName, err)
  346. }
  347. if len(dmo.Failed) > 0 {
  348. errs := make([]string, len(dmo.Failed))
  349. for i, bree := range dmo.Failed {
  350. source := "aws"
  351. if bree.SenderFault {
  352. source = "redriver"
  353. }
  354. errs[i] = fmt.Sprintf("ID: %s / Failure: %s = %q / Source: %s",
  355. *bree.Id, *bree.Message, *bree.Code, source)
  356. }
  357. return fmt.Errorf("failed deleting %d items out of %d from queue %q: %s",
  358. len(dmo.Failed), len(keys), qName, strings.Join(errs, "\n"))
  359. }
  360. log.Println(dmo)
  361. return nil
  362. }
  363. func (r *redriver) Purge(ctx context.Context, qName string) error {
  364. qui := &sqs.GetQueueUrlInput{QueueName: &qName}
  365. qu, err := r.GetQueueUrl(ctx, qui)
  366. if err != nil {
  367. return fmt.Errorf("failed getting URL for queue %q: %w", qName, err)
  368. }
  369. pqi := sqs.PurgeQueueInput{QueueUrl: qu.QueueUrl}
  370. _, err = r.PurgeQueue(ctx, &pqi)
  371. if err != nil {
  372. return fmt.Errorf("failed purging queue %q: %w",
  373. qName, err)
  374. }
  375. return nil
  376. }
  377. // RedriveItems redrives the selected message back to their respective source queue,
  378. // removing them from the DLQ once they have been sent.
  379. //
  380. // Since a queue can act as a DLQ for more than one source queue, the messages
  381. // sends are grouped by source queue.
  382. func (r *redriver) RedriveItems(ctx context.Context, dlqName string, messages []Message) error {
  383. sqURLs := make(map[string][]Message, 1) // In most cases, only a single queue will be used.
  384. for _, message := range messages {
  385. sARN := message.Attributes.DeadLetterQueueSourceARN
  386. sURL, err := URLFromARNString(sARN)
  387. if err != nil {
  388. return fmt.Errorf("failed resolving source ARN %q to URL: %v", sARN, err)
  389. }
  390. sqURLs[sURL] = append(sqURLs[sURL], message)
  391. }
  392. for qURL, messages := range sqURLs {
  393. if err := r.redriveQueueMessages(ctx, dlqName, qURL, messages); err != nil {
  394. return err
  395. }
  396. }
  397. return nil
  398. }
  399. // redriveQueueMessages handles message redriving for messages in a single queue.
  400. func (r *redriver) redriveQueueMessages(ctx context.Context, dlqName string, qURL string, messages []Message) error {
  401. if len(messages) > BatchMax {
  402. return ErrBatchTooBig
  403. }
  404. qui := &sqs.GetQueueUrlInput{QueueName: &dlqName}
  405. dlqURL, err := r.GetQueueUrl(ctx, qui)
  406. if err != nil || dlqURL == nil {
  407. return fmt.Errorf("failed getting URL for queue %q: %w", dlqName, err)
  408. }
  409. // Hide messages to prevent other consumers from seeing them and generating duplicates.
  410. fatal, nontafal := r.hideQueueMessages(ctx, "", *dlqURL.QueueUrl, messages)
  411. if fatal != nil {
  412. return fmt.Errorf("failed hiding messages during redrive towards queue %q: %w", qURL, fatal)
  413. }
  414. if nontafal != nil {
  415. log.Printf("Redrive nonfatal error hiding messages on queue %q: %v", dlqName, nontafal)
  416. }
  417. // Send the messages back to their source queue.
  418. if err := r.resendQueueMessages(ctx, qURL, messages); err != nil {
  419. return fmt.Errorf("failed sending messages back to queue %q: %w", qURL, err)
  420. }
  421. // Delete them from the DLQ.
  422. keys := make([]ItemsKeys, len(messages))
  423. for i, m := range messages {
  424. keys[i] = m.Keys()
  425. }
  426. if err := r.DeleteItems(ctx, dlqName, keys); err != nil {
  427. return fmt.Errorf("failed deleting messages already redriven from DLQ %s to queue %q: beware of duplicates: %w",
  428. dlqName, qURL, err)
  429. }
  430. return nil
  431. }
  432. func (r *redriver) resendQueueMessages(ctx context.Context, qURL string, messages []Message) error {
  433. smbre := make([]types.SendMessageBatchRequestEntry, len(messages))
  434. for i, m := range messages {
  435. m.MessageAttributes["previous-message-id"] = m.MessageId
  436. mav, err := MessageAttributeValuesFromJSONable(m.MessageAttributes)
  437. if err != nil {
  438. return fmt.Errorf("failed converting message attributes for message %s on queue %q: %v",
  439. m.MessageId, qURL, err)
  440. }
  441. smbre[i] = types.SendMessageBatchRequestEntry{
  442. Id: aws.String(strconv.Itoa(i)),
  443. MessageBody: &m.Body,
  444. MessageAttributes: mav,
  445. }
  446. }
  447. smbi := sqs.SendMessageBatchInput{
  448. Entries: smbre,
  449. QueueUrl: &qURL,
  450. }
  451. smbo, err := r.SendMessageBatch(ctx, &smbi)
  452. if err != nil {
  453. return fmt.Errorf("failed sending messages to queue %q: %v",
  454. qURL, err)
  455. }
  456. if len(smbo.Failed) == 0 {
  457. return nil
  458. }
  459. errs := make([]error, len(smbo.Failed))
  460. for _, err := range smbo.Failed {
  461. msg := fmt.Sprintf("ID: %s, Code: %s, Message: %s", *err.Id, *err.Code, *err.Message)
  462. if err.SenderFault {
  463. msg += " (sender fault)"
  464. }
  465. errs = append(errs, errors.New(msg))
  466. }
  467. return fmt.Errorf("partial redrive: failed re-sending %d/%d messages, %v",
  468. len(smbo.Failed), len(smbi.Entries), errs)
  469. }
  470. func (r *redriver) hideQueueMessages(ctx context.Context, dlqName string, qURL string, messages []Message) (fatal, nonfatal error) {
  471. cmvbre := make([]types.ChangeMessageVisibilityBatchRequestEntry, len(messages))
  472. for i, m := range messages {
  473. cmvbre[i] = types.ChangeMessageVisibilityBatchRequestEntry{
  474. Id: aws.String(strconv.Itoa(i)),
  475. ReceiptHandle: aws.String(m.ReceiptHandle),
  476. VisibilityTimeout: r.VTO,
  477. }
  478. }
  479. cmvbi := sqs.ChangeMessageVisibilityBatchInput{
  480. Entries: cmvbre,
  481. QueueUrl: aws.String(qURL),
  482. }
  483. cmvbo, err := r.ChangeMessageVisibilityBatch(ctx, &cmvbi)
  484. if err != nil {
  485. return fmt.Errorf("failed hiding request on DLQ %q: %w", dlqName, err), nil
  486. }
  487. switch len(cmvbo.Failed) {
  488. case len(cmvbi.Entries):
  489. // No message made it: abort.
  490. return fmt.Errorf("failed hiding all %d messages on DLQ %q", len(cmvbi.Entries), dlqName), nil
  491. case 0:
  492. return nil, nil // All well
  493. default:
  494. errs := make([]error, len(cmvbo.Failed))
  495. for _, err := range cmvbo.Failed {
  496. msg := fmt.Sprintf("ID: %s, Code: %s, Message: %s", *err.Id, *err.Code, *err.Message)
  497. if err.SenderFault {
  498. msg += " (sender fault)"
  499. }
  500. errs = append(errs, errors.New(msg))
  501. }
  502. // Some message made it, crossing fingers.
  503. return nil, fmt.Errorf("failed hiding %d/%d messages, %v",
  504. len(cmvbo.Failed), len(cmvbi.Entries), errs)
  505. }
  506. }
  507. func RedriverService(dic *izidic.Container) (any, error) {
  508. cli := dic.MustService(services.SvcClient).(*sqs.Client)
  509. w := dic.MustParam(services.PWriter).(io.Writer)
  510. vto := dic.MustParam(services.PVTO).(time.Duration)
  511. wait := int32(dic.MustParam(services.PWait).(int))
  512. return &redriver{
  513. Client: cli,
  514. VTO: int32(vto.Seconds()),
  515. Wait: wait,
  516. Writer: w,
  517. }, nil
  518. }