async-messaging-client

command module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

async-messaging-client

Go Go Report Card Release

Sends and receives messages in an asynchronous way to / from different Cloud messaging services.

Currently, the following Cloud services are supported:

Installation

Linux / Mac OS
Option 1 (script)
curl https://raw.githubusercontent.com/fhopfensperger/async-messaging-client/main/get.sh | bash
Option 2 (manually)

Go to Releases download the latest release according to your processor architecture and operating system, then unzip and copy it to the right location

tar xvfz async-messaging-client_x.x.x_darwin_amd64.tar.gz
cd async-messaging-client_x.x.x_darwin_amd64
chmod +x async-messaging-client
sudo mv async-messaging-client /usr/local/bin/
Windows
  1. Go to Releases
  2. Download the latest release async-messaging-client_x.x.x_windows_amd64.tar.gz
  3. Use 7-Zip or your favourite file archiver to unpack the archive
  4. Optional Add the async-messaging-client.exe in to your PATH

Usage Examples:

Google Pub/Sub

NOTE Before publishing message to a Pub/Sub topic and/ or subscribing to a subscription it is important to set proper authentication.


Print usage:
$ async-messaging-client pubsub --help
Interact with Google Cloud Pub/Sub

Usage:
  async-messaging-client pubsub [command]

Available Commands:
  publish     Publish a message to a Google Pub/Sub Topic
  subscribe   Subscribe to a Google Pub/Sub Subscription

Flags:
  -h, --help             help for pubsub
  -p, --project string   Google Cloud Project ID
  -t, --topic string     Google Cloud Pub/Sub Topic

Use "async-messaging-client pubsub [command] --help" for more information about a command.
Authentication
  1. Create a service account and assign proper permissions in the Google Cloud Platform console
  2. Download the service account key
  3. Set environment variable GOOGLE_APPLICATION_CREDENTIALS For Linux / Mac OS
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account-key.json

For Windows

set GOOGLE_APPLICATION_CREDENTIALS=C:\Path\to\service-account-key.json
Publishing (Sending)

Local files

# Content of test.json
{
  "prop1": 123,
  "prop2": "456",
  "prop3": "789",
  "prop4": {
    "prop1": 123,
    "prop2": "456",
    "propArray": [
      "456", "789", "0"
    ]
  }
}

# Content of attributes.json
{
  "eventType": "this.is.a.sample.event.type",
  "dispatcherId": "this.is.a.sample.id",
  "schemaVersion": "v1"
}

Send message (test.json) with attributes (attributes.json) to a topic topic-test

$ async-messaging-client pubsub publish -p google-project-id -t topic-test -f test.json -a attributes.json
2021-04-08T14:33:17+02:00 INF Trying to send message: 
{
  "prop1": 123,
  "prop2": "456",
  "prop3": "789",
  "prop4": {
    "prop1": 123,
    "prop2": "456",
    "propArray": [
      "456", "789", "0"
    ]
  }
}
with attributes: map[string]string{"dispatcherId":"this.is.a.sample.id", "eventType":"this.is.a.sample.event.type", "schemaVersion":"v1"}
to topic: topic-test for project: google-project-id
2021-04-08T14:33:18+02:00 INF Successfully published message with msgId: 2258869234167928 to projects/google-project-id/topics/topic-test 

Simple Strings

$ async-messaging-client pubsub publish -p google-project-id message-string
Subscribing (Receiving)

To receive message which are sent to a topic using a subscription and acknowledge them right away

$ async-messaging-client pubsub subscribe -p google-project-id -s test-sub
2021-04-08T14:36:08+02:00 INF Subscribing to test-sub on project google-project-id

2021-04-08T14:36:29+02:00 INF Got message: {
  "prop1": 123,
  "prop2": "456",
  "prop3": "789",
  "prop4": {
    "prop1": 123,
    "prop2": "456",
    "propArray": [
      "456", "789", "0"
    ]
  }
}, from projects/google-project-id/subscriptions/test-sub with attributes map[string]string{"dispatcherId":"this.is.a.sample.id", "eventType":"this.is.a.sample.event.type", "schemaVersion":"v1"} with message id 2258869234167928

 

Documentation

Overview

Copyright © 2020 Florian Hopfensperger <f.hopfensperger@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL