Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ma91n/pubsubschema
https://github.com/ma91n/pubsubschema
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ma91n/pubsubschema
- Owner: ma91n
- License: apache-2.0
- Created: 2021-03-07T01:05:49.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-03-07T08:20:45.000Z (over 3 years ago)
- Last Synced: 2024-01-07T03:59:59.618Z (11 months ago)
- Language: Go
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pubsubschema
Pub/Subメッセージスキーマ機能のGoサンプル実装。
* https://cloud.google.com/pubsub/docs/schemas
## 事前準備
```bash
# スキーマ作成
gcloud beta pubsub schemas create avroschema1 ^
--type=AVRO ^
--definition="{\"type\":\"record\",\"name\":\"Avro\",\"fields\":[{\"name\":\"StringField\",\"type\":\"string\"},{\"name\":\"FloatField\",\"type\":\"float\"},{\"name\":\"BooleanField\",\"type\":\"boolean\"}]}"# スキーマ表示
gcloud beta pubsub schemas describe avroschema1# スキーマ検証
gcloud beta pubsub schemas validate-message ^
--message-encoding=json ^
--message={\"StringField\":\"hello\",\"FloatField\":123.45,\"BooleanField\":true} ^
--schema-name=avroschema1gcloud beta pubsub schemas validate-message ^
--message-encoding=json ^
--message={\"NGField\":\"dummy\"} ^
--schema-name=avroschema1gcloud beta pubsub schemas validate-message ^
--message-encoding=json ^
--message={\"StringField\":\"hello\",\"FloatField\":123.45,\"BooleanField\":"xxx"} ^
--schema-name=avroschema1gcloud beta pubsub schemas validate-message ^
--message-encoding=json ^
--message={\"StringField\":\"hello\",\"FloatField\":123.45,\"BooleanField\":true,\"extra\":\"aaa\"} ^
--schema-name=avroschema1# トピック作成(JSON)
gcloud beta pubsub topics create avrotopic ^
--message-encoding=JSON ^
--schema=avroschema1# トピック作成(バイナリ)
gcloud beta pubsub topics create avrotopic2 ^
--message-encoding=BINARY ^
--schema=avroschema1# 環境変数設定
set GOOGLE_APPLICATION_CREDENTIALS=%USERPROFILE%/.gcp/-1234567890abc.json
```