Sends and receives messages in an asynchronous way to / from different Cloud messaging services.
Currently, the following Cloud services are supported:
brew install fhopfensperger/tap/async-messaging-client
curl https://raw.githubusercontent.com/fhopfensperger/async-messaging-client/main/get.sh | bash
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/
- Go to Releases
- Download the latest release async-messaging-client_x.x.x_windows_amd64.zip
- Use your favourite file archiver to unpack the archive
- Optional Add the
async-messaging-client.exe
to yourPATH
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..."
NOTE Before publishing message to a Pub/Sub topic and/ or subscribing to a subscription it is important to set proper authentication.
$ 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.
- Create a service account and assign proper permissions in the Google Cloud Platform console
- Download the service account key
- 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
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
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
# Content of test.json
{ "key1": "value1", "key2": "value2", "message" }
async-messaging-client sb send -f test.json -q myQueueName -c "Endpoint=sb://host.servicebus.windows.net/;SharedAccessKeyName=..."
async-messaging-client sb receive -q myQueueName -c "Endpoint=sb://host.servicebus.windows.net/;SharedAccessKeyName=..."
async-messaging-client sb receive -d 10m -q myQueueName -c "Endpoint=sb://host.servicebus.windows.net/;SharedAccessKeyName=..."
export CONNECTION_STRING='Endpoint=sb:...'
export QUEUE="myQueueName"
async-messaging-client sb send -f test.json
async-messaging-client sb receive -d 1h