Skip to content

Commit f41950e

Browse files
committed
fix test
1 parent 8bf56b3 commit f41950e

File tree

9 files changed

+192
-69
lines changed

9 files changed

+192
-69
lines changed

docs/generators/channels.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
preset: 'channels',
1313
outputPath: './src/__gen__/',
1414
language: 'typescript',
15-
protocols: ['nats', 'kafka']
15+
protocols: ['nats']
1616
}
1717
]
1818
};
@@ -26,7 +26,7 @@ This is supported through the following inputs: [`asyncapi`](#inputs)
2626

2727
It supports the following languages; [`typescript`](#typescript)
2828

29-
It supports the following protocols; [`nats`](../protocols/nats.md), [`kafka`](../protocols/kafka.md), [`mqtt`](../protocols/mqtt.md)
29+
It supports the following protocols; [`nats`](../protocols/nats.md), [`kafka`](../protocols/kafka.md), [`mqtt`](../protocols/mqtt.md), [`amqp`](../protocols/amqp.md)
3030

3131
## Options
3232
These are the available options for the `channels` generator;
@@ -43,12 +43,13 @@ Depending on which protocol, these are the dependencies:
4343
- `NATS`: https://github.com/nats-io/nats.js v2
4444
- `Kafka`: https://github.com/tulios/kafkajs v2
4545
- `MQTT`: https://github.com/mqttjs/MQTT.js v5
46+
- `AMQP`: https://github.com/amqp-node/amqplib v0
4647

4748
For TypeScript what is generated is a single file that include functions to help easier interact with AsyncAPI channels. For example;
4849

4950
```ts
5051
import { Protocols } from 'src/__gen__/index';
51-
const { nats, kafka, mqtt, ... } = Protocols;
52+
const { nats, kafka, mqtt, amqp ... } = Protocols;
5253
const { jetStreamPublishTo..., jetStreamPullSubscribeTo..., jetStreamPushSubscriptionFrom..., publishTo..., subscribeTo... } = nats;
5354
```
5455

docs/protocols/amqp.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
sidebar_position: 99
3+
---
4+
5+
# AMQP
6+
`AMQP` is currently available through the generators ([channels](#channels)):
7+
8+
| **Languages** | publish exchange | publish queue | subscribe |
9+
|---|---|---|
10+
| TypeScript | ✔️ | ✔️ | |
11+
12+
All of this is available through [AsyncAPI](../inputs/asyncapi.md).
13+
14+
## Channels
15+
Read more about the [channels](../generators/channels.md) generator here before continuing.
16+
17+
This generator provides support functions for each resource ensuring you the right payload and parameter are used.
18+
19+
<table>
20+
<thead>
21+
<tr>
22+
<th>Input (AsyncAPI)</th>
23+
<th>Using the code</th>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
<tr>
28+
<td>
29+
30+
```yaml
31+
asyncapi: 3.0.0
32+
info:
33+
title: Account Service
34+
version: 1.0.0
35+
description: This service is in charge of processing user signups
36+
channels:
37+
userSignups:
38+
address: user/signedup
39+
messages:
40+
userSignedup:
41+
$ref: '#/components/messages/UserSignedUp'
42+
operations:
43+
publishUserSignups:
44+
action: send
45+
channel:
46+
$ref: '#/channels/userSignups'
47+
consumeUserSignups:
48+
action: receive
49+
channel:
50+
$ref: '#/channels/userSignups'
51+
components:
52+
messages:
53+
UserSignedUp:
54+
payload:
55+
type: object
56+
properties:
57+
displayName:
58+
type: string
59+
description: Name of the user
60+
email:
61+
type: string
62+
format: email
63+
description: Email of the user
64+
65+
```
66+
</td>
67+
<td>
68+
69+
```ts
70+
import * as Amqp from 'amqplib';
71+
// Location depends on the payload generator configurations
72+
import { UserSignedup } from './__gen__/payloads/UserSignedup';
73+
// Location depends on the channel generator configurations
74+
import { Protocols } from './__gen__/channels';
75+
const { amqp } = Protocols;
76+
const { publishToPublishUserSignupsExchange, publishToPublishUserSignupsQueue } = mqtt;
77+
78+
/**
79+
* Setup the regular client
80+
*/
81+
const client = await amqplib.connect('amqp://localhost');
82+
83+
const myPayload = new UserSignedup({displayName: 'test', email: 'test@test.dk'});
84+
// Produce the messages with the generated channel function
85+
await publishToPublishUserSignupsExchange(myPayload, client);
86+
await publishToPublishUserSignupsQueue(myPayload, client);
87+
```
88+
</td>
89+
</tr>
90+
</tbody>
91+
</table>

docs/protocols/kafka.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ const kafkaClient = new Kafka({
8383
});
8484

8585
const myPayload = new UserSignedup({displayName: 'test', email: 'test@test.dk'});
86-
const myParameters = new UserSignedUpParameters({userId: 'test'});
8786

8887
// Consume the messages with the generated channel function
8988
const consumerCallback = async (
@@ -105,7 +104,7 @@ const consumer = await consumeFromConsumeUserSignups(
105104
);
106105

107106
// Produce the messages with the generated channel function
108-
const producer = await produceToPublishUserSignups(myPayload, myParameters, kafkaClient);
107+
const producer = await produceToPublishUserSignups(myPayload, kafkaClient);
109108
```
110109
</td>
111110
</tr>

docs/protocols/mqtt.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ const { publishToUserSignedup } = mqtt;
8181
const client = await MqttClient.connectAsync("mqtt://0.0.0.0:1883");
8282

8383
const myPayload = new UserSignedup({displayName: 'test', email: 'test@test.dk'});
84-
const myParameters = new UserSignedUpParameters({userId: 'test'});
8584

8685
// Produce the messages with the generated channel function
87-
const producer = await publishToUserSignedup(myPayload, myParameters, kafkaClient);
86+
const producer = await publishToUserSignedup(myPayload, client);
8887
```
8988
</td>
9089
</tr>

src/codegen/generators/typescript/channels/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ export async function generateTypeScriptChannels(
556556

557557
case 'amqp': {
558558
const topic = simpleContext.topic;
559-
let natsContext: RenderRegularParameters = {
559+
let amqpContext: RenderRegularParameters = {
560560
...simpleContext,
561561
topic,
562562
messageType: ''
@@ -575,8 +575,8 @@ export async function generateTypeScriptChannels(
575575
}
576576
const {messageModule, messageType} =
577577
getMessageTypeAndModule(payload);
578-
natsContext = {
579-
...natsContext,
578+
amqpContext = {
579+
...amqpContext,
580580
messageType,
581581
messageModule,
582582
subName: findNameFromOperation(operation, channel)
@@ -590,7 +590,7 @@ export async function generateTypeScriptChannels(
590590
generator.asyncapiReverseOperations
591591
)
592592
) {
593-
renders.push(AmqpRenderer.renderPublishExchange({...natsContext, additionalProperties: {exchange: exchangeName}}));
593+
renders.push(AmqpRenderer.renderPublishExchange({...amqpContext, additionalProperties: {exchange: exchangeName}}));
594594
}
595595
if (
596596
shouldRenderFunctionType(
@@ -600,7 +600,7 @@ export async function generateTypeScriptChannels(
600600
generator.asyncapiReverseOperations
601601
)
602602
) {
603-
renders.push(AmqpRenderer.renderPublishQueue(natsContext));
603+
renders.push(AmqpRenderer.renderPublishQueue(amqpContext));
604604
}
605605
}
606606
} else {
@@ -612,7 +612,7 @@ export async function generateTypeScriptChannels(
612612
}
613613
const {messageModule, messageType} =
614614
getMessageTypeAndModule(payload);
615-
natsContext = {...natsContext, messageType, messageModule};
615+
amqpContext = {...amqpContext, messageType, messageModule};
616616

617617
if (
618618
shouldRenderFunctionType(
@@ -622,7 +622,7 @@ export async function generateTypeScriptChannels(
622622
generator.asyncapiReverseOperations
623623
)
624624
) {
625-
renders.push(AmqpRenderer.renderPublishExchange({...natsContext, additionalProperties: {exchange: exchangeName}}));
625+
renders.push(AmqpRenderer.renderPublishExchange({...amqpContext, additionalProperties: {exchange: exchangeName}}));
626626
}
627627
if (
628628
shouldRenderFunctionType(
@@ -632,7 +632,7 @@ export async function generateTypeScriptChannels(
632632
generator.asyncapiReverseOperations
633633
)
634634
) {
635-
renders.push(AmqpRenderer.renderPublishQueue(natsContext));
635+
renders.push(AmqpRenderer.renderPublishQueue(amqpContext));
636636
}
637637
}
638638
protocolCodeFunctions[protocol].push(

src/codegen/generators/typescript/channels/protocols/amqp/publishExchange.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function renderPublishExchange({
2424
const publishOperation = `let dataToSend: any = ${messageType === 'null' ? 'null' : messageMarshalling};
2525
const channel = await amqp.createChannel();
2626
const routingKey = ${addressToUse};
27-
channel.publish(exchange, routingKey, Buffer.from(dataToSend));`;
27+
channel.publish(exchange, routingKey, Buffer.from(dataToSend), options);`;
2828

2929
const functionParameters = [
3030
{
@@ -44,7 +44,7 @@ channel.publish(exchange, routingKey, Buffer.from(dataToSend));`;
4444
jsDoc: ' * @param amqp the AMQP connection to send over'
4545
},
4646
{
47-
parameter: `options?: {exchange: string | undefined} extends Amqp.Options.Publish`
47+
parameter: `options?: {exchange: string | undefined} & Amqp.Options.Publish`
4848
}
4949
];
5050

@@ -57,9 +57,9 @@ ${functionName}: (
5757
${functionParameters.map((param) => param.parameter).join(', ')}
5858
): Promise<void> => {
5959
return new Promise<void>(async (resolve, reject) => {
60-
const exchange = options.exchange ?? '${additionalProperties?.exchange}';
60+
const exchange = options?.exchange ?? '${additionalProperties?.exchange}';
6161
if(!exchange) {
62-
return reject('No exchange value found, please provide one to call publishToSendUserSignedupExchange')
62+
return reject('No exchange value found, please provide one')
6363
}
6464
try {
6565
${publishOperation}

src/codegen/generators/typescript/channels/protocols/amqp/publishQueue.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function renderPublishQueue({
2323
const publishOperation = `let dataToSend: any = ${messageType === 'null' ? 'null' : messageMarshalling};
2424
const channel = await amqp.createChannel();
2525
const queue = ${addressToUse};
26-
channel.sendToQueue(queue, Buffer.from(dataToSend));`;
26+
channel.sendToQueue(queue, Buffer.from(dataToSend), options);`;
2727

2828
const functionParameters = [
2929
{
@@ -41,6 +41,9 @@ channel.sendToQueue(queue, Buffer.from(dataToSend));`;
4141
{
4242
parameter: 'amqp: Amqp.Connection',
4343
jsDoc: ' * @param amqp the AMQP connection to send over'
44+
},
45+
{
46+
parameter: `options?: Amqp.Options.Publish`
4447
}
4548
];
4649

test/blackbox/test_files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'path';
22
import * as fs from 'fs';
33

44
// Select a specific file to test
5-
const TEST_SPECIFIC_FILE: any = '';
5+
const TEST_SPECIFIC_FILE: any = 'documentation';
66
// Select a specific config to test
77
const TEST_SPECIFIC_CONFIG: any = '';
88

0 commit comments

Comments
 (0)