URLinks Docs
GatewayChain
Set theme to dark (⇧+D)

Get started

Gateway Chain is a serverless message queue solution allows serverless, edge runtimes and other distributed workflows to communicate with each other.

A Chain is responsible for processing requests and forwarding them to the next gateway(endpoint) in the chain.

Chain allows you to pass data between gateways in the chain. Such as json, binary data, large file in Bucket.

​​ Create a workflow

A workflow is a remote function, like a topic in Kafka (or other message queue systems) with callbacks. You can create multiple workflows in a chain.

​​ Add endpoints to workflow

An endpoint is a gateway in the workflow. You can add multiple endpoints to a workflow, depends on chain’s configuration; endpoints will have different behaviors.

​​ Publish messages to chain

A messages can contain any type of data.

Let’s log a message to an external service using typescript SDK.


import { Gateway, type Endpoint } from "@urlinks/gateway-chain"
type GatewayWorkflow = {
log: Workflow<string>
}
export default {
async fetch(request: Request, ctx: Context) {
const gateway = new Gateway<GatewayEndPoints>(ctx.env.GATEWAY_CHAIN_URL, ctx.env.GATEWAY_CHAIN_URL)
const text = await request.text()
ctx.waitUntil(gateway.log(text))
// your own handler ...
}
}

​​ Register Endpoint

By default, a chain’s url will be the link + /{chain}/{workflow}, you can create your own endpoint or use the SDK directly.


import { Endpoint } from "@urlinks/gateway-chain"
const endpoint = new Endpoint<string>("log", log, ctx.env.GATEWAY_CHAIN_URL, ctx.env.GATEWAY_CHAIN_SECRECT)
async function log(text: string, ctx: Context) {
// store to database
}
export default endpoint