Router configuration

How to configure the router config.yml for your NATS event provider.

Defining a NATS provider

All event providers are defined under events.sources:

events:
    sources:
        default:
            ...
        anotherSourceName:
            ...

Each named property under events.sources corresponds to a sourceName argument that is defined by an events directive. If no sourceName is provided, the default value, "default", is used. If an events directive defines a sourceName argument that is not defined in the router config.yml, the router will return an error and fail to start.

Required Properties

The following properties are always required:

Property nameTypeValue

provider

enum

NATS

url

string

your NATS server url

Authentication (optional)

The authentication property is optional; however, if it is defined, either a token, or a username and password pair must be provided:

Authentication property nameTypeValueAdditional requirements

token

string

your NATS server token

no username nor password property

username

string

your NATS server username

no token property; password property

password

string

your NATS server password

no token property; username property

Example configuration

Consider the following Event-Driven Graph schema SDL and its corresponding router config.yml:

# EDG schema SDL (some definitions omitted for breity)
type Subscription {
    userUpdated(id: Int!): User! @edfs__susbcribe(subjects: ["userUpdated.{{ args.id }}"])
    userUpdatedTwo(id: Int!): User! @edfs__subscribe(subjects: ["userUpdated.{{ args.id }}"], sourceName: "anotherNats")
}
# (partial) router config.yml

events:
    sources:
        default:
            provider: NATS
            url: "nats://localhost:4222"
            authentication:
                token: "xxxxx"
        anotherNats:
            provider: NATS
            url: "nats://localhost:4223"

The Subscription.userUpdated field defines no sourceName argument; therefore, it corresponds to events.sources.default in the config.yml.

The Subscription.userUpdatedTwo field defines the value "anotherNats" for its sourceName argument; therefore, it corresponds to events.sources.default in the router config.yml.

Last updated