Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcloud beta pubsub subscriptions pull format

Quick question: When I pull message from pubsub subscription via command line tool

gcloud beta pubsub subscriptions pull MY_SUB

I am getting a table with (all details and) data as string (already decoded) But i want to use it so i did:

gcloud beta pubsub subscriptions pull MY_SUB --format=json

Than i receive a json with (all details) but the data is encoded.

There is a way to get it parsed with formatting?

Example of publishing message:

gcloud beta  pubsub topics publish myTopic "Topic Message" --attribute=Ai=A,Bee=B

NO-FORMATTING_RETURN

  ─────────────┬─────────────────┬────────────────┬─────────────────────────

  ──────────────────────────────────────────────────────────────────────────
    ─────────────────────────────────────────────────────────────┐
    │     DATA    │    MESSAGE_ID   │   ATTRIBUTES   │                                                                             
    ACK_ID                                                                             
    │

  ├─────────────┼─────────────────┼────────────────┼────────────────────────

  ──────────────────────────────────────────────────────────────────────────
     ──────────────────────────────────────────────────────────────┤
     │ Topic Message │ 122122177601805 │ Ai=A Bee=B  │ ACK_ID... │

  └─────────────┴─────────────────┴────────────────┴────────────────────────

  ──────────────────────────────────────────────────────────────────────────
    ──────────────────────────────────────────────────────────────┘

FORMATTING

[
{
"ackId": "ACK_ID..",
"message": {
  "attributes": {
    "Ai": "A",
      "Bee": "B"
    },
     "data": "SGVsbG8gVG9waWM=",
     "messageId": "122121955409996",
     "publishTime": "2017-05-11T10:26:54.143Z"
    }
}
]
like image 554
Uda Avatar asked May 11 '17 11:05

Uda


People also ask

Is Pub sub push or pull?

In a push subscription, a Pub/Sub server initiates a request to your subscriber client to deliver messages. The following image shows the workflow between a subscriber client and a push subscription.

What is streaming pull in Pubsub?

Asynchronous PullMessages can be received in your application using a long running message listener, and acknowledged one message at a time, as shown in the example below. Java, Python, . NET, Go, and Ruby clients use the StreamingPull service API to implement the asynchronous client API efficiently.

What is pull subscription?

A pull subscription requests that records are collected and sent to the data consumer when the data consumer requests. The use of a pull subscription provides more control over the flow of records to the transaction record consumer.


1 Answers

You are on the right track with the use of the --format argument, but you need to use projections in order to decode the data. In this case, you need to use the decode() projection. Here's how you can perform the same command with the same data except the message's data is base64 decoded.

gcloud beta pubsub subscriptions pull MY_SUB --format="json(ackId, message.attributes, message.data.decode(\"base64\").decode(\"utf-8\"), message.messageId, message.publishTime)"

[
  {
    "ackId": "QV5AEkw...D5-NTlF",
    "message": {
      "attributes": {
        "Ai": "A",
        "Bee": "B"
      },
      "data": "Topic Message",
      "messageId": "127236468931635",
      "publishTime": "2017-05-29T23:15:04.637Z"
    }
  }
]
like image 86
Technetium Avatar answered Oct 06 '22 02:10

Technetium