OCI Queueサービスの簡単な検証(httpメソッド POST/GET)

## 概要
OCIにQueueサービス利用が開始されましたので簡単な検証を行ってみました

OCI Queue がすべての商用リージョンで利用可能に
https://blogs.oracle.com/oracle4engineer/post/oci-queue-ga

Oracle Cloud Infrastructure Documentation
Queue
https://docs.oracle.com/en-us/iaas/Content/queue/

## 検証方法
基本的な検証を行うため、以下の手順で実施しました
* キューの作成
* キューに入れるメッセージの作成
* メッセージのPut
* メッセージのGet
* DLQに移行したメッセージのGet

## 検証
* キューの作成
開発者サービス>>キューを選択しキューの作成ボタンを押下
キューを作成
現時点ではFIFOはサポートされていないとのことです
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2730992/4332ce26-4311-45da-d82d-a0b11c1d2355.png)

キューが作成されました
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2730992/a173d0ab-cd43-dbeb-a039-8eda80f7422a.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2730992/81895cb0-4f64-6827-649c-4c5b04a987f7.png)


* キューに入れるメッセージの作成
以下のようにメッセージを作成しました
```queuemessage1.json
{
  "messages": [
    {
      "content": "queuemessage1"
    }
  ]
}
```

* メッセージのPut
OCI CLIを使用したHTTP形式を使用しました
Return Codeが200になればOKです

```
[user@linux]$ oci raw-request --http-method POST --target-uri  https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com/20210201/queues/【QueueのOCID】/messages --request-body file://queuemessage1.json
{
  "data": {
    "messages": [
      {
        "expireAfter": "",
        "id": 
      }
    ]
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-methods": "POST,PUT,GET,HEAD,DELETE,OPTIONS",
    "access-control-allow-origin": "*",
    "access-control-expose-headers": "access-control-allow-credentials,access-control-allow-methods,access-control-allow-origin,content-length,content-type,opc-client-info,opc-request-id",
    "content-length": "80",
    "content-type": "application/json",
    "opc-request-id": ""
  },
  "status": "200 OK"
}

```
OCIコンソール上でもキューに1つのメッセージがPutされました
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2730992/c3babb34-385c-f385-a8dd-f3e48445afde.png)

* メッセージのGet
以下のコマンドでget操作を行います
Putしたメッセージ"queuemessage1"が取得できました
```
[user@linux]$ oci raw-request --http-method GET --target-uri  https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com/20210201/queues/【QueueのOCID】/messages?timeoutInSeconds=3
{
  "data": {
    "messages": [
      {
        "content": "queuemessage1",
        "deliveryCount": 4,
        "expireAfter": "",
        "id": ,
        "receipt": "【receipt】",
        "visibleAfter": ""
      }
    ]
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-methods": "POST,PUT,GET,HEAD,DELETE,OPTIONS",
    "access-control-allow-origin": "*",
    "access-control-expose-headers": "access-control-allow-credentials,access-control-allow-methods,access-control-allow-origin,content-length,content-type,opc-client-info,opc-request-id",
    "content-length": "415",
    "content-type": "application/json",
    "opc-request-id": "【opc-request-id】"
  },
  "status": "200 OK"
}
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2730992/f158eb47-6a76-7e90-eece-6f7caa7c2c1d.png)

30秒の表示タイムアウト内にもう一度GETリクエストを行うとメッセージは取得できません

```
[user@linux]$ oci raw-request --http-method GET --target-uri  https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com/20210201/queues/【QueueのOCID】/messages?timeoutInSeconds=3
{
  "data": {
    "messages": []
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-methods": "POST,PUT,GET,HEAD,DELETE,OPTIONS",
    "access-control-allow-origin": "*",
    "access-control-expose-headers": "access-control-allow-credentials,access-control-allow-methods,access-control-allow-origin,content-length,content-type,opc-client-info,opc-request-id",
    "content-length": "15",
    "content-type": "application/json",
    "opc-request-id": ""
  },
  "status": "200 OK"
}
```
30秒の表示タイムアウト後は再度メッセージが取得可能となります。
メッセージ処理が完了して再度利用されないようにするためには、以下のようにメッセージを削除します
Return Codeが204になれば削除完了です
```
[user@linux]$ oci raw-request --http-method DELETE --target-uri  https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com/20210201/queues/【QueueのOCID】/messages/【receipt】
{
  "data": "",
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-methods": "POST,PUT,GET,HEAD,DELETE,OPTIONS",
    "access-control-allow-origin": "*",
    "access-control-expose-headers": "access-control-allow-credentials,access-control-allow-methods,access-control-allow-origin,content-length,opc-client-info,opc-request-id",
    "opc-request-id": "【opc-request-id】"
  },
  "status": "204 No Content"
}
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2730992/41bb9677-9fb4-feca-ff88-94d061800efd.png)

* DLQに移行したメッセージのGet
配信最大試行回数(今回は5回)を超えるとメッセージはDLQに移行します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2730992/7aa1a56a-3f6f-ea03-ef7d-529c64ee01ab.png)

DLQ内のメッセージをGetすることも可能です
```
Queue内の確認、表示可能なメッセージはない
[user@linux]$ oci raw-request --http-method GET --target-uri  https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com/20210201/queues/【QueueのOCID】/messages?timeoutInSeconds=3
{
  "data": {
    "messages": []
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-methods": "POST,PUT,GET,HEAD,DELETE,OPTIONS",
    "access-control-allow-origin": "*",
    "access-control-expose-headers": "access-control-allow-credentials,access-control-allow-methods,access-control-allow-origin,content-length,content-type,opc-client-info,opc-request-id",
    "content-length": "15",
    "content-type": "application/json",
    "opc-request-id": ""
  },
  "status": "200 OK"
}

DLQ内の確認、メッセージが表示される
[user@linux]$ oci raw-request --http-method GET --target-uri  https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com/20210201/queues/【DLQのOCID】/messages?timeoutInSeconds=3
{
  "data": {
    "messages": [
      {
        "content": "queuemessage1",
        "deliveryCount": 6,
        "expireAfter": "",
        "id": ,
        "receipt": "",
        "visibleAfter": ""
      }
    ]
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-methods": "POST,PUT,GET,HEAD,DELETE,OPTIONS",
    "access-control-allow-origin": "*",
    "access-control-expose-headers": "access-control-allow-credentials,access-control-allow-methods,access-control-allow-origin,content-length,content-type,opc-client-info,opc-request-id",
    "content-length": "421",
    "content-type": "application/json",
    "opc-request-id": ""
  },
  "status": "200 OK"
}
```