Skip to content

A tool to sends and receive messages in an asynchronous way to / from different Cloud messaging services.

License

Notifications You must be signed in to change notification settings

fhopfensperger/async-messaging-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Homebrew

brew install fhopfensperger/tap/async-messaging-client

Script

curl https://raw.githubusercontent.com/fhopfensperger/async-messaging-client/main/get.sh | bash

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.zip
  3. Use your favourite file archiver to unpack the archive
  4. Optional Add the async-messaging-client.exe to your PATH

Run as container

Besides installing the binary on the local computer, you have the option to run the program as a container

# Sending a string message 
docker run -it -rm ghcr.io/fhopfensperger/async-messaging-client sb send -q myQueueName -c "Endpoint..." hello
# Sending a json file
docker run -it --rm -v $(pwd)/test.json:/app/test.json ghcr.io/fhopfensperger/async-messaging-client sb send -f test.json -q myQueueName -c "Endpoint..."
# Define environment variable
docker run -it --rm -e QUEUE=myQueueName ghcr.io/fhopfensperger/async-messaging-client sb receive -c "Endpoint..."

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

Azure Service Bus

# Content of test.json
{ "key1": "value1", "key2": "value2", "message" }
Sending
async-messaging-client sb send -f test.json -q myQueueName -c "Endpoint=sb://host.servicebus.windows.net/;SharedAccessKeyName=..."
Receiving one message
async-messaging-client sb receive -q myQueueName -c "Endpoint=sb://host.servicebus.windows.net/;SharedAccessKeyName=..."
Receiving for a specific duration
async-messaging-client sb receive -d 10m -q myQueueName -c "Endpoint=sb://host.servicebus.windows.net/;SharedAccessKeyName=..."

Option 2 (using environment variables)

Setting environment variables
export CONNECTION_STRING='Endpoint=sb:...'
export QUEUE="myQueueName"
Sending
async-messaging-client sb send -f test.json 
Receiving
async-messaging-client sb receive -d 1h