@got-api/ons

https://help.aliyun.com/document_detail/102996.html

Usage no npm install needed!

<script type="module">
  import gotApiOns from 'https://cdn.skypack.dev/@got-api/ons';
</script>

README

api-ons

https://help.aliyun.com/document_detail/102996.html

TODO

  • 请求重试

sample

const Ons = require('.')

const {
  TEST_ALIYUN_KEY,
  TEST_ALIYUN_SECRET,
  TEST_ONS_ENDPOINT,
  TEST_ONS_INSTANCE_ID
} = process.env

const ons = new Ons({
  endpoint: TEST_ONS_ENDPOINT,
  accessKeyId: TEST_ALIYUN_KEY,
  accessKeySecret: TEST_ALIYUN_SECRET
})

const baseQuery = ons
  .query()
  .instanceId(TEST_ONS_INSTANCE_ID)
  .topic('ADM_TIMER')
  .tag('test_dev_1')
  .consumer('GID_ADM_TIMER_test_dev_hc')

const start = async () => {
  const { MessageId } = await baseQuery.create('test')
  let hasMore = true
  do {
    const msgs = await baseQuery.find(1)
    while (msgs.length) {
      const msg = msgs.pop()
      if (msg.MessageId === MessageId) {
        hasMore = false
      }
      await baseQuery.delete(msg.ReceiptHandle)
    }
  } while (hasMore)
}

start()