3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

OCI Queueサービスの簡単な検証(OCI CLI)

Last updated at Posted at 2023-01-08

概要

別記事にてOCI Queueサービスの検証をAPIを使用して実施しました。
OCI Queueサービスの簡単な検証
https://qiita.com/tktk2712/items/76d04f93a6a8727270b2
今回はOCI CLIを使用して検証を行ってみました

検証方法

基本的な検証を行うため、以下の手順で実施しました

  • キューの作成
  • キューに入れるメッセージの作成
  • メッセージのPut
  • メッセージのGet
  • DLQに移行したメッセージのGet

検証

  • キューの作成
    別記事にて作成済みのキューをそのまま利用します
  • キューに入れるメッセージの作成
    以下のようにメッセージを作成しました
queuemessage1.json
{
  "messages": [
    {
      "content": "queuemessage1"
    }
  ]
}
  • メッセージのPut
    OCI CLIは2023/1時点で最新の3.22.0です。
    バージョンが古いとコマンドがサポートされていないようです。
user@linux:~ (ap-tokyo-1)$ oci -v
3.22.0

OCI CLI Command Referenceに沿ってPutコマンドを実行するとエラー404となります

user@linux:~ (ap-tokyo-1)$ oci queue messages put-messages --messages file://queuemessage1.json --queue-id 【QueueのOCID】
ServiceError:
{
    "client_version": "Oracle-PythonSDK/2.90.0, Oracle-PythonCLI/3.22.0",
    "code": "NotAuthorizedOrNotFound",
    "logging_tips": "Please run the OCI CLI command using --debug flag to find more debug information.",
    "message": "Authorization failed or requested resource not found.",
    "opc-request-id": "",
    "operation_name": "put_messages",
    "request_endpoint": "POST https://messaging.ap-tokyo-1.oci.oraclecloud.com/20210201/queues/【QueueのOCID】/messages",
    "status": 404,
    "target_service": "queue",
    "timestamp": "",
    "troubleshooting_tips": "See [https://docs.oracle.com/iaas/Content/API/References/apierrors.htm] for more information about resolving this error. If you are unable to resolve this issue, run this CLI command with --debug option and contact Oracle support and provide them the full error message."
}

エラー内容を確認するとrequest_endpointが別のURIになっています。
正しいメッセージ・エンドポイントhttps://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com にするためにGlobal Parametersの--endpointで直接指定しました。

user@linux:~ (ap-tokyo-1)$ oci queue messages put-messages --messages file://queuemessage1.json --queue-id 【QueueのOCID】 --endpoint https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com
ServiceError:
{
    "client_version": "Oracle-PythonSDK/2.90.0, Oracle-PythonCLI/3.22.0",
    "code": "InvalidParameter",
    "logging_tips": "Please run the OCI CLI command using --debug flag to find more debug information.",
    "message": "Unable to parse JSON body",
    "opc-request-id": "",
    "operation_name": "put_messages",
    "request_endpoint": "POST https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com/20210201/queues/【QueueのOCID】/messages",
    "status": 400,
    "target_service": "queue",
    "timestamp": "",
    "troubleshooting_tips": "See [https://docs.oracle.com/iaas/Content/API/References/apierrors.htm] for more information about resolving this error. If you are unable to resolve this issue, run this CLI command with --debug option and contact Oracle support and provide them the full error message."
}

Endpointは修正されましたがステータスが400に変わりました。messageの内容を確認するとJSON形式を修正する必要があるようです。
そのため、正しいInput形式を確認するため--generate-param-json-inputをつけてJSONサンプルを取得します

user@linux:~ (ap-tokyo-1)$ oci queue messages put-messages --generate-param-json-input messages > example.json
user@linux:~ (ap-tokyo-1)$ cat example.json
[
  {
    "content": "string"
  },
  {
    "content": "string"
  }
]

上記サンプルに沿ってInput fileを修正します

queuemessage1.json
[
  {
    "content": "queuemessage1"
  }
]

Putを再実行します

user@linux:~ (ap-tokyo-1)$ oci queue messages put-messages --messages file://queuemessage1.json --queue-id 【QueueのOCID】 --endpoint https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com
{
  "data": {
    "messages": [
      {
        "id": 67553994410557448
      }
    ]
  }
}

今度は正しく送信できました
image.png

  • メッセージのGet
    以下のようにget-messageで取得できました
user@linux:~ (ap-tokyo-1)$ oci queue messages get-messages --queue-id 【QueueのOCID】 --endpoint https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com
{
  "data": {
    "messages": [
      {
        "content": "queuemessage1",
        "delivery-count": 1,
        "expire-after": "",
        "id": 67553994410557448,
        "receipt": "【receipt】",
        "visible-after": ""
      }
    ]
  }
}

メッセージの削除も同様に可能です

user@linux:~ (ap-tokyo-1)$ oci queue messages delete-message --message-receipt 【receipt】 --queue-id 【QueueのOCID】 --force --endpoint https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com
user@linux:~ (ap-tokyo-1)$ 

--forceオプションをつけないと削除するか聞かれます

  • DLQに移行したメッセージのGet
    DLQのメッセージGetも可能です
user@linux:~ (ap-tokyo-1)$ oci queue messages get-messages --queue-id 【QueueのOCID】 --endpoint https://cell-1.queue.messaging.ap-tokyo-1.oci.oraclecloud.com
{
  "data": {
    "messages": [
      {
        "content": "queuemessage1",
        "delivery-count": 7,
        "expire-after": "",
        "id": 67553994410557449,
        "receipt": "【receipt】",
        "visible-after": ""
      }
    ]
  }
}
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?