Skip to main content

AMQP

AMQP is currently available through the generators (channels):

LanguagesPublish exchangePublish queueSubscribe
TypeScript✔️✔️

All of this is available through AsyncAPI.

Channels

Read more about the channels generator here before continuing.

This generator provides support functions for each resource ensuring you the right payload and parameter are used.

Input (AsyncAPI)Using the code
asyncapi: 3.0.0
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signups
channels:
userSignups:
address: user/signedup
messages:
userSignedup:
$ref: '#/components/messages/UserSignedUp'
operations:
publishUserSignups:
action: send
channel:
$ref: '#/channels/userSignups'
consumeUserSignups:
action: receive
channel:
$ref: '#/channels/userSignups'
components:
messages:
UserSignedUp:
payload:
type: object
properties:
displayName:
type: string
description: Name of the user
email:
type: string
format: email
description: Email of the user

import * as Amqp from 'amqplib';
// Location depends on the payload generator configurations
import { UserSignedup } from './__gen__/payloads/UserSignedup';
// Location depends on the channel generator configurations
import { Protocols } from './__gen__/channels';
const { amqp } = Protocols;
const { publishToPublishUserSignupsExchange, publishToPublishUserSignupsQueue } = amqp;

/**
* Setup the regular client
*/
const client = await amqplib.connect('amqp://localhost');

const myPayload = new UserSignedup({displayName: 'test', email: '[email protected]'});
// Produce the messages with the generated channel function
await publishToPublishUserSignupsExchange(myPayload, client);
await publishToPublishUserSignupsQueue(myPayload, client);