Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2688a18

Browse files
docs(@nestjs/microservices) Added RabbitMQ docs
1 parent 68e3f56 commit 2688a18

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

‎src/app/app-routing.module.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { MigrationComponent } from './homepage/pages/migration/migration.compone
7373
import { MqttComponent } from './homepage/pages/microservices/mqtt/mqtt.component';
7474
import { NatsComponent } from './homepage/pages/microservices/nats/nats.component';
7575
import { GrpcComponent } from './homepage/pages/microservices/grpc/grpc.component';
76+
import { RabbitMQComponent } from './homepage/pages/microservices/rabbitmq/rabbitmq.component';
7677
import { SupportComponent } from './homepage/pages/support/support.component';
7778

7879
const routes: Routes = [
@@ -281,6 +282,11 @@ const routes: Routes = [
281282
component: GrpcComponent,
282283
data: { title: 'gRPC - Microservices' },
283284
},
285+
{
286+
path: 'microservices/rabbitmq',
287+
component: RabbitMQComponent,
288+
data: { title: 'RabbitMQ - Microservices' },
289+
},
284290
{
285291
path: 'microservices/pipes',
286292
component: MicroservicesPipesComponent,

‎src/app/app.module.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import { ConfigurationComponent } from './homepage/pages/techniques/configuratio
8585
import { MigrationComponent } from './homepage/pages/migration/migration.component';
8686
import { MqttComponent } from './homepage/pages/microservices/mqtt/mqtt.component';
8787
import { GrpcComponent } from './homepage/pages/microservices/grpc/grpc.component';
88+
import { RabbitMQComponent } from './homepage/pages/microservices/rabbitmq/rabbitmq.component';
8889
import { NatsComponent } from './homepage/pages/microservices/nats/nats.component';
8990
import { SupportComponent } from './homepage/pages/support/support.component';
9091

@@ -178,6 +179,7 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
178179
MigrationComponent,
179180
MqttComponent,
180181
GrpcComponent,
182+
RabbitMQComponent,
181183
NatsComponent,
182184
SupportComponent,
183185
],

‎src/app/homepage/menu/menu.component.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class MenuComponent implements OnInit {
111111
{ title: 'MQTT', path: '/microservices/mqtt' },
112112
{ title: 'NATS', path: '/microservices/nats' },
113113
{ title: 'gRPC', path: '/microservices/grpc' },
114+
{ title: 'RabbitMQ', path: '/microservices/rabbitmq' },
114115
{
115116
title: 'Exception filters',
116117
path: '/microservices/exception-filters',
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<div class="content">
2+
<h3>RabbitMQ</h3>
3+
<p>
4+
The <a href="https://www.rabbitmq.com/" target="blank">RabbitMQ</a> is the most widely deployed open source message broker.
5+
</p>
6+
<h4>Installation</h4>
7+
<p>Before we start, we have to install required package:</p>
8+
<pre><code class="language-bash">
9+
$ npm i --save amqp</code></pre>
10+
<h4>Transporter</h4>
11+
<p>
12+
In order to switch to <strong>RabbitMQ</strong> transporter, we need to modify an options object passed to the <code>createMicroservice()</code> method.
13+
</p>
14+
<span class="filename">
15+
{{ 'main' | extension: optionsT.isJsActive }}
16+
<app-tabs #optionsT></app-tabs>
17+
</span>
18+
<pre><code class="language-typescript">{{ options }}</code></pre>
19+
<h4>Options</h4>
20+
<p>
21+
There are a bunch of available options that determine a transporter behavior.
22+
</p>
23+
<table>
24+
<tr>
25+
<td><code>url</code></td>
26+
<td>Connection url </td>
27+
</tr>
28+
<tr>
29+
<td><code>queue</code></td>
30+
<td>Queue name which your server will listen</td>
31+
</tr>
32+
<tr>
33+
<td><code>queueOptions</code></td>
34+
<td>Additional options for creating a queue. They are well-described <a href="https://github.com/postwait/node-amqp" target="blank">here</a></td>
35+
</tr>
36+
</table>
37+
<h4>Client</h4>
38+
<p>
39+
In order to connect with Client, we are creating the <code>ClientProxy</code> instance using the <code>ClientProxyFactory</code> (exported from <code>@nestjs/microservices</code> package).
40+
</p>
41+
<span class="filename">
42+
{{ 'client' | extension: clientT.isJsActive }}
43+
<app-tabs #clientT></app-tabs>
44+
</span>
45+
<pre><code class="language-typescript">{{ client }}</code></pre>
46+
<p>
47+
In <code>queue</code>, we define queue that our server is listening. You don't have to worry about reply queue, NestJS will create it for each client. But each server needs a unique queue. You can use multiple instanсes of your server to balance your load.
48+
</p>
49+
<p>
50+
To send a message and listen to reply simply use <code>send()</code> method:
51+
</p>
52+
<span class="filename">
53+
{{ 'client' | extension: sendT.isJsActive }}
54+
<app-tabs #sendT></app-tabs>
55+
</span>
56+
<pre><code class="language-typescript">{{ send }}</code></pre>
57+
<p>
58+
Where <code>MyInterfaceForMessage</code> and <code>MyInterfaceForReply</code> are interfaces for message and reply.
59+
</p>
60+
</div>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
2+
import { BasePageComponent } from '../../page/page.component';
3+
4+
@Component({
5+
selector: 'app-rabbitmq',
6+
templateUrl: './rabbitmq.component.html',
7+
changeDetection: ChangeDetectionStrategy.OnPush,
8+
})
9+
export class RabbitMQComponent extends BasePageComponent {
10+
get options() {
11+
return `
12+
const app = await NestFactory.createMicroservice(ApplicationModule, {
13+
transport: Transport.RMQ,
14+
options: {
15+
url: \`amqp://$\{conf.user}:\${conf.password}@\${conf.host}\`,
16+
queue: 'myqueue',
17+
queueOptions: { durable: false }
18+
},
19+
});`;
20+
}
21+
22+
get client() {
23+
return `
24+
this.client = ClientProxyFactory.create({
25+
transport: Transport.RMQ,
26+
options: {
27+
url: \`amqp://\${conf.user}:\${conf.password}@\${conf.host}\`,
28+
queue: 'myqueue',
29+
queueOptions: { durable: false }
30+
}
31+
});`;
32+
}
33+
34+
get send() {
35+
return `
36+
let pattern = { cmd: 'doit' };
37+
this.client.send<MyInterfaceForMessage, MyInterfaceForReply>(pattern, 'myqueue').subscribe((x: MyInterfaceForReply) => {
38+
console.log('I got resp: ' + x);
39+
})`;
40+
}
41+
42+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /