This code sample demonstrates the usage of the go-batcher
.
-
Clone this repo https://github.com/plasne/go-batcher
-
Open the
/sample
directory in Visual Studio Code -
Update
sample/go.mod
with your go version -
Update the
replace
command insample/go.mod
with your local path for go-batcherreplace github.com/plasne/go-batcher => <local-path-for-go-batcher>
-
Create an Azure Storage Account and a container. This will be the used for the SharedResource rate limiter. Using Azure CLI you can use the following commands:
# Set your variables SUBSCRIPTIONID="insert-azure-subscription-id" RESOURCEGROUP="insert-resource-group-name" LOCATION="insert-location" #e.g., westus AZBLOB_ACCOUNT="insert-storage-account-name" AZBLOB_CONTAINER="insert-storage-account-container-name" # Login to azure az login # Set your default subscription az acount set -s $SUBSCRIPTIONID # Create resource group az group create --name $RESOURCEGROUP --location $LOCATION # Create storage account az storage account create --name $AZBLOB_ACCOUNT --resource-group $RESOURCEGROUP --location $LOCATION --sku Standard_RAGRS --kind StorageV2 # Create storage account container az storage container create --name $AZBLOB_CONTAINER --account-name $AZBLOB_ACCOUNT --auth-mode login
-
Create your .env file by copying .sample-env
cp .sample-env .env
and set up the following variables:
- AZBLOB_ACCOUNT: The Azure Storage Account name
- AZBLOB_CONTAINER: The Azure Storage Account container
- AZBLOB_KEY: The Azure Storage Account key
-
Open your Terminal to run the sample
go run .
-
In another terminal run the following curl command to enqueue Operations to the Batcher.
curl http://localhost:8080/ingest
You can also increase SharedCapacity by 1,000 by running the following curl command.
curl http://localhost:8080/inc
Likewise, you can decrease the SharedCapacity by 1,000 by running the following curl command.
curl http://localhost:8080/dec