-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release v1.0.0
- Loading branch information
Peter Wikström
authored
Feb 27, 2023
1 parent
e50e814
commit 1cd0573
Showing
22 changed files
with
1,069 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import { toPascalCase } from '../utils/common'; | ||
|
||
export function Consumers({ channels }) { | ||
if (channels.length === 0) { | ||
return null; | ||
} | ||
|
||
return `protected override Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
_amqpService.${toPascalCase(channels[0].operationId)}(); | ||
return Task.CompletedTask; | ||
}`; | ||
return ` | ||
// Code for the subscriber: Recieves messages from RabbitMq | ||
_amqpService.${channels[0].subscriber.operationId}(); | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { toPascalCase } from '../utils/common'; | ||
|
||
export function Publishers({ channels }) { | ||
if (channels.length === 0) { | ||
return null; | ||
} | ||
|
||
return `protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
// TODO: Send message on custom events, below is a timing example. | ||
return ` | ||
// Code for the publisher: Send message on custom events, below is a timing example. | ||
// A real world example would probably read temeratures from some kind of I/O temperature sensor. | ||
/* | ||
var rnd = new Random((int) DateTime.Now.Ticks); | ||
while (!stoppingToken.IsCancellationRequested) | ||
{ | ||
var message = new ${toPascalCase(channels[0].messageType)}(); | ||
_amqpService.${toPascalCase(channels[0].operationId)}(message); | ||
var message = new ${channels[0].publisher.messageType}(); | ||
_amqpService.${channels[0].publisher.operationId}(message); | ||
await Task.Delay(rnd.Next(500, 3000), stoppingToken); | ||
} | ||
}`; | ||
*/ | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,48 @@ | ||
import { getChannels, toPascalCase } from '../../utils/common'; | ||
|
||
const template = (publishers, consumers, params) => `using System; | ||
const template = (channels, params) => `using System; | ||
using ${params.namespace}.Models; | ||
namespace ${params.namespace}.Services.Interfaces; | ||
public interface IAmqpService : IDisposable | ||
{ | ||
${publishers | ||
${channels | ||
.filter((channel) => channel.publisher) | ||
.map( | ||
(publisher) => ` | ||
(channel) => ` | ||
/// <summary> | ||
/// Operations from async api specification | ||
/// Publish operation from ${channel.routingKey} | ||
/// </summary> | ||
/// <param name="message">The message to be handled by this amqp operation</param> | ||
void ${toPascalCase(publisher.operationId)}(${ | ||
publisher.messageType | ||
} message); | ||
void ${toPascalCase(channel.publisher.operationId)}(${toPascalCase( | ||
channel.publisher.messageType | ||
)} message); | ||
` | ||
) | ||
.join('')} | ||
${consumers | ||
${channels | ||
.filter((channel) => channel.subscriber) | ||
.map( | ||
(consumer) => ` | ||
(channel) => ` | ||
/// <summary> | ||
/// Operations from async api specification | ||
/// Subscribe operation from ${channel.routingKey} | ||
/// </summary> | ||
/// <param name="message">The message to be handled by this amqp operation</param> | ||
void ${toPascalCase(consumer.operationId)}(); | ||
void ${toPascalCase(channel.subscriber.operationId)}(); | ||
` | ||
) | ||
.join('')} | ||
}`; | ||
|
||
export function IAmqpService({ asyncapi, params }) { | ||
if (!asyncapi.hasComponents()) { | ||
const channels = getChannels(asyncapi); | ||
|
||
if (channels.length === 0) { | ||
return null; | ||
} | ||
|
||
const publishers = getChannels(asyncapi).filter( | ||
(channel) => channel.isPublish | ||
); | ||
const consumers = getChannels(asyncapi).filter( | ||
(channel) => !channel.isPublish | ||
); | ||
|
||
return template(publishers, consumers, params); | ||
return template(channels, params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.