- [Instructor] We now want to implement a method
that sends messages that were posted
via the feedback forum
to RabbitMQ.
For that, I'd first have to install an
NPM module that can speak to RabbitMQ
and that's in qplib, so I run npm install,
dash dash save, amqplib,
and I open the feedback js file
in services on the conference app,
and then first I will bring in
the library const,
amqplib equals require,
amqplib.
Now we have to implement the function that adds
an entry because it was present like that in the old
feedback cast, so it takes a name, a title, and a message.
So now, I add async,
add entry,
name, title, message.
And now for the q I start with
defining how this q should be called, its feedback
and next I will
create the connection to this q by adding const conn,
equals await, amqplib,
dot connect.
And this is amqp on local host.
Next we have to
create the channel to this q
for that to add const ch,
equals await, conn, create channel
and then I have to
summon this feedback q into existence by adding await,
ch, assert q
and the passing,
the name of the q.
Next I will now prepare the message to be
queued, so I add const qm,
for queue message,
equals JSON, stringify
because RabbitMQ only accepts
buffers to be sent through it and this takes a name,
a title, and a message
and then I can return ch, send to queue,
there I will now, again, tell which q it is.
So it's feedback and
I use buffer dot from,
qm, and I have to also declare the coding.
It's utf8.
That looks good so far,
so let's start the conference app.
Our services are all running of course.
RabbitMQ is running as well,
and let's see if it works, yes and I go to feedback
and there I now,
(typing)
make it clear that this is a queued message.
(more typing)
And, in the end I press submit.
You see that I get my thank you for your feedback response
but of course there's no consumer now
on the feedback service for this queue message
and we will implement that in the next video.