Messaging and Queuing NATS API

Introduction

The Neural Autonomic Transport System, or NATS, is an open-source messaging system written in Go. It is part of the Cloud Native Computing Foundation (CNCF) and has more than 40 client language implementations. The application has been designed with performance, scalability, and ease of use in mind. If you're new to NATS, you can learn more about it on our NATS overview page.

Tip:

If NATS is not the Messaging and Queuing service you're looking for, check out our SQS or SNS services. You can also consult the legacy v1alpha1 API. See our dedicated documentation to find out more about Messaging and Queuing going into General Availability, and the associated migration from v1alpha1 to v1beta1.

Concepts

Refer to our dedicated concepts page to find definitions of all terminology related to Messaging and Queuing.

Quickstart

  1. Configure your environment variables

    Note:

    This is an optional step that seeks to simplify your usage of the API.

    export SCW_SECRET_KEY="<API secret key>"
    export SCW_PROJECT_ID="<Scaleway Project ID>"
  2. Create a NATS account. A NATS account provides a scope for your NATS streams, messages and credentials.

    curl --silent -X POST \
    -H "X-Auth-Token: $SCW_SECRET_KEY" \
    -H "Content-Type: application/json" \
    "https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts" \
    -d '{
    "name": "my-nats-account",
    "project_id": "'$SCW_PROJECT_ID'"
    }' | tee my-nats-account.json | jq
    Tip:
    • | tee my-nats-account.json saves the JSON object returned by the API to a file (used by next steps)
    • | jq displays the output nicely
  3. Create credentials. Credentials are necessary to authenticate a client to the NATS service. The nats_account_id field is automatically set to the value of id returned by the previous command:

    curl --silent -X POST \
    -H "X-Auth-Token: $SCW_SECRET_KEY" \
    -H "Content-Type: application/json" \
    "https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-credentials" \
    -d '{
    "name": "my-credentials",
    "nats_account_id": "'$(jq -r .id my-nats-account.json)'"
    }' | tee my-nats-credentials.json | jq
  4. Extract the credentials you created in the previous step:

    jq -r .credentials.content my-nats-credentials.json > nats.creds
  5. Publish your first message with the NATS CLI. Open two terminals for this purpose.

    • On terminal 1: subscribe to a subject

      nats sub -s $(jq -r .endpoint my-nats-account.json) --creds nats.creds my-subject
    • On terminal 2: publish a message to this subject:

      nats pub -s $(jq -r .endpoint my-nats-account.json) --creds nats.creds my-subject 'Hi there!'

    The "Hi there!" message should appear on the terminal 1. You can now abort the subscription by typing "CTRL+C" on terminal 1.

  6. Delete the NATS account

    curl --silent -X DELETE \
    -H "X-Auth-Token: $SCW_SECRET_KEY" \
    -H "Content-Type: application/json" \
    "https://api.scaleway.com/mnq/v1beta1/regions/fr-par/nats-accounts/$(jq -r .id my-nats-account.json)" | jq
Requirements:
  • You have a Scaleway account
  • You have created an API key and that the API key has sufficient IAM permissions to perform the actions described on this page
  • You have installed curl
  • You have installed natscli (choose your installation method between go install, .zip download or .deb installation)
  • You have installed jq

Technical limitations

The maximum storage capacity of a NATS account is 300 MB. Be aware that replicates are counted into this quota.

Technical information

Regional availability

Scaleway Messaging and Queuing is currently only available in the Paris, France region (fr-par).

NATS credentials

Credentials give full access to the NATS account. Isolation can be handled by using several NATS accounts.

Going further

For more help using Scaleway Messaging and Queuing, check out the following resources:

You can also read the official NATS documentation:

NATS accounts

A NATS account allows you to interact with a NATS cluster

GET
/mnq/v1beta1/regions/{region}/nats-accounts
POST
/mnq/v1beta1/regions/{region}/nats-accounts
GET
/mnq/v1beta1/regions/{region}/nats-accounts/{nats_account_id}
PATCH
/mnq/v1beta1/regions/{region}/nats-accounts/{nats_account_id}
DELETE
/mnq/v1beta1/regions/{region}/nats-accounts/{nats_account_id}

NATS credentials

NATS credentials give services and platforms access to the NATS cluster using any standard NATS client

GET
/mnq/v1beta1/regions/{region}/nats-credentials
POST
/mnq/v1beta1/regions/{region}/nats-credentials
GET
/mnq/v1beta1/regions/{region}/nats-credentials/{nats_credentials_id}
DELETE
/mnq/v1beta1/regions/{region}/nats-credentials/{nats_credentials_id}